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:
Post a Comment