Project 8 timer

Yeah Hi.

I am currently working on project 8 "Digital Hourglass.

I seem to have stumbled upon a problem in my code. The hourglass works with relatively short interval. However when i turn it up to the one in the book. It won’t turn on any lights.

I will attach my code if you would like to take a look at it.

Digital_Hourglass.ino (654 Bytes)

Right now you have the interval set to 600000. That’s ten minutes. Did you wait that long?

Here’s the code for those that don’t want to download:

const int switchPin = 8;

unsigned long previousTime = 0;

int switchState = 0;
int prevSwitchState = 0;

int led = 2;

long interval = 600000;

void setup() {
  for(int x = 2;x<8;x++){
    pinMode(x, OUTPUT);
  }

  pinMode(switchPin, INPUT);
}
void loop(){
  unsigned long currentTime = millis();
  
  if(currentTime - previousTime > interval) {
    previousTime = currentTime;
    
    digitalWrite(led, HIGH);
    led++;
  }
  switchState = digitalRead(switchPin);
  if(switchState != prevSwitchState){
    for(int x = 2;x<8;x++){
      digitalWrite(x, LOW);
    }
    led = 2;
    previousTime = currentTime;
  }
  prevSwitchState = switchState;
}