Tuesday, August 12, 2008

StickDuino Fun!

I got my StickDuino in the mail yesterday, and, upon opening it, realized something was missing: headers! There were no header pins! Luckily, I had some laying around. I placed those in their holes on the board, plugged the whole thing into a breadboard to hold it still, and soldered. Two minutes later, it was ready to go. Within 15 minutes, I had a program modified to control an RGB LED. After some further programming, I came up with this:
/*
* RGBRandom
* by Pete Marchetto
*
* Based on Loop by David Mellis. Randomly lights an RGB LED with one of 7 colors.
* Demonstrates the use of a for() loop and arrays.
*
*/

int timer = 1000; // The higher the number, the slower the timing.
int pins[] = { 0,1,3 }; // an array of pin numbers (Vcc or 3.3V is on pin 2)
int num_pins = 3; // the number of pins (i.e. the length of the array)

void setup()
{
int i;
randomSeed (analogRead (0)); // seeds the random number generator off A0
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num_pins - 1
pinMode(pins[i], OUTPUT); // set each pin as an output
}

void loop()
{
int i;

for (i = 0; i < num_pins; i++) { // loop through each pin...
digitalWrite(pins[random(0, 3)], LOW); // turning one on at random,
delay(timer); // pausing,
digitalWrite(pins[random(0,3)], HIGH); // and turning one off at random.
}
}

Which can be found at this location as a Processing file. So far, with the exception of the missing headers, I like it alot!

No comments: