Tuesday, October 7, 2008
LED patterns with ARDUINO
With the arduino board, we programmed LEDs to turn on and off in a sequential pattern. Our initial prototype consisted only of the arduino board which controlled the speed of flashing of a single LED.
int timer = 100; // The higher the number, the slower the timing.int pins[] = { 2, 3, 4, 5 }; // an array of pin numbersint num_pins = 4; // the number of pins (i.e. the length of the array)void setup(){ int i; for (i = 0; i < i =" 0;" i =" num_pins">= 0; i--) { digitalWrite(pins[i], HIGH); delay(timer); digitalWrite(pins[i], LOW); }}
Below is our first code, and video of prototype.
int ledPin = 13; // LED connected to digital pin 13void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}void loop(){ digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second}
Our second prototype utilized a bread board in conjunction with the arduino diecimila in order to control patterning among a group of four LEDs.
Below is our second code, and video of prototype.
int timer = 100; // The higher the number, the slower the timing.int pins[] = { 2, 3, 4, 5 }; // an array of pin numbersint num_pins = 4; // the number of pins (i.e. the length of the array)void setup(){ int i; for (i = 0; i < i =" 0;" i =" num_pins">= 0; i--) { digitalWrite(pins[i], HIGH); delay(timer); digitalWrite(pins[i], LOW); }}