N
N
nkorobkov2018-10-08 10:02:53
Arduino
nkorobkov, 2018-10-08 10:02:53

How does this Arduino code work?

There is the following scheme:
5bbb009ee8ecf484367087.png
The code was not written by me, I do not understand and do not plan to use Arduino. Please help me just to understand how the following code works, because it is very important:

const int data = 2;
const int store = 3;
const int shift = 4;

int potiValue;

// column counter
int j = 0;
// showDuration counter
int k;

int row[8] = {127, 191, 223, 239, 247, 251, 253, 254};
// Smiley Happy
int columnH[8] = {60, 66, 165, 129, 165, 153, 66, 60};
// Smiley Normal
int columnN[8] = {60, 66, 165, 129, 129, 189, 66, 60};
// Smiley Sad
int columnS[8] = {60, 66, 165, 129, 153, 165, 66, 60};

void setup()
{
  Serial.begin(9600);
  // 74HC595
  pinMode(data, OUTPUT); // data
  pinMode(store, OUTPUT); // store
  pinMode(shift, OUTPUT); // shift
  
  pinMode(13, OUTPUT);
}

void poti()
{
  potiValue = analogRead(0);
}

void happy()
{
  for(k = 0; k<100; k++)
  {
    for(int i=0; i<8; i++)
    {
      digitalWrite(store, LOW);
      shiftOut(data, shift, LSBFIRST, columnH[j]);
      shiftOut(data, shift, LSBFIRST, row[i]);
      digitalWrite(store, HIGH);
      j++;
      poti();
      delay(potiValue);
    }
    j = 0;
  }
}

void normal()
{
  for(k = 0; k<100; k++)
  {
    for(int i=0; i<8; i++)
    {
      digitalWrite(store, LOW);
      shiftOut(data, shift, LSBFIRST, columnN[j]);
      shiftOut(data, shift, LSBFIRST, row[i]);
      digitalWrite(store, HIGH);
      j++;
      poti();
      delay(potiValue);
    }
    j = 0;
  }
}

void sad()
{
  for(k = 0; k<100; k++)
  {
    for(int i=0; i<8; i++)
    {
      digitalWrite(store, LOW);
      shiftOut(data, shift, LSBFIRST, columnS[j]);
      shiftOut(data, shift, LSBFIRST, row[i]);
      digitalWrite(store, HIGH);
      j++;
      poti();
      delay(potiValue);
    }
    j = 0;
  }
}

void loop()
{
  happy();
  normal();
  sad();
}

The result of the work: a smiley is displayed on the diodes, in which 3 emotions change in turn:
5bbb01781eb2c121647459.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem, 2018-10-08
@proudmore

As it is written in the code, it works :)
It would be easier to explain to you what you are interested in if your ultimate goal was known.
And then I want to understand how it works, but I don’t want to understand how it works and I don’t plan to :)

O
OnYourLips, 2018-10-08
@OnYourLips

The code was not written by me, I do not understand and do not plan to use Arduino.
You follow the link in the header: https://freelansim.ru/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question