Hi Guys, Re my post, Frustrated, Frustrated with "while()" date May 24th, I thought I had this problem sorted, Im finding as soon as I solve one problem another two show up. Re advice and code given by Nick Gammon, it works ok to a degree.
Problem (1) I want the LEDs to come on and off when the button is pressed and released, at my timeing
ie, do away with all the "Delays", once FIRST LED13 has gone off, the code should move on to next or second SECOND LED. I am thinking of a " GOTO " command here, but thats discouraged in Arduino.
Problem (2) I forsee at start of the run, FIRST LED13, will be LOW so code will run straight to SECOND LED12 ( before I have time to activate FIRST LED13)Does this make sense ?
I think if I had a different "input" to each LED, my problem would be easier, but it has to be one input controlling all LEDs. Am I asking the impossible ?
Thanks, Chez7.
PS, How do I download my sketch to this forum ? I try " Copy to forum", It shows on post as a lot of #color cc bla bla,in the code.
#define FIRST_LED 13 // LED connected to: digital pin 13
#define SECOND_LED 12
void setup()
{
pinMode(FIRST_LED, OUTPUT); // sets the digital pin as output
pinMode(SECOND_LED, OUTPUT); // and for the second LED
} // end of setup
void loop()
{
int input; // variable to read into
do
{
input = digitalRead(7); //using pin 7 as input
}
while (input == 0); // end of do loop
digitalWrite(SECOND_LED, HIGH); // turns the LED on
delay(2000); // waits for a second
digitalWrite(SECOND_LED, LOW); // turns the LED off
delay(2000); // waits for a second
do
{
input = digitalRead(7); //using pin 7 as input
}
while (input == 0); // end of do loop
digitalWrite (FIRST_LED, HIGH); // turns the LED on
delay(2000); // waits for a second
digitalWrite(FIRST_LED, LOW); // turns the LED off
delay(2000); // waits for a second
} // end of loop