const int latchPin = 8; // ST_CP
const int clockPin = 7; // SH_CP
const int dataPin = 9; // D
const int buttonPin = 2;
const int relayPin = 4;
int buttonState = HIGH;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 50;
bool isLetterH = false;
const byte letterL = ~0b00001110;
const byte letterH = ~0b00110111;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
displayPattern(letterL);
}
void displayPattern(byte pattern) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, pattern);
digitalWrite(latchPin, HIGH);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
isLetterH = !isLetterH;
displayPattern(isLetterH ? letterH : letterL);
if (isLetterH) {
digitalWrite(relayPin, HIGH);
} else {
digitalWrite(relayPin, LOW);
}}}}
lastButtonState = reading;
}
/*const int latchPin = 8; // ST_CP
const int clockPin = 7; // SH_CP
const int dataPin = 9; // D
const int buttonPin = 4;
int buttonState = HIGH;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 50;
bool isLetterH = false;
const byte letterL = ~0b00001110;
const byte letterH = ~0b00110111;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
displayPattern(letterL);
}
void displayPattern(byte pattern) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, pattern); // Use LSBFIRST
digitalWrite(latchPin, HIGH);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
isLetterH = !isLetterH;
displayPattern(isLetterH ? letterH : letterL);
}
}
}
lastButtonState = reading;
}*/