Saturday, September 22, 2007

Physical Computer - Lab #2

Moving forward in the adventures of the electrical nature - it was already time to dive into the programming side of physical computing. Lab #2 consisted of wiring up a simple circuit with a switch and a couple of LEDs and being able to program a Arduino board to process simple logic through authored code. After working through the previous lab - I found the circuit-boarding side of this lab to be far easier, even with the addition of the Arduino microprocessor, which as the time was completely foreign to me. Below are a couple of pictures of the process, plus a link to the source code for my first Arduino program.



Fig 1.1: First success using Arduino


Fig 1.2: Using a simple switch logic gate


Fig 1.3: Six LEDs blinking one after another


Source Code: six_led_lights


Note: I have noticed that one of the (many) limitations of the programming language initially available to use with the Ardunio microprocessor is the inability to directly get the size of an array through a method or any sort of standalone function. This becomes problematic when needing to accurately loop through an array of LED pins, or anything else stored in an array for that matter. A way around this limitation without resorting to counting the elements manually and hard-coding that number to a variable is to instead use the following code, as additionally outlined in my source code.

int led_pins[] = {3,4,5,6,7,8};
int led_pin_count = sizeof(led_pins) / 2;


The global function 'sizeof' returns a value which represents the number of bytes currently stored in a given variable. Since we can assume that an integer is 2 bytes; dividing the value sizeof returns by 2 will result in the elemental size of our array.

No comments: