How can I design a programming code to control the Arduino w
How can I design a programming code to control the Arduino with components of a button and a LED processing as following:
After I press three times to turn the LED on and press three times to turn the LED off.
Thank you all yoiu guys.
Solution
int ledpin=13; //LED isconnected to digital pin 13
int switchPin=5; //switch connected to digital pin 2
int switcvalue; //avariable to keep track of when switch is pressed
int counter=0; //my counter variable
//int couterValue; //a possble value variable for my counter
void setup()
{
pinMode(ledPin, OUTPUT); //sets the ledPin to be an output
pinMode(switchPin, INPUT); //sets the switch pin to bean INPUT
digitalWrite(switchPin, HIGH); //sets the default(unpressed) state of switchPin to HIGH
}
void loop()
{
switchValue=digitalRead(switchPin); //check to see if the switch is pressed
if(switchValue==LOW) { //if the switch is pressed then
degitalWrite(ledpin,HIGH); //turn the LED on
delay(200); //wait for a second
digitalWrite(ledoin, LOW); //turn the LED off
delay(200);
counter++;
if(counter>3) {
digitalWritten(ledPin,LOW); //turn the LED offand keepitoff(why isn\'t this working)
}
}
else { //otherwise,
digitalWritte(ledpin, LOW); //turn the LED off
counter=0;
}
}
after youhave the counteron 3, this part runs over and over again,
if ((switchvalue==low)&&(counter<=3)) { //if the switch is press then
digitalwrite(ledpin, HIGH); //turn the led on
delay(200); //wait for a second
digitalwrite(ledpin, low); //turn theled off
delay(200); //wait for a second
counter++;
}
if(switchvalue==HIGH)
{
counter=0;
}

