I'll try to explain what I'm seeing here. I'm trying out a concept by sending a number from the serial monitor to the Arduino, which sends the binary equivalent to LEDs through a 74HC595 shift register. If I send any number which includes the lowest bit, i.e. an odd number, there is a 2 to 3 second delay before the LEDs are energized. There is no delay for even numbers that don't include the lowest bit.
For example If I send 90 there is an immediate response. If I send 89 or 91, I see the delay. It doesn't matter what was previously displayed. Any odd number, even if twice in a row gets the delay.
Can someone explain what is happening here?
// Pin connections to 74HC595
const int latchPin = 8; // To 74HC595 pin 12
const int clockPin = 12; // To 74HC595 pin 11
const int dataPin = 11; // To 74HC595 pin 14
byte outputData = 0; // Stores the byte to send
void setup() {
pinMode(dataPin, OUTPUT); // Serial data to register
pinMode(latchPin, OUTPUT); // Latches register outputs
pinMode(clockPin, OUTPUT); // Clock signal
Serial.begin(9600);
Serial.println("Enter a number (0-255) to send to 74HC595:");
}
/* R-R = 129 \
R-Y = 130 | These are the
R-G = 132 > five possible
Y-R = 65 | signal aspects
G-R = 33 /
*/
void loop() {
if (Serial.available() > 0) {
String input = Serial.readStringUntil('\n'); // Read until newline
input.trim(); // Remove spaces
if (input.length() > 0) {
int value = input.toInt();
if (value >= 0 && value <= 255) {
outputData = (byte)value;
digitalWrite(latchPin, LOW); // To allow data flow
shiftOut(dataPin, clockPin, MSBFIRST, outputData);
digitalWrite(latchPin, HIGH); // Hold data in register
Serial.print("Entered ");
Serial.println(outputData, DEC);
Serial.print("Binary: ");
Serial.println(outputData, BIN); // Output as binary no.
Serial.print("Hex: ");
Serial.println(outputData, HEX); // Hexadecimal equivalent
} else {
Serial.println("Invalid number. Enter 0-255.");
}
}
}
}


