Wednesday, September 19, 2007

Arduino Board

It's been a few months since I purchased the Arduino board, and I finally sat down to start playing with it. My first program is a quick test, converting a Basic Stamp program over. It deals with (pseudo)random generation, outputting simply as LEDs.

/*
* Random Blink
*
* Should change this so it's more flexible, for any start pin and any end pin.
* This is an analogous program to the random, serial/python script made for the
* Basic Stamp, which logged every single interaction in a SQLite database.
* I will add to this to make it interface with that program next.
*/

int ledPinSet = 9;
int ledPin = 13; // LED connected to digital pin 13
int randTime; // Random 5 PINs
int randPinOn;
int randPinOff;

void setup() // run once, when the sketch starts

{
do {

pinMode(ledPinSet, OUTPUT); // sets the digital pin as output
ledPinSet += 1;

} while (ledPinSet <>

}

void loop() // run over and over again
{
randTime = (500,1500);
randPinOn = random(4);
randPinOff = random(4);
digitalWrite(ledPin - randPinOn, HIGH); // sets the LED on
delay(randTime); // waits for a second
digitalWrite(ledPin - randPinOff, LOW); // sets the LED off
delay(randTime); // waits for a second
}

There's still a serial output and an integration into python, which saves the random data into a SQLite file, but I'm sure that will be pretty straightforward.

No comments:

Post a Comment