Stop the Blinking Light!
I was really excited when I made my first project
blink. Talking to others, they usually feel the same. (I bet
you did too!) There’s something mesmerizingly satisfying
about making a light turn on and off. However, it
becomes a little repetitive after a while — on ... off ... on ...
off ... once every second. A thousand blinks later and it’s
just plain annoying — probably has you reaching for the
power connector! This month, we’ll learn how we can
stop that blinking light (without pulling the power) by
building projects to interact more fully with the user —
we’ll be exploring digital and analog inputs.
Flashback to the Arduino Uno
This series is intended to take you beyond the
Arduino. Before we kick off with the bare-metal
microcontroller, let’s quickly look back at how the Uno
handles inputs so we have a common departure point.
The Arduino boards have a number of pins marked as
digital only; on the Uno, these are pins 0 to 13. In
addition to these 14 pins, you can use the analog pins (A0
to A5) as digital inputs.
To read a digital input from a pin, you need to:
1. Let the Arduino Uno know you want to use the pin
as an input, and set the internal pull-up resistor if
needed by using the pinMode() function.
2. Read the value from the pin, using the digitalRead()
Remember when using inputs that you must connect
a pull-up or pull-down resistor, or use the internal pull-up
resistor on the pin. This stops the pin from floating by
pulling it to a known high/low state. A look at the
ATmega328 datasheet tells us that the internal pull-up
resistor ranges between 20 kΩ and 50 kΩ.
Only pins A0 to A5 can be used as analog inputs on
the Arduino Uno. They return a value from 0 to 1023 (i.e.,
they have 10-bit precision) which represents voltage levels
between 0V and a specified “voltage reference.” On the
Uno, this voltage reference defaults to 5V. We’ll touch
more on reference voltages later.
To read an analog input from a pin, you need to:
Beyond the Beyond the
36 May 2015
The “Ins” of an AVR Microcontroller
Last month, we managed to get
our breadboard-based AVR
microcontroller project blinking at
us using Atmel Studio. This month,
we’re going to focus on interacting
with the bare-metal microcontroller
by handling inputs — both digital
and analog. We’ll also pull the first
three articles together by building
a simple game.
Figure 1: An
overview of the