// 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:
volatile int32_t gCounter = 0; // global volatile variable
// LCD Objekt erzeugen
// - I2C Adresse: 0x27
// - Zeichen pro Zeile: 16
// - Anzahl Zeilen: 2
LiquidCrystal_I2C myLCD = LiquidCrystal_I2C(0x27, 16, 2);
//--------------------------------------------------
// Interrupt Service Routine for pin 34
void IRAM_ATTR ISR_34() {
gCounter++; // increase global counter
}
// Interrupt Service Routine for pin 35
void IRAM_ATTR ISR_35() {
gCounter--; // decrease global counter
}
//--------------------------------------------------
void setup() {
//---
// Init USART:
Serial.begin(115200);
Serial.println("Hallo BBW !!!");
//---
// Init LCD:
myLCD.init();
myLCD.backlight();
//---
// Init Pin 34 als INPUT mit internem Pulldown-Widerstand.
// Der Default-Zustand am Pin ist so LOW.
pinMode(34, INPUT_PULLDOWN);
// Init Pin 35 als INPUT mit internem Pulldown-Widerstand.
// Der Default-Zustand am Pin ist so LOW.
pinMode(35, INPUT_PULLDOWN);
// Attach interrupt for pin 34 to interrupt function ISR_34
attachInterrupt(digitalPinToInterrupt(34), ISR_34, RISING);
// Attach interrupt for pin 35 to interrupt function ISR_35
attachInterrupt(digitalPinToInterrupt(35), ISR_35, RISING);
}
//--------------------------------------------------
void loop() {
// Wait 500ms (2Hz)
delay(500);
// Output gCounter to USART
Serial.print("gCounter = ");
Serial.println(gCounter);
// Output gCounter to LCD
myLCD.setCursor(15, 0); // set cursor to last position of first line
myLCD.printf("%6d", gCounter); // print gCounter with 6 digits, right aligned
}