Hello! My problem is that I thought I had an understanding of how I could use an input from a button to jump back into a While Loop, but some reason I can't seem to get it right.
int pinCount = 12;
int timer = 300;
int pinArray[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int pinArrayInverse[] = {
9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2};
int arduinoActivate = 11;
int sendTo2 = 0;
int whatDo = 0;
int arcDelay = 75;
int randomVar = 0;
int buttonPin = 14;
int buttonState = 0;
int powerTest = 0;
void setup() {
for (int cycle = 0; cycle < pinCount - 4; cycle++) {
pinMode(pinArray[cycle], OUTPUT);
}
pinMode(buttonPin, INPUT);
}
void loop() {
if (powerTest == 0) {
buttonState = digitalRead(buttonPin);
while (buttonState == LOW) {
buttonState = digitalRead(buttonPin);
}
}
powerTest = 1;
whatDo = random(1, 5);
if (whatDo == 1); {
randomVar = 4;
for (int cycle = 0; cycle < randomVar; cycle++) {
for (int cycle = 0; cycle < (pinCount); cycle++) {
digitalWrite(pinArray[(cycle - 4)], LOW);
digitalWrite(pinArray[(cycle - 0)], HIGH);
buttonState = digitalRead(buttonPin);
delay(arcDelay);
buttonState = digitalRead(buttonPin);
}
}
}
if (whatDo == 2); {
randomVar = 4;
for (int cycle = 0; cycle < randomVar; cycle++) {
for (int cycle = 0; cycle < (pinCount); cycle++) {
digitalWrite(pinArrayInverse[(cycle - 4)], LOW);
digitalWrite(pinArrayInverse[(cycle - 0)], HIGH);
delay(arcDelay);
}
}
}
}
This is going to be the beginning of a program I am going to expand, and it's all going to be the same basic principles just in different ways. So once I understand what I am doing wrong here, everything should hopefully run smoothly. This program activates 8 LED and sends a 4 LED bar across them in a loop four times, and then does it backwards. Each one of the whatDo if statements is supposed to be 1 out of however many animations I decide to make.
My problem though is that I can't find a way to jump back to the While Loop in the beginning that doesn't exit until the input on pin 14 (A0) becomes HIGH. When I run the program it works fine, nothing happens until I send a 5v signal to pin 14 (A0). Then the main loop continues and will ignore the While Loop as long as int powerTest does not equal 0. I thought I could put
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
powerTest = 0;
}
on different lines of the program to change powerTest into 0 so that the if statement at the beginning of the main loop would activate the while loop, but instead the program turns on from the input like normally, and then turns off after the second animation without any input from me.
Help?
Thank you for your time!