Blinking Leds without using delay

Hi i am looking to write code to have a Green Led flashing every 5 seconds and when a push button is pressed 5000 times a blue led starts flashing and the green led goes off. There is a second push button and if that is pressed a red led goes on and the green and blue turn off. Only 1 led can be flashing at a time and i cant use the delay function to flash the led as the delay is too long. I have attached the code i have with no flashing. Thanks

int COUNT = 0;

void setup()
{
  pinMode(12, INPUT);//Push button 1
  pinMode(7, OUTPUT);// Green led;
  pinMode(5, OUTPUT);// Blue led
  pinMode(11, INPUT);// Push button 2
  pinMode(6, OUTPUT);// Red led
  Serial.begin(9600);

}

void loop()
{
  if (digitalRead(12) == 1) {
    if (COUNT < 5000) {
      COUNT += 1;
      digitalWrite(7, HIGH);
      delay(1000); // Wait for 1000 millisecond(s)
    } else {
      if (COUNT >= 5000) {
        digitalWrite(5, HIGH);
        digitalWrite(7, LOW);
      }
    }
  }
  if (digitalRead(11) == 1) {
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(7, LOW);
  }
  Serial.println(COUNT);
}

I would suggest watching a few Arduino tutorials. You are not resetting your counter. You could have a hardware problem, could you post a schematic so we can be sure?

  pinMode(12, INPUT);//Push button 1

I suspect you need to read this Buttons and other electro-mechanical inputs (introduction) - General Electronics - Arduino Forum

I also suspect this is a school or college assignment, is this correct?

Have you looked at the useful BlinkWithoutDelay example in the IDE? That should give you a few ideas.

Steve

.... and when a push button is pressed 5000 times ......

I think you copied that down from the blackboard incorrectly. Pressing a button 5000 times is insane.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.