/*
#####################################################
|| ||
|| Title: One by One ||
|| Created by: Carlyn Maw, Tom Igoe ||
|| Date: 25 Oct, 2006 ||
|| Adapted by: GC1CEO ||
|| ||
|| Sends one byte at the time which turns on 1 bit ||
|| at a time going from right to left. ||
|| ||
|| ||
#####################################################
*/
//Pin connected to ST_CP (Storage Clock / Latch) of 74HC595
int latchPin = 8;
//Pin connected to SH_CP (Shift Clock) of 74HC595
int clockPin = 12;
////Pin connected to DS / SER (Data/Serial Input) of 74HC595
int dataPin = 11;
////Pin connected to inverted MR / SRCLR (Master Reset / Serial Register Clear) of 74HC595
int resetPin = 10;
////Pin connected to inverted OE (Output Enable) of 74HC595
int oePin = 9;
void setup() {
Serial.begin(9600);
Serial.println("reset");
//set pins to output so you can control the shift register and setting button and pot pins to INPUT
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(resetPin, OUTPUT);
pinMode(oePin, OUTPUT);
// Setting reset to HIGH to stop reset and setting output enable to LOW to always enable output
digitalWrite(resetPin, HIGH);
digitalWrite(oePin, LOW);
// Cleaning up serial monitor and announcing program has initalized and going to loop
Serial.println();
Serial.println();
Serial.println();
Serial.println();
Serial.println();
Serial.println();
Serial.println();
Serial.print("Program initalized!");
Serial.println();
}
void loop() {
// write to the shift register with the correct bit set high:
for(int x = 0;x < 8;x++){
registerWrite(x, HIGH);
delay(400);
}
}
// This method sends bits to the shift register:
void registerWrite(int whichPin, int whichState) {
// the bits you want to send
byte bitsToSend = 0;
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);
// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}