9.5 Example: ledBlink

/* ledBlink. This script will cause an LED attached to pin 11 
to blink on and off rapidly. The delay(250) instructions will
result in 250 ms, or 1/4 s, delays. The code turn on the LED 
for 1/4 s, off for 1/4 s.  This corresponds to a blink rate 
of 1/(.25+.25)=1/.5 = 2 Hz. */
#define LED 11

void setup(){
   pinMode(LED, OUTPUT);
}

void loop(){
   digitalWrite(LED, HIGH);
   delay(250);
   digitalWrite(LED, LOW);
   delay(250);
}

License

Icon for the Creative Commons Attribution 4.0 International License

Applied Electrical Engineering Fundamentals by David J. McLaughlin is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book