I am working on a little totem tower with 6 sets of 3 LED and 1 button. I have it set up, for now, so that every button press, one random light turns either on or off depending on its previous state.
problem is that once lights from light[4] and light[5] turn on, my program says they are always off but it leaves them on.
I'm not quite sure what my problem is or if I was able to explain it well enough, let me know if you know what could be causing this.
int light[7] = {12,10,8,6,4,2,22};
long randNum;
long tempNum = 0;
int BTN = 26;
int BTNstate = 0;
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < 7; i++){
pinMode(light[i], OUTPUT);
//pinMode(light[i], INPUT);
}
pinMode(BTN, INPUT);
Serial.begin(9600);
}
void loop() {
// Serial.println("starting countdown");
BTNstate = digitalRead(BTN);
// put your main code here, to run repeatedly:
/*for (int i = 0; i < 7; i++){
digitalWrite(light[i], HIGH);
}
delay(1000);*/
if (BTNstate == HIGH){
Serial.println("starting countdown");
randomLight();
}
}
void randomLight(){
//light flicker in a randomized patter for 10 seconds
//for (int i = 0; i <=100; i++){
randNum = random(7);
Serial.print("random num is ");
Serial.println(randNum);
/*if (tempNum == randNum){
if (randNum == 6)
randNum -= 1;
else if (randNum >= 0)
randNum += 1;
}*/
if (digitalRead(light[randNum]) == LOW){
digitalWrite(light[randNum], digitalRead(!light[randNum]));
Serial.print("IF light ");
Serial.print(light[randNum]);
Serial.print(" is ");
Serial.println(digitalRead(light[randNum]));
}
else{
digitalWrite(light[randNum], LOW);
Serial.print("ELSE light ");
Serial.print(light[randNum]);
Serial.print(" is ");
Serial.println(digitalRead(light[randNum]));
}
delay(1000);
tempNum = randNum;
// }
}