Blinking – doubled

Description

A blinking LED that starts at with a given number of blinks and then doubles the number of blinks progressively. Example: 1 blink, pause, 2 blinks, pause, 4 blinks, pause, 8 blinks, …, all the way to 100 blinks.

Components

1 Arduino

1 LED

1 220 Ohm Resistor

1 Breadboard

3 wires

Code

/*
 Blink
 Turns on an LED 1 time, pauses, turns on an LED 2 times quickly, pauses, 
 turns on an LED 4 times quickly, pauses, etc., doubling the number
 of quick blinks each time. 
 */

// the setup function runs once when you press reset or power the board
void setup() {
 // initialize digital pin 13 as an output.
 pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
 int blinkCount = 1; //initialize the first number of blinks in a series
 while (blinkCount < 100) { //max number of blinks in a series
 for (int i = 0; i < blinkCount; i++) {
 digitalWrite(13, HIGH); //turn on LED
 delay(100); //time LED is on
 digitalWrite(13, LOW); //turn off LED
 delay(100); //time LED is off
 }
 delay(2000); //delay between blinking series
 blinkCount = blinkCount + blinkCount; //double the length of the series
 }
}

Image

Arduino

Leave a Reply