In the code I have two variables r and c, I assign them a random number by saying r = random( 8 ) then c = random( 8 ). This leads me to two questions:
- are they being assigned two different random numbers or the same random number per iteration of the loop?
- how is this turning on only one led of an 8x8 led matrix at a time if they are different random numbers? shouldn't the row be just the NOT version of the column (ex, B00100000 and B11011111) this would turn on only 1 led.
I am just really confused as to what is happening here
#define DS 6 // connect to pin 14 on the 74HC595
#define ST_CP 8 // connect to pin 12 on the 74HC595 (LATCH)
#define SH_CP 10 // connect to pin 11 on the 74HC595 (CLOCK)
int binary[] = {1, 2, 4, 8, 16, 32, 64, 128};
int r = 0;
int c = 0;
void setup()
{
pinMode(DS, OUTPUT);
pinMode(ST_CP, OUTPUT);
pinMode(SH_CP, OUTPUT);
randomSeed(analogRead(0));
}
void setLED(int row, int column, int del)
{
digitalWrite(ST_CP, LOW);
shiftOut(DS, SH_CP, LSBFIRST, binary[column]);
shiftOut(DS, SH_CP, LSBFIRST, ~binary[row]);
digitalWrite(ST_CP, HIGH);
delay(del);
}
void loop()
{
r = random(8);
c = random(8);
setLED(r, c, 1);
}