| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- /*
- * TreePositionSwitch.cpp
- *
- * Created on: 21.12.2025
- * Author: FSmilari
- */
-
- #include "TreePositionSwitch.h"
-
- /*****************
- ** Constructors.
- ****************/
- TreePositionSwitch::TreePositionSwitch(int Pos1Pin, int Pos2Pin, int Pos3Pin) : Pos1_Pin(Pos1Pin), Pos2_Pin(Pos2Pin), Pos3_Pin(Pos3Pin), actualPosition(-1) {
- lastDebounceTime = 0;
-
- pinMode(Pos1_Pin, INPUT_PULLUP);
- pinMode(Pos2_Pin, INPUT_PULLUP);
- pinMode(Pos3_Pin, INPUT_PULLUP);
- }
-
- void TreePositionSwitch::loop(void) {
- int currentReadPosition = -1;
-
- if (digitalRead(Pos1_Pin) == LOW) {
- currentReadPosition = 1;
- }
- else if (digitalRead(Pos2_Pin) == LOW) {
- currentReadPosition = 2;
- }
- else if (digitalRead(Pos3_Pin) == LOW) {
- currentReadPosition = 3;
- }
-
- // Änderung erkannt?
- if (currentReadPosition != lastReadPosition) {
- lastDebounceTime = millis();
- lastReadPosition = currentReadPosition;
- }
-
- // Zustand stabil genug?
- if ((millis() - lastDebounceTime) >= debounceTime) {
- actualPosition = lastReadPosition;
- }
- }
-
- int TreePositionSwitch::getPosition(void) {
- return actualPosition;
- }
- void TreePositionSwitch::setDebounceTime(unsigned long time) {
- lastDebounceTime = time;
- }
|