Testing and Arduino Code

Well tonight I had some time as I was watching the Giants and St. Louis game on tv and thought I would work on my Arduino project.  The project that me and my wife have come up with is actually right around the corner its to do with Halloween its going to make the eyes on the pumpkins, skeletons, spiders, and bats light up and glow.  The code I have come up with right now is not the code but its also something I am working on for my son he is 2 and likes playing with his cars so I am making him a stop light.  This also works for my train set to be the lights on the crossing signs or other places.

This also will work for use with Thanksgiving, Christmas, and New Years because it is just messing with lights.  Now you can run the LED’s in Parallel but you will need to make sure you have the right voltage and resistor on the device.  Now lets get to the code!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 3 Way Blink
 This will blink 3 different lights on and off in a row and keep rotating.
 
 This Example code is Copyright Eric Vasquez 2012 can be used freely long as credit is
 given.
*/
 
/*
 Here we are going to select the 3 Digital Pins that we will have the LED's on they
 are 0, 9, 10 if we need to add more we will add another ledxx where the xx's are
 it will be the number of the digital pin.
*/
int led0 = 0;
int led9 = 9;
int led10 = 10;
 
void setup() {
 
 /*
 Here we are going to initialize the digital Pins that we are going to use as output
 */
 pinMode(led0, OUTPUT);
 pinMode(led9, OUTPUT);
 pinMode(led10, OUTPUT);
 
}
 
void loop() {
 
 /*
 Here we will have it cycle 3 times to turn on each of the LED's on their own and turn the
 other two off when it is not their turn. We can use this to loop around and randomly select
 what LED we want to turn on or off and change the order around. Also we are using a 500ms 
 delay we can change it the higher we go the more time it will take 500ms is about 1 1/2 seconds.
 If it goes to low then it will be as if it was always on.
 */
 digitalWrite(led0, HIGH);
 digitalWrite(led9, LOW);
 digitalWrite(led10, LOW);
 delay(500);
 digitalWrite(led0, LOW);
 digitalWrite(led9, HIGH);
 digitalWrite(led10, LOW);
 delay(500);
 digitalWrite(led0, LOW);
 digitalWrite(led9, LOW);
 digitalWrite(led10, HIGH);
 delay(500);
 
}

Sure that is simple code but for my first real test and application for the Arduino its not bad.  I plan on getting more code up I am going to make the eyes Fade in and out, but I am trying to decide should I make them work off a motion sensor so they fade in and out slowly but the closer you get the faster they go till they are on the whole time?  Let me know what you think about this.

More to come! Stay Tuned!

Leave a Reply