/*
##############################################
|| ||
|| Title: Integer Serial Read and Display ||
|| Name: GC1CEO ||
|| Date: 09/19/2024 ||
|| ||
|| Description: ||
|| ||
|| Reads a number between 0 and 65,535 from ||
||serial and outputs it in binary code among||
|| 2 shift registers and 16 LEDs. ||
|| ||
##############################################
*/
//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;
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 65535).");
}
void loop() {
if (Serial.available() > 0) {
inputNum = Serial.readString();
incomingNum = inputNum.toInt();
}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, (incomingNum >> 8));
shiftOut(dataPin, clockPin, MSBFIRST, incomingNum);
digitalWrite(latchPin, HIGH);
}