The project is about to lit up the less in a particular way (in the way u want)
The led's will bright up one by one and then they will travel in a reverse direction.Here, you can use any led you want and also the any colour combination.
Don't forget to like.
The code is as follows.
byte ledPin[]={4, 5, 6, 7, 8, 9, 10, 11, 12, 13};//to define the led's pin
int ledDelay(65);
int direction =1;
int currentLed;
unsigned long changeTime;//this is taken as unsigned because of the function in which it will be used in future
void setup() {
for (int x=0;x<10;x++)
{
pinMode(ledPin[x], OUTPUT);
}
changeTime=millis();
}
void changeLed()
{
for( int x=0;x<10;x++)
{
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLed], HIGH);
currentLed+=direction;
if (currentLed==9)
{
direction=-1;
}
if (currentLed==0)
{
direction =1;
}
}
void loop() {
// put your main code here, to run repeatedly:
if ((millis()-changeTime)>ledDelay)
{
changeLed();
changeTime=millis();
}
}
Comments