/*

  ####################################################
  ||                                                ||
  ||Title: Serial Read with a 74HC595 Shift Register||
  ||                  Name: GC1CEO                  ||
  ||                Date: 09/17/2024                ||
  ||                  Attribution:                  ||
  ||        Based on shiftOutCode, All Cycle        ||
  ||    by Carlyn Maw,Tom Igoe, David A. Mellis     ||
  ||      Date: 10/25/2006 Modified: 3/23/2010      ||
  ||                                                ||
  ||                  Description:                  ||
  ||   This program cycles through 8 of the LEDs,   ||
  ||  lighting up at a time from right to left and  ||
  ||        then repeats this process again.        ||
  ||                                                ||
  ####################################################

*/

//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
  for(int a = 0; a < 25; a++) {
    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(1000);

  }

}

// 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:

  // MSBFIRST starts from the right and LSBFIRST would start from the left

  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

  // move the byte from the shift register to the storage register which
  // if oePin is HIGH will immediately output it to the LEDs.

  digitalWrite(latchPin, HIGH);

}
$abcdeabcde151015202530354045505560fghijfghij
74HC595