/**************************************************
ESP32 und BBWAS1 (Teil 6) - Aufgabe 6
***************************************************/
//--------------------------------------------------
// Pin-Zuweisungen
#define PIN_TASTE_UP 17
#define PIN_TASTE_DOWN 14
// Zeitstempel
uint32_t timeStampA = 0;
uint32_t timeStampB = 0;
uint32_t timeStampC = 0;
// Zählerstand
int32_t gZaehlerstand = 0;
int32_t gZaehlerstand_Last = -1;
// Status Taste UP
bool gStatusUP = false;
bool gStatusUP_Last = false;
// Status Taste DOWN
bool gStatusDOWN = false;
bool gStatusDOWN_Last = false;
//--------------------------------------------------
void setup() {
Serial.begin(115200);
pinMode(PIN_TASTE_UP, INPUT);
pinMode(PIN_TASTE_DOWN, INPUT);
Serial.println("System gestartet...");
}
//--------------------------------------------------
void loop() {
task_A();
task_B();
task_C();
}
//--------------------------------------------------
// Serial Out @ 10 Hz
void task_A() {
if (millis() - timeStampA >= 100) {
timeStampA = millis();
//
if(gZaehlerstand != gZaehlerstand_Last) {
gZaehlerstand_Last = gZaehlerstand;
//
Serial.print("Zaehlerstand = ");
Serial.println(gZaehlerstand);
}
}
}
//--------------------------------------------------
// Taste UP und Taste DOWN lesen @ 100 Hz
void task_B() {
if (millis() - timeStampB >= 10) {
timeStampB = millis();
//
gStatusUP = digitalRead(PIN_TASTE_UP);
gStatusDOWN = digitalRead(PIN_TASTE_DOWN);
}
}
//--------------------------------------------------
// Tastendruckzähler @ 100 Hz
void task_C() {
if (millis() - timeStampC >= 10) {
timeStampC = millis();
//
// UP: LOW -> HIGH
if((gStatusUP_Last == false) && (gStatusUP == true)) {
gZaehlerstand++;
}
//
// DOWN: LOW -> HIGH
if((gStatusDOWN_Last == false) && (gStatusDOWN == true)) {
gZaehlerstand--;
}
//
gStatusUP_Last = gStatusUP;
gStatusDOWN_Last = gStatusDOWN;
}
}
UP
DOWN