Difference between revisions of "Cylon LEDs"
Jump to navigation
Jump to search
(→Code) |
(→Code) |
||
Line 28: | Line 28: | ||
//bpw 2/11/22 | //bpw 2/11/22 | ||
− | int pinled1 = | + | int pinled1 = 6; |
− | int pinled2 = | + | int pinled2 = 7; |
− | int pinled3 = | + | int pinled3 = 8; |
− | int pinled4 = | + | int pinled4 = 9; |
− | int pinled5 = | + | int pinled5 = 10; |
− | int pinled6 = | + | int pinled6 = 11; |
− | int pinled7 = | + | int pinled7 = 12; |
+ | int pinled8 = 13; | ||
int t = 50; | int t = 50; | ||
void setup() | void setup() | ||
Line 45: | Line 46: | ||
pinMode(pinled6, OUTPUT); | pinMode(pinled6, OUTPUT); | ||
pinMode(pinled7, OUTPUT); | pinMode(pinled7, OUTPUT); | ||
+ | pinMode(pinled8, OUTPUT); | ||
} | } | ||
void loop() | void loop() | ||
{ | { | ||
− | |||
digitalWrite(pinled1, HIGH); | digitalWrite(pinled1, HIGH); | ||
delay(t); | delay(t); | ||
Line 71: | Line 72: | ||
delay(t); | delay(t); | ||
digitalWrite(pinled5, LOW); | digitalWrite(pinled5, LOW); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled7, HIGH); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled6, LOW); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled8, HIGH); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled7, LOW); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled7, HIGH); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled8, LOW); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled6, HIGH); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled7, LOW); | ||
delay(t); | delay(t); | ||
digitalWrite(pinled5, HIGH); | digitalWrite(pinled5, HIGH); | ||
Line 79: | Line 96: | ||
delay(t); | delay(t); | ||
digitalWrite(pinled5, LOW); | digitalWrite(pinled5, LOW); | ||
− | delay( | + | delay(tim); |
digitalWrite(pinled3, HIGH); | digitalWrite(pinled3, HIGH); | ||
+ | delay(t); | ||
+ | digitalWrite(pinled4, LOW); | ||
delay(t); | delay(t); | ||
− | |||
− | |||
digitalWrite(pinled2, HIGH); | digitalWrite(pinled2, HIGH); | ||
− | delay(t); | + | delay(t); |
digitalWrite(pinled3, LOW); | digitalWrite(pinled3, LOW); | ||
delay(t); | delay(t); | ||
Line 92: | Line 109: | ||
digitalWrite(pinled2, LOW); | digitalWrite(pinled2, LOW); | ||
delay(t); | delay(t); | ||
+ | |||
} | } | ||
Revision as of 13:25, 11 February 2011
Introduction
Cylon LEDs In this experiment, we will create a Cylon (Battlestar Galactica) effect with LEDs. I get this request quite a lot when people are first starting to program arduinos.
Components Needed
- Freeduino or Arduino or clone
- USB cable for Freeduino
- Freeduino development software - download here!
- Solderless Breadboard
- Hookup wire 22gauge solid
- 8 LEDs -same color is preferable
- 8 1K resistors
How to
- See the fritzing diagram
Schematic
Fritzing
Code
//code for cylon //bpw 2/11/22 int pinled1 = 6; int pinled2 = 7; int pinled3 = 8; int pinled4 = 9; int pinled5 = 10; int pinled6 = 11; int pinled7 = 12; int pinled8 = 13; int t = 50; void setup() { pinMode(pinled1, OUTPUT); pinMode(pinled2, OUTPUT); pinMode(pinled3, OUTPUT); pinMode(pinled4, OUTPUT); pinMode(pinled5, OUTPUT); pinMode(pinled6, OUTPUT); pinMode(pinled7, OUTPUT); pinMode(pinled8, OUTPUT); } void loop() { digitalWrite(pinled1, HIGH); delay(t); digitalWrite(pinled2, HIGH); delay(t); digitalWrite(pinled1, LOW); delay(t); digitalWrite(pinled3, HIGH); delay(t); digitalWrite(pinled2, LOW); delay(t); digitalWrite(pinled4, HIGH); delay(t); digitalWrite(pinled3, LOW); delay(t); digitalWrite(pinled5, HIGH); delay(t); digitalWrite(pinled4, LOW); delay(t); digitalWrite(pinled6, HIGH); delay(t); digitalWrite(pinled5, LOW); delay(t); digitalWrite(pinled7, HIGH); delay(t); digitalWrite(pinled6, LOW); delay(t); digitalWrite(pinled8, HIGH); delay(t); digitalWrite(pinled7, LOW); delay(t); digitalWrite(pinled7, HIGH); delay(t); digitalWrite(pinled8, LOW); delay(t); digitalWrite(pinled6, HIGH); delay(t); digitalWrite(pinled7, LOW); delay(t); digitalWrite(pinled5, HIGH); delay(t); digitalWrite(pinled6, LOW); delay(t); digitalWrite(pinled4, HIGH); delay(t); digitalWrite(pinled5, LOW); delay(tim); digitalWrite(pinled3, HIGH); delay(t); digitalWrite(pinled4, LOW); delay(t); digitalWrite(pinled2, HIGH); delay(t); digitalWrite(pinled3, LOW); delay(t); digitalWrite(pinled1, HIGH); delay(t); digitalWrite(pinled2, LOW); delay(t); }
Troubleshooting
Probably the easiest way to troubleshoot LEDs is to power them. Take the wire that goes to the arduino output pin and touch it to 5V to see that the LED lights up. If it does not, turn the LED around and try again. LEDs are pretty hearty as long as you have a 1K resistor in series with them.