Hi, today my hair is going grey.
I really dont understand why this code dont work, nothing on serial when pressing buttons
buttons is connected between GND and GPIO.
I run this on an ESP32 OLED LiLigo
const int nextPin = 34; // les next kube data, knapp til høyre
const int previousPin = 35; // les previous kube data, knapp til venstre
int previousButtonState; // the current reading from the input pin
int lastpreviousButtonState = HIGH; // the previous reading from the input pin
unsigned long lastpreviousDebounceTime = 0; // the last time the output pin was toggled
int nextButtonState; // the current reading from the input pin
int lastnextButtonState = HIGH; // the previous reading from the input pin
unsigned long lastnextDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(previousPin, INPUT_PULLUP);
pinMode(nextPin, INPUT_PULLUP);
Serial.begin(115200); // Start seriell kommunikasjon for debugging
}
void loop() {
// read the state of the switches into local variables:
int previousReading = digitalRead(previousPin);
int nextReading = digitalRead(nextPin);
// Debounce previousPin
if (previousReading != lastpreviousButtonState) {
lastpreviousDebounceTime = millis();
}
if ((millis() - lastpreviousDebounceTime) > debounceDelay) {
if (previousReading != previousButtonState) {
previousButtonState = previousReading;
if (previousButtonState == LOW) {
Serial.println("Previous button");
}
}
}
lastpreviousButtonState = previousReading;
// Debounce nextPin
if (nextReading != lastnextButtonState) {
lastnextDebounceTime = millis();
}
if ((millis() - lastnextDebounceTime) > debounceDelay) {
if (nextReading != nextButtonState) {
nextButtonState = nextReading;
if (nextButtonState == LOW) {
Serial.println("Next button");
}
}
}
lastnextButtonState = nextReading;
}
