This lab will requires the same setup as last week. However, breadboard space is limited and some planning will be required to fit everything nicely on the board. You will be making an LED array that will display different patterns based on three types of input: a pushbutton, an optical encoder and a potentiometer. You should make an electrical circuit that is based on the following electrical schematic. The code that you will be experimenting with relies on using the input and output pin numbers provided. In addition to that, you’ll be lightly modifying some provided sketches.

Larger image here.
Take the LEDs given to you in your kit and build a line of LED’s. Remember to select suitable pull-up resistors that are around 1k ohms. The SN7417 (datasheet) can only sink 40mA.

larger image here
There are three different types of inputs that we’ll be exploring: digital input with a tactile switch, digital input with an optical encoder, and analog input with a potentiometer.
The pushbutton is connects two points in a circuit when you press it. The pushbutton sits between a pull-up resistor and ground. A pull-up resistor is a resistor used to force the wire to settle to a HIGH state, and prevent excess current from flowing into your circuit. When the switch is pressed, voltage at the input to the 74LS14 (datasheet) is then 0.
Optical encoders (datasheet) are a way to measure rotational position, and velocity. Two photodiodes are offset at 90 degrees and based on pulse frequency and the difference of the pulses from the diodes, one can figure out rotational position and direction of rotation. Make sure that you are correctly supplying voltage to the encoder. Applying voltage wrongly can break this $50 part.
The potentiometer will be the only analog input that you will be using. As described in lab 1, a voltage follower using either the OAP4342 (datasheet) or the TLV2374 (datasheet) acts to separate the voltage from the potentiometer and the signal voltage.
Larger image available
First, verify that your completed LED array works correctly by loading the provided sketch “BlinkAll”. This should cause the LED’s to blink in unison. To demonstrate digital input, we will be controlling the LED’s with a pushbutton.
Push buttons, like the one used in lab, have a tactile response due to a leaf spring that is inside. A single button press will often result in physical rebounding that can send tiny little bounces. The image below shows both the actual response (top) and a digital interpretation (bottom) of a switch.

Analog input is another way of encoding information into the digital realm. The Arduino measures voltages between 0V and 5V with an ADC; it then scales the measured voltages to an integer value between 0 and 1023. In this part of the lab, you will be using a potentiometer to control the luminosity of the LED’s. The Arduino’s analogWrite() function really outputs a PWM signal. Due to the use of the inverter, analogWrite(0) is a 100% duty cycle whereas analogWrite(255) is a 0% duty cycle.
Sometimes, you may run across a sensor or actuator for which other people have written a library. Libraries generally simplify your code by creating a layer of abstraction that removes low level details. For example, instead of decoding the pulses of a quadrature encoder to figure out rotational change, you only need to call a “helper” function to determine its position. There are many tested libraries available at http://arduino.cc/en/Reference/Libraries.
The Arduino does not have a built in quadrature encoder, and this makes it difficult to use optical encoders for motor control. Dedicated IC’s for quadrature decoding such as the HP HCTL 20XX. They range between $10 and $20 per chip, and will require some thinking to implement them properly.
You must have a board that completes all the following:
A fantastic introduction to debouncing and various algorithms devised to resolve it.
The source of the quadrature library. This guy is also creating a CNC printer with the Arduino.