/*
* 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:
Post a Comment