Saturday, March 12, 2016

Hello Arduino

Last week I started playing with a new toy -- the Arduino. I have a couple of IoT-style projects kicking around the back of my head, but at this point, I'm just learning.

Here is a photo of my first "original" project -- a binary counter built with 8 LED's:



And the corresponding source code:

int leds[] = {2,3,4,5,6,7,8,9};

void setup() {
  int index;
  for (index = 0; index <= 7; index++) {
    pinMode(leds[index], OUTPUT);
  }
}

void loop() {
  int num;
  for (num = 0; num < 256; num++) {
    int bitNum = 0;
    for (bitNum = 0; bitNum < 8; bitNum++) {
      if (num & (1 << bitNum)) {
        digitalWrite(leds[bitNum], HIGH);
      } else {
        digitalWrite(leds[bitNum], LOW);
      }
    }
    delay(1000);
  }
}

Building things in the Real World is lots of fun for software people like me that spend so much time in the land of abstractions. Assuming I do anything interesting, I'll try to post the details here.

No comments: