Friday, July 9, 2010

fibonacci blinker

arduino code:

blinks the led on pin 13 in the fibonacci sequence - at least until it hits the max value of a long, and then rolls over.



int ledPin = 13; // LED connected to digital pin 13
long seq1 = 1; // Sequence number 1
long seq2 = 2; // Sequence number 2
long seq3 = 3; // Sequence number 3
// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
for (int numberOftimes = seq1; numberOftimes >=1; numberOftimes--){
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
delay(5000); // wait 5 seconds between series of blinks
seq1=seq2; //shift the second number into the first variable
seq2=seq3; //shift the third number into the second variable
seq3=seq1+seq2; // calculate the third number (based on previous two)

}

dev

As it is, so it goes.

Once again a large gap between putting down anything as a record - (in the spirit of things) Hello, World! Those of you who've taken a programming class or two, that's for you.



Last post was about being in Germany - a good experience but a long one. The beer was good, but not a lot of variety (more at the grocery store than any bars). I'm glad it's over but I'd go again. This post is about doing, rather than talking (or thinking).

For awhile I've been interested in arduino micro-controllers. Mainly from reading the RSS feed of Make Magazine. They have lots of projects that seem interesting, and close to hobbies I'd actually like to have - rather than read about. I've taken old t shirts and made a blanket out of them. I made an interesting collage out of all of my old CD booklets and cover art. I like to paint, used to make models (and have some lying around, ready to be assembled). Use to play with legos (and have a plan for a fish tank with legos inside). So i enjoy making an item of "stuff" out of a larger quantity of "stuff" i have around/collected. It's also a way of reducing the collection. (I have plans for a large quantity of bottle caps, and a drawer of a beginning collecting of altoid tins )

Anyway, I started by purchasing an arduino board from sparkfun. Plugged it into my computer, and quickly ran through the two blink examples. I quickly ran through the two blink examples (and while writing, decided i should do a fibonacci sequence blinker, but anyway) and realized i needed some components if this was going to become a true "hobby". Work put me through a professional soldering class (rework and repair certified) so I feel pretty confident.

Picked up some more bits last night (including a soldering iron that won't set the apartment on fire - a true concern).

If I think to, I'll write more later.