somenjana
Published © GPL3+

Dimming in and out of a LED

The LED connected to D-13 and GND in dimmed in and out continiously using pulse width modulation.

BeginnerProtip1,096
Dimming in and out of a LED

Things used in this project

Story

Read more

Schematics

FED UP AND FED DOWN

Code

FED-UP AND FED DOWN OF THE LED

Arduino
Just paste the code in the Arduino software and upload! BINGO!!
// Programe: Fed-up and Fed-down
const int LED = 13; // LED connected to digital pin 13
int masterHIGH = 10; 
int masterLOW = 0; // masterHIGH and masterLOW are the variables for varying the time during fed in and out

void setup()
{
pinMode(LED, OUTPUT); // sets the digital
// pin as output
}

void loop(){
  
for (int j=0; j<11; j++){ // This loop used for dimming the LED slowly, 11 times executed due to the value of masterHIGH from 10 to 0
for (int i=0; i<50; i++){// This loop uses PWM (pulse width modulation), masterHIGH and masterLOW are used for changing the PWM. i=10 represents 10*50=500 millisec to stay in a particular PWM.

digitalWrite(LED, HIGH); // turns the LED on
delay(masterHIGH); // waits for a masterHIGH millisec
digitalWrite(LED, LOW); // turns the LED off
delay(masterLOW); // waits for a masterLOW millisec
}
masterHIGH=masterHIGH-1;
masterLOW=10-masterHIGH;
}
// masterHIGH will be 0 after leaving the loop and masterLOW will be 10

for (int j=0; j<11; j++){ // This loop used for brighting the LED slowly, 11 times executed due to the value of masterHIGH from 0 to 10
  masterHIGH=masterHIGH+1;
  masterLOW=10-masterHIGH;
for (int i=0; i<50; i++){// This loop uses PWM (pulse width modulation), masterHIGH and masterLOW are used for changing the PWM.  i=10 represents 10*50=500 millisec to stay in a particular PWM.

digitalWrite(LED, HIGH); // turns the LED on
delay(masterHIGH); // waits for a masterHIGH millisec
digitalWrite(LED, LOW); // turns the LED off
delay(masterLOW); // waits for a masterLOW millisec


}

}


}

Credits

somenjana

somenjana

2 projects • 0 followers

Comments