Difference between revisions of "Cylon LEDs"

From LVL1
Jump to navigation Jump to search
 
(3 intermediate revisions by one other user not shown)
Line 25: Line 25:
 
==Code==
 
==Code==
 
<pre>
 
<pre>
//code for cylon
+
//code for Cylon - I am sure this could be more elegant!
 
//bpw 2/11/22
 
//bpw 2/11/22
  
int pinled1 = 13;  
+
int pinled1 = 6;  
int pinled2 = 12;  
+
int pinled2 = 7;  
int pinled3 = 11;
+
int pinled3 = 8;
int pinled4 = 10;
+
int pinled4 = 9;
int pinled5 = 9;
+
int pinled5 = 10;
int pinled6 = 8;
+
int pinled6 = 11;
int pinled7 = 7;
+
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 81: Line 98:
 
delay(t);
 
delay(t);
 
digitalWrite(pinled3, HIGH);
 
digitalWrite(pinled3, HIGH);
 +
delay(t);
 +
digitalWrite(pinled4, LOW);
 
delay(t);
 
delay(t);
digitalWrite(pinled4, LOW);
 
delay(tim);
 
 
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);
 +
 
}
 
}
  
Line 98: Line 116:
 
==Troubleshooting==
 
==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.
 
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.
 +
 +
[[Category:HOWTO]]

Latest revision as of 23:52, 25 June 2015

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

Cylon schem.jpg

Fritzing

Cylon bb.jpg

Code

//code for Cylon - I am sure this could be more elegant!
//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(t);
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.