I followed this tutorial; the schematics or the breadboard layout is more complicated that the ones that we've been experimenting on in the past. Wires cross over one another. I think the most difficult part was putting things in the right place. Well. at least we learned about the shift resistor.
Materials:
1. Arduino Board
2. Jumper wires
3. Shift resistor
4. 270 resistors (need 8 of these)
5. LED (need 8 of these)
6. Breadboard
Every micro controller has a limited amount of pin for input and output, so by using shift resistor, it connects to the breadboard, allowing us to have more pin for input and output. If the circuit is complete, the LED would take turn to light up, one after the other. One of my friend managed to get 7 out of 8 LEDs light up. However, while he was trying to complete the whole circuit, one of the wire or resistor was loose and so he lost the whole circuit's connection. Only Mr. Robert's (our teacher) circuit worked.
/*
Adafruit Arduino - Lesson 4. 8 LEDs and a Shift Register
*/
int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
byte leds = 0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
leds = 0;
updateShiftRegister();
delay(500);
for (int i = 0; i < 8; i++)
{
bitSet(leds, i);
updateShiftRegister();
delay(500);
}
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}