I just got my Ardunio inventor kit about two hours ago. I tried out the blink hello world and flipped through the other suggested programs but nothing caught my eye.
So I set about to making a binary counter. I used the “8 LED” example for the hardware. The code was a bit more tricky since I didn’t have a full grasp (still don’t) of binary. I had to fix a bug or two in my original algorithm but once that was done I cleaned up the code and added some simple configuration options.
Video, sorry about the out of focus portions
http://www.youtube.com/watch?v=uA8re61ZBDw
Anyway thank you Sparkfun and arduino.
The code if anyone is interested:
/*
Binary counter
Counts up and prints result to LEDs, for practicing binary counting.
This code is in the public domain.
*/
int startPin = 2;
int everyNthPin = 1;
int totalPins = 12;
int delayInms = 500;
void setup() {
for (int i = startPin; ( i / everyNthPin ) - startPin < totalPins; i += everyNthPin) {
pinMode(i, OUTPUT);
}
}
int expo( int base , int power) {
int total = base;
for( int times = power; times > 1; times--) {
total *= base;
}
return total;
}
int i = 0;
void loop() {
int carry = i;
int currentbit = 0;
int j = startPin;
for (; ( j / everyNthPin ) - startPin < totalPins; j += everyNthPin) {
currentbit = carry % 2;
carry = carry / 2;
if (currentbit > 0) {
digitalWrite(j, HIGH);
} else {
digitalWrite(j, LOW);
}
}
i++;
if (i >= expo(2 , totalPins) ) i = 0;
delay(delayInms);
}