SMILEY’S WORKSHOP ☺
• Note that AVRDude ends with “avrdude done.
Thank You.” Now that is class! Especially for a
free program, so go to their website and donate
Press the Arduino reset button and pin 9 should
blink once per second. We have now done the Blink
example TAW last month and converted it to ACW
Next, we will start doing some hardware projects
that let us convert more of the Arduino examples
from TAW to ACW.
Debouncing a Pushbutton
Converting the Arduino Debounce example to
C for AVRStudio is much like converting the Blink
example, but I want to repeat the steps — condensed
a bit — to help reinforce the conversion process:
■FIGURE 9. AVRDude upload.
• Create new directory C:\Arduino ToAVRStudio-
• Copy the core Arduino files to our Debounce directory
from the Arduino-0013\hardware\cores\Arduino\
• Create new AVRStudio project Debounce in
• Copy the Arduino Debounce example to Debounce.c
• Change the inPin from 7 to 8:
int inPin = 8; // number of the input pin
• Change the outPin from 13 to 9 and outPin from:
int outPin = 9; // number of the output pin
• Add #include “wiring.h” to the top of the file.
• Add the main() program shown in the Blink
source code above.
• Compile and don’t worry about the warnings.
• Go to the Windows Start Button and click on Run.
• Open: cmd.
• After > type cd C:\Arduino ToAVRStudio-debounce\default.
• After > type: avrdude -p m328p -c avrisp -P
com6 -b 57600 -F -U flash:w:Debounce.hex
remembering that your device may not be on
• Press the reset button on the Arduino and the
enter key on the PC.
essentially a very expensive light switch, but who said
learning was cheap?
Using PWM to Fade an LED
We can use the LED attached to pin 9 to demonstrate
PWM (Pulse Width Modulation). Figure 12 shows the
ALPs being waved up and down with the LED fading in
and out. Notice that the red streaks seem like beads
whereas the green streaks are smooth. This is because the
red LED is being turned on and off every 33. 3 times per
second, with the on time varying. The camera lens was left
open to capture several hundred of those intervals. Look
at the center of the red streaks and you will see each red
‘bead’ gets progressively brighter until they seem to blend
■FIGURE 10. Schematic for LED and pushbutton.
The AVRStudio version of the Debounce code
is also available in the Workshop10.zip. And, as a
reminder, yes — this is harder than using the
Arduino IDE, but it provides a clear path to C programming using the Atmel official tools, which is
the direction I’ll be going with future Workshops.
Push the button and the LED state toggles
between on and off. That was fun, and now, as
shown in Figures 10 and 11, you have what is
May 2009 65