When my Arduino arrived, I couldn't wait to do something, anything. The kids were almost as excited as I was. But right away, they were ready to start building a robot. It will be tough to convince them of the need to learn a lot of theory before diving in.
First Sketch
I had read that the Arduino had a permanent LED mounted on the board, attached to pin 13. Since I have no other devices or LEDs to attached to the board, this would have to suffice. With that in mind, I planned to blink that LED, the Arduino equivalent of "Hello World," the first program that almost every programming language teaches as its first lesson. Loading the Arduino software had already been done. It merely has to be extracted from its zip file. I chose to put the development on a thumb drive so that whether I use my PC, laptop, or whatever, I would be able to carry the code with me.The next step was to install the Windows drivers. The Arduino site provides simple instructions. Plug in the Arduino to an available USB port. When Windows gives up trying to find the appropriate drivers, you close the wizard, browse to the device manager, and open the new unknown device. Open that device, click update driver, and browse to the driver folder in the Arduino development directory. The only other thing necessary is to note the com port that it is assigned.
Opening the Arduino development application, I browsed the example library and opened one under the basic heading aptly called "blink." Scanning the code:
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ // Pin 13 has an LED connected on most Arduino boards. // give it a name: int led = 13; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
[sigh]
Then I realized I hadn't selected the board. Quickly, I went to the tools->board menu and selected the "Arduino Mega 2560." Clicked upload, and this time breathed a sigh of relief as the little red LED blinked off and on. SUCCESS! Later, I showed the kids, line by line through the code, explaining variables, the two required functions, how the pinMode function prepares the pin for, in this case, output, how the digitalWrite function turns on or off the LED, and finally what the delay function does.
For fun, we played with the delay values and shortened them to see the results.
Now I have to figure out the next step...
No comments:
Post a Comment