// 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
}
}
}
Comments