Hello everyone!
I am very new to Arduino, and so far I am stuck on the Digital Hourglass project in the project book.
I have set up the circuit, but what I want to do when all the LEDs light up is to play a bit with the sequences, meaning keep the original timer, but turn the LEDs off from 7 to 2 with the same interval and loop it back again from the beginning. I have searched the forums and the only thing I found was to sequentially light up and turn off the LEDs, but not in the same interval as the original timer.
The code is attached. I don't know whether I should edit something in the if (led > 7) prompt or I should do something else altogether..
Please assist me and explain whether there is a typical code for such loops.
Thank you
const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int previousSwitchState = 0;
int led = 2;
long interval = 1000;
int directions = 1;
void setup() {
// put your setup code here, to run once:
for (int x = 2; x < 8; x++) {
pinMode(x, OUTPUT);
}
pinMode(switchPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentTime = millis();
if (currentTime - previousTime > interval) {
previousTime = currentTime;
digitalWrite(led, HIGH);
led ++;
}
if (led > 7){
}
switchState = digitalRead(switchPin);
if (switchState != previousSwitchState) {
for (int x = 2; x < 8; x++) {
digitalWrite(x, LOW);
}
led = 2;
previousTime = currentTime;
}
previousSwitchState = switchState;
}