Variable blinking light

Description


I used an Arduino with a red light. I changed the code to have a variable rate of blinking moving back and forth between a delay of 100 to 500 milliseconds. I tested it and saw the change.

Components


  • 1 Arduino
  • 1 LED
  • 1 Resistor (220Ω)
  • 1 Breadboard
  • 3 Wires

Code


int ledPin = 13;
int currentRate = 1000;
int rateDir = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(ledPin, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
if (currentRate > 500) {
rateDir = 0;
} else if (currentRate < 100) {
rateDir = 1;
}
if (rateDir == 1) {
currentRate = currentRate + 50;
} else {
currentRate = currentRate - 50;
}
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(currentRate); // wait for current delay
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(currentRate); // wait for current delay
}

IMG_20160831_151457

Leave a Reply