/*
  #######################################################
  ||                                                   ||
  ||      Title: integer Serial Read and Display       ||
  ||                   Name: GC1CEO                    ||
  ||                 Date: 09/16/2024                  ||
  ||                                                   ||
  ||                   Description:                    ||
  ||                                                   ||
  ||Program reads a value from 0 to 255 from the Serial||
  ||Monitor, converts it into binary and displays it on||
  ||                      8 LEDs.                      ||
  ||                                                   ||
  #######################################################

  This example uses the Logic Analyzer and shows what happens when
  a number is inputted. I added an IF statement to stop it from
  constantly shifting out the last number inputted so that it compares
  the previous number to the inputted number.

  The DATA/DS line stays high when not in use, the LATCH/STCLK is pulled
  LOW when a byte is inputted and when pulled HIGH it outputs that number
  if OE is set to HIGH.
*/
//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;

int incomingNum = 0;
int prevNum = 0;
String inputNum;

void setup() {
  Serial.begin(9600);

  //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("");
  }
  Serial.println("Please enter a number (from 0 to 255).");
}
void loop() {


  if (Serial.available() > 0) {
    
    inputNum = Serial.readString();
    incomingNum = inputNum.toInt();
    
    
    }
  if (incomingNum != prevNum) {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, incomingNum);
  digitalWrite(latchPin, HIGH);
  prevNum = incomingNum;
  }
}


$abcdeabcde151015202530354045505560fghijfghij
74HC595
D0D1D2D3D4D5D6D7GNDLOGIC