Assignment: Introduction to Arduino and Physical Computing
Collaborators:
Assignment: Introduction to Arduino and Physical Computing
Collaborators:
"Red Light, Green Light" Blinking LED
Description
Use the Arduino to control a light emitting diode and make it blink in different colors at different rates.
Components Used
- Light Emitting Diode (LED)
- Resistor
Arduino Code
/* Blinking LED
* ------------* Turns on and off a dual color light emitting diode (LED) with its color-specific leads connected to digital
* pins 12 and 13. The LED blinks alternating from red to green in a sycopated interval of 1 s red, 700 ms green.* To limit current flow through the circuit, we added a 220 ohm resistor on the middle lead,
which then connects to the ground (GND) pin on the Arduino.
*
* Created 8 Sept. 2009 by Chung-Hay
* http://arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
int ledred = 13; // red LED connected to digital pin 13
int ledgreen = 12;
void setup() // run once, when the sketch starts
{
pinMode(ledred, OUTPUT); // sets the digital pin as output
pinMode(ledgreen, OUTPUT);
}
void loop() // run over and over again
{
digitalWrite(ledred, HIGH); // sets the red LED on
digitalWrite(ledgreen, LOW);
delay(1000); // waits for a second
digitalWrite(ledred, LOW); // sets the red LED off
digitalWrite(ledgreen, HIGH);
delay(700); // waits for a second
}
Items
Red lit LED:
(Yellow wire = Green light = PIN 12, Orange wire = Red light = PIN 13, Green wire = GND)
Green lit LED: