0

I want to let the led blink for 3 seconds then 2 seconds then one second using the button one time and without using if/else

void setup() {
    // put your setup code here, to run once: 
    pinMode(5, INPUT); 
    pinMode(6, OUTPUT);
} 

void loop() { 
    // put your main code here, to run repeatedly: 
    digitalRead(5, HIGH);
    digitalWrite(6, HIGH); 
    delay(3000);
    digitalWrite(6, LOW);
    digitalWrite(6, HIGH); 
    delay(2000); 
    digitalWrite(6, LOW); 
    digitalWrite(6, HIGH); 
    delay(1000); 
}
  • Why don't you want to use if/else? Or is this a school assignment? – chrisl Sep 23 '19 at 6:07
  • it is a school assignment actually – Sam Abdul Sep 23 '19 at 6:08
  • 1
    switch case is your friend ;) – ElectronSurf Sep 23 '19 at 6:30
  • 1
    Switch is an alternative to if --- unless are you at the "interrupts" section of your class... – GMc Sep 23 '19 at 8:20
  • digitalRead() returns either LOW (which is a macro equivalent to 0) or HIGH (which is 1). – Edgar Bonet Sep 23 '19 at 10:32
0

As the required operation is finite and short, you can just hard code the sequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.