"LED shifting using push-button and Arduino nano"
This project uses an Arduino Nano in 3 Different colors Led and Push-Button to Shifting led on.
This use to Decoration Lights and toys etc.
you use to 3 to more Led this project.
* Circuit Diagram :
Link get Blowe
View this video. https://youtu.be/9uNiHqaziqs
int ledy=10;
int ledw=9;
int ledr=8;
int buttonpin=2;
int stateOfPin=0;
int oldStateOfPin=0;
int buttonState=0;
void setup()
{
pinMode(ledy,OUTPUT);
pinMode(ledw,OUTPUT);
pinMode(ledr,OUTPUT);
pinMode(buttonpin,INPUT);
}
void loop()
{
buttonState = digitalRead(buttonpin);
if (buttonState == 1)
{
delay(50);
buttonState=digitalRead(buttonpin);
if(buttonState==0)
{
stateOfPin=oldStateOfPin+1;
}
}
else
{
delay(50);
}
switch(stateOfPin)
{
case 1:
digitalWrite(ledy,HIGH);
delay(200);
digitalWrite(ledy,LOW);
delay(200);
oldStateOfPin = stateOfPin;
break;
case 2:
digitalWrite(ledw,HIGH);
delay(200);
digitalWrite(ledw,LOW);
delay(200);
oldStateOfPin = stateOfPin;
break;
case 3:
digitalWrite(ledr,HIGH);
delay(200);
digitalWrite(ledr,LOW);
delay(200);
oldStateOfPin = stateOfPin;
break;
default:
digitalWrite(ledy,LOW);
digitalWrite(ledw,LOW);
digitalWrite(ledr,LOW);
oldStateOfPin=0;
break;
}
}
Thanks for reading the blog
🙌🙌🙌🙌
ReplyDelete