78Views3Replies

Author Options:

Arduino Blink Code help? Answered

I have just started learning the arduino. I have also started to learn basic C so I am familiar with for,while loops,etc. 

I'm working on a circuit that when triggered using a pusbutton, an LED blinks 5 times with a 1 second delay between each state and then switches off until triggered again.

I need help in writing the code.

Discussions

0
None
steveastrouk

4 years ago

You're using "rightsig" and "leftsig" as constants and variables, so it won't work. Use "cnt" as a counter variable in your for loops, you can use the same name twice, because only one counter is working at a time.

0
None
steveastrouk

4 years ago

"Is it right ?"

Does it work ? If it does, its right, if it doesn't it isn't.

0
None
Jonathanrjpereira

4 years ago

I tried to write some code is this right. NOTE: in the code below i am using two buttons for two LEDs:

int leftsig= 9;

int rightsig= 10;

int buttonstate1=0;

int buttonstate2=0;

int button1= 8;

int button2= 7;

int i=0;

int j=0;

void setup()

{

pinMode(leftsig, OUTPUT);

pinMode(rightsig, OUTPUT);

pinMode(button1, INPUT);

pinMode(button2, INPUT);

}

void loop()

{

{

buttonstate1= digitalRead(button1);

if(buttonstate1==HIGH)

{

for(leftsig=0;leftsig<5;leftsig++)

{

digitalWrite(leftsig,HIGH);

delay(1000);

digitalWrite(leftsig,LOW);

}

}

else(leftsig,LOW);

}

{

buttonstate2= digitalRead(button2);

if(buttonstate2==HIGH)

{

for(rightsig=0;rightsig<5;rightsig++)

{

digitalWrite(rightsig,HIGH);

delay(1000);

digitalWrite(rightsig,LOW);

}

}

else(rightsig,LOW);

}

}