// https://microcontrollerslab.com/esp32-pinout-use-gpio-pins/
// https://github.com/espressif/arduino-esp32
// https://github.com/espressif/arduino-esp32/tree/master/cores/esp32
// https://github.com/johnrickman/LiquidCrystal_I2C
//--------------------------------------------------
// Includes:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//--------------------------------------------------
// Globals:
// LCD Objekt erzeugen
// - I2C Adresse: 0x27
// - Zeichen pro Zeile: 16
// - Anzahl Zeilen: 2
LiquidCrystal_I2C myLCD = LiquidCrystal_I2C(0x27, 16, 2);
volatile int32_t gCounter;
//--------------------------------------------------
void setup() {
//---
// Init USART:
Serial.begin(115200);
Serial.println("Hallo BBW !!!");
//---
// Init LCD:
myLCD.init();
myLCD.backlight();
// Write LCD
myLCD.setCursor(0, 0);
myLCD.printf("Hallo BBW !!!");
//---
// Init Pin 34 als INPUT mit internem Pulldown-Widerstand.
// Der Default-Zustand am Pin ist so LOW.
pinMode(34, INPUT_PULLDOWN);
// Init Interrupt:
// - Pin 34 ist Quelle für Interrups.
// - Signalwechsel von LOW nach HIGH löst Interrup aus.
// - Bei einem Interrupt wird die Funktione inkrementISR() ausgeführt.
attachInterrupt(34, inkrementISR, RISING);
//---
// Init Pin 35 als INPUT mit internem Pulldown-Widerstand.
// Der Default-Zustand am Pin ist so LOW.
pinMode(35, INPUT_PULLDOWN);
// Init Interrupt:
// - Pin 35 ist Quelle für Interrups.
// - Signalwechsel von LOW nach HIGH löst Interrup aus.
// - Bei einem Interrupt wird die Funktione dekrementISR() ausgeführt.
attachInterrupt(35, dekrementISR, RISING);
}
//--------------------------------------------------
void loop() {
// Wait 500ms (2Hz)
delay(500);
Serial.println(gCounter);
myLCD.setCursor(0, 0);
myLCD.printf("%d", gCounter);
}
//--------------------------------------------------
void ARDUINO_ISR_ATTR inkrementISR() {
if (gCounter != INT_MAX)
gCounter++;
else
gCounter = INT_MIN;
}
//--------------------------------------------------
void ARDUINO_ISR_ATTR dekrementISR() {
if (gCounter != INT_MIN)
gCounter--;
else
gCounter = INT_MAX;
}