const int LED1=11; //The LED is connected to pin 9
const int BUTTON1=4; //The Button is connected to pin 2
boolean on1=false;
int buttonState2=0;
const int LED=9; //The LED is connected to pin 9
const int BUTTON=2; //The Button is connected to pin 2
boolean on=false;
int buttonState=0;
void setup()
{
pinMode (LED, OUTPUT); //Set the LED pin as an output
pinMode (BUTTON, INPUT); //Set button as input (not required)
digitalWrite(LED,HIGH);
pinMode (LED1, OUTPUT); //Set the LED pin as an output
pinMode (BUTTON1, INPUT); //Set button as input (not required)
digitalWrite(LED1,HIGH);
}
void loop()
{
buttonState = digitalRead(BUTTON);
if (buttonState==HIGH)
{
if (on==true)
{
on=false;
}
else
{
on=true;
}
if(on==true) {
digitalWrite(LED,HIGH);
}
else {
digitalWrite(LED,LOW);
}
delay(500);
}
buttonState2 = digitalRead(BUTTON1);
if (buttonState2==HIGH)
{
if (on1==true)
{
on1=false;
}
else
{
on1=true;
}
if(on1==true) {
digitalWrite(LED1,HIGH);
}
else {
digitalWrite(LED1,LOW);
}
delay(500);
} }
Comments
Post a Comment