| @@ -26,6 +26,8 @@ | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/Adafruit_BusIO}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/LCDWIKI_GUI}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/LCDWIKI_SPI}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/ezButton/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/RotaryEncoder/src}""/> | |||
| </option> | |||
| <inputType id="io.sloeber.compiler.cpp.sketch.input.543353444" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | |||
| </tool> | |||
| @@ -38,6 +40,8 @@ | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/Adafruit_BusIO}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/LCDWIKI_GUI}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/LCDWIKI_SPI}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/ezButton/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/RotaryEncoder/src}""/> | |||
| </option> | |||
| <inputType id="io.sloeber.compiler.c.sketch.input.1984508786" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | |||
| </tool> | |||
| @@ -50,6 +54,8 @@ | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/Adafruit_BusIO}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/LCDWIKI_GUI}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/LCDWIKI_SPI}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/ezButton/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/EchoLot/libraries/RotaryEncoder/src}""/> | |||
| </option> | |||
| <inputType id="io.sloeber.compiler.S.sketch.input.2093386672" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | |||
| </tool> | |||
| @@ -56,6 +56,11 @@ | |||
| <type>2</type> | |||
| <location>C:/Users/FSmilari/Documents/Arduino/libraries/LCDWIKI_SPI</location> | |||
| </link> | |||
| <link> | |||
| <name>libraries/RotaryEncoder</name> | |||
| <type>2</type> | |||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/RotaryEncoder/1.5.2</locationURI> | |||
| </link> | |||
| <link> | |||
| <name>libraries/SPI</name> | |||
| <type>2</type> | |||
| @@ -66,5 +71,10 @@ | |||
| <type>2</type> | |||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.4/libraries/Wire</locationURI> | |||
| </link> | |||
| <link> | |||
| <name>libraries/ezButton</name> | |||
| <type>2</type> | |||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/ezButton/1.0.3</locationURI> | |||
| </link> | |||
| </linkedResources> | |||
| </projectDescription> | |||
| @@ -1,21 +1,11 @@ | |||
| #include "Arduino.h" | |||
| #include <LCDWIKI_GUI.h> // core graphics library | |||
| #include <LCDWIKI_SPI.h> // hardware-specific library | |||
| #include "RotaryControler.h" | |||
| const int trigPin = 12; | |||
| const int echoPin = 10; | |||
| //#define MODEL SSD1283A | |||
| //#define CS 10 | |||
| //#define CD 9 | |||
| //#define SDA 7 | |||
| //#define MOSI SDA | |||
| //#define SCK 13 | |||
| //#define RST 8 | |||
| //#define LED -1 //if you don’t need to control the LED pin,you should set it to -1 and set it to 3.3V | |||
| // | |||
| //LCDWIKI_SPI mylcd(MODEL, CS, CD, MISO, MOSI, RST, SCK, LED); | |||
| #define BLACK 0x0000 | |||
| #define BLUE 0x001F | |||
| #define RED 0xF800 | |||
| @@ -32,9 +22,17 @@ const int echoPin = 10; | |||
| #define RST A4 | |||
| #define CS A5 | |||
| static const int RotEnc_Switch_Pin = 2; | |||
| static const int RotEnc_Clk_Pin = 3; | |||
| static const int RotEnc_Dta_Pin = 4; | |||
| static const int Measure_Pin = 8; | |||
| String lastDistance = ""; | |||
| LCDWIKI_SPI mylcd(MODEL, CS, CD, MISO, MOSI, RST, SCK, LED); //software spi,model,cs,cd,miso,mosi,reset,clk,led | |||
| RotaryControler RotaryControler(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotEnc_Switch_Pin); | |||
| ExEzButton MeasureBtn(Measure_Pin, false, 2000); | |||
| void setup() | |||
| { | |||
| @@ -44,6 +42,12 @@ void setup() | |||
| mylcd.Init_LCD(); | |||
| mylcd.Fill_Screen(BLACK); | |||
| pinMode(Measure_Pin, INPUT); | |||
| pinMode(RotEnc_Switch_Pin, INPUT); | |||
| MeasureBtn.setDebounceTime(50); | |||
| RotaryControler.setDebounceTime(50); | |||
| } | |||
| void loop() | |||
| @@ -65,38 +69,50 @@ void loop() | |||
| // mylcd.Fill_Screen(0x001F); | |||
| // delay(3000); | |||
| MeasureBtn.loop(); | |||
| RotaryControler.loop(); | |||
| mylcd.Set_Text_Mode(1); | |||
| mylcd.Set_Text_colour(WHITE); | |||
| mylcd.Set_Text_Back_colour(RED); | |||
| mylcd.Set_Text_Size(2); | |||
| digitalWrite(trigPin, LOW); | |||
| delayMicroseconds(5); | |||
| if (RotaryControler.isSwitchPressed()) { | |||
| Serial.println("RotaryEnc SwitchPressed"); | |||
| } | |||
| digitalWrite(trigPin, HIGH); | |||
| delayMicroseconds(20); | |||
| digitalWrite(trigPin, LOW); | |||
| if (MeasureBtn.isPressing()) { | |||
| long duration = pulseIn(echoPin, HIGH); | |||
| long distance = duration * 0.03432 / 2; | |||
| digitalWrite(trigPin, LOW); | |||
| delayMicroseconds(5); | |||
| digitalWrite(trigPin, HIGH); | |||
| delayMicroseconds(20); | |||
| digitalWrite(trigPin, LOW); | |||
| // Serial.print("duration:"); | |||
| // Serial.println(duration); | |||
| long duration = pulseIn(echoPin, HIGH); | |||
| long distance = duration * 0.03432 / 2; | |||
| // Serial.print("Distance:"); | |||
| Serial.println(distance); | |||
| // Serial.print("duration:"); | |||
| // Serial.println(duration); | |||
| // Serial.print("Distance:"); | |||
| // Serial.println(distance); | |||
| char buf[50]; | |||
| sprintf(buf, "%lu cm", distance); | |||
| char buf[50]; | |||
| sprintf(buf, "%lu cm", distance); | |||
| if (!lastDistance.equals(buf)) { | |||
| mylcd.Fill_Rect(0, 48, 130, 20, RED); | |||
| mylcd.Print_String(buf, 30, 50); | |||
| delay(100); | |||
| lastDistance = buf; | |||
| } | |||
| if (!lastDistance.equals(buf)) { | |||
| mylcd.Fill_Rect(0, 48, 130, 20, RED); | |||
| mylcd.Print_String(buf, 30, 50); | |||
| delay(100); | |||
| lastDistance = buf; | |||
| delay(200); | |||
| } else { | |||
| mylcd.Fill_Screen(BLACK); | |||
| } | |||
| delay(200); | |||
| } | |||
| //void setup() { | |||
| @@ -126,7 +142,7 @@ void loop() | |||
| // long distance = duration * 0.03432 / 2; | |||
| // | |||
| // Serial.print("duration:"); | |||
| // Serial.println(duration); | |||
| // Serial.println(duration);; | |||
| // | |||
| // Serial.print("Distance:"); | |||
| // Serial.println(distance); | |||
| @@ -0,0 +1,81 @@ | |||
| /* | |||
| * Implementation of ExEzButton.h | |||
| * | |||
| * Erstellt: 05.01.2021 | |||
| * Autor: Flo Smilari | |||
| */ | |||
| #include "ExEzButton.h" | |||
| /***************** | |||
| ** Constructors. | |||
| ****************/ | |||
| ExEzButton::ExEzButton(int pin) : | |||
| ExEzButton(pin, false) { | |||
| } | |||
| ExEzButton::ExEzButton(int pin, bool _inverted) : | |||
| ExEzButton(pin, _inverted, 2000) { | |||
| } | |||
| ExEzButton::ExEzButton(int pin, bool _inverted, int _longpressTime) : | |||
| ezButton(pin) { | |||
| inverted = _inverted; | |||
| longpressTime = _longpressTime; | |||
| pressedTime = 0; | |||
| releasedTime = 0; | |||
| } | |||
| /****************** | |||
| ** Public methods | |||
| *****************/ | |||
| void ExEzButton::loop(void) { | |||
| int lastSteadyStateBefore = getState(); | |||
| ezButton::loop(); | |||
| int lastSteadyStateAfter = ezButton::getState(); | |||
| if (lastSteadyStateBefore != lastSteadyStateAfter) { | |||
| if (!inverted) { | |||
| if (lastSteadyStateBefore == LOW && lastSteadyStateAfter == HIGH) { | |||
| pressedTime = millis(); | |||
| releasedTime = 0; | |||
| } else if (lastSteadyStateBefore == HIGH && lastSteadyStateAfter == LOW) { | |||
| releasedTime = millis(); | |||
| } | |||
| } else { | |||
| if (lastSteadyStateBefore == HIGH && lastSteadyStateAfter == LOW) { | |||
| pressedTime = millis(); | |||
| releasedTime = 0; | |||
| } else if (lastSteadyStateBefore == LOW && lastSteadyStateAfter == HIGH) { | |||
| releasedTime = millis(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| bool ExEzButton::isPressed() { | |||
| bool pressed; | |||
| if (!inverted) { | |||
| pressed = ezButton::isPressed(); | |||
| } else { | |||
| pressed = (ezButton::getPreviousState() == LOW && ezButton::getState() == HIGH); | |||
| } | |||
| return (pressed && pressedTime > 0 && releasedTime > 0 && (releasedTime - pressedTime) < longpressTime); | |||
| } | |||
| bool ExEzButton::isLongPressed() { | |||
| if (releasedTime != 0) { | |||
| unsigned long long pressDuration = releasedTime - pressedTime; | |||
| bool longPressed = (pressDuration > longpressTime); | |||
| if (longPressed) { | |||
| pressedTime = 0; | |||
| releasedTime = 0; | |||
| } | |||
| return longPressed; | |||
| } | |||
| return false; | |||
| } | |||
| bool ExEzButton::isPressing() { | |||
| return ezButton::getState() == HIGH; | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| /* | |||
| * ExEzButton, supports long press detection. Inherits from ezButton. | |||
| * | |||
| * Erstellt: 05.01.2021 | |||
| * Autor: Flo Smilari | |||
| */ | |||
| #include <ezButton.h> | |||
| #include "Loopable.h" | |||
| class ExEzButton: public ezButton, public Loopable { | |||
| private: | |||
| bool inverted; | |||
| unsigned long longpressTime; | |||
| unsigned long pressedTime; | |||
| unsigned long releasedTime; | |||
| public: | |||
| ExEzButton(int pin); | |||
| ExEzButton(int pin, bool _inverted); | |||
| ExEzButton(int pin, bool _inverted, int _longpressTime); | |||
| bool isPressing(void); | |||
| bool isPressed(); | |||
| bool isLongPressed(void); | |||
| void loop(void) override; | |||
| }; | |||
| //Added by Sloeber | |||
| #pragma once | |||
| @@ -0,0 +1,19 @@ | |||
| /* | |||
| * Looper.h | |||
| * | |||
| * Created on: 01.03.2022 | |||
| * Author: FSmilari | |||
| */ | |||
| #ifndef LOOPABLE_H_ | |||
| #define LOOPABLE_H_ | |||
| class Loopable { | |||
| public: | |||
| virtual void loop(void); | |||
| virtual ~Loopable() { | |||
| } | |||
| }; | |||
| #endif /* LOOPABLE_H_ */ | |||
| @@ -0,0 +1,60 @@ | |||
| /* | |||
| * RotaryControler.cpp | |||
| * | |||
| * Created on: 04.02.2022 | |||
| * Author: FSmilari | |||
| */ | |||
| #include "RotaryControler.h" | |||
| /***************** | |||
| ** Constructors. | |||
| ****************/ | |||
| RotaryControler::RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin) : Encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin, | |||
| RotaryEncoder::LatchMode::FOUR3), RotarySwitch(RotEnc_Switch_Pin, true, 2000) { | |||
| position = 0; | |||
| Encoder.setPosition(position); | |||
| } | |||
| /****************** | |||
| ** Public methods | |||
| *****************/ | |||
| void RotaryControler::tick(void) { | |||
| Encoder.tick(); | |||
| } | |||
| void RotaryControler::resetPosition(void) { | |||
| Encoder.setPosition(0L); | |||
| } | |||
| long RotaryControler::getPosition(void) { | |||
| return Encoder.getPosition(); | |||
| } | |||
| int RotaryControler::getDirection(void) { | |||
| return (int) Encoder.getPosition(); | |||
| } | |||
| bool RotaryControler::isSwitchPressed(void) { | |||
| return RotarySwitch.isPressed(); | |||
| } | |||
| bool RotaryControler::isSwitchLongPressed(void) { | |||
| return RotarySwitch.isLongPressed(); | |||
| } | |||
| void RotaryControler::setDebounceTime(unsigned long time) { | |||
| RotarySwitch.setDebounceTime(time); | |||
| } | |||
| void RotaryControler::loop(void) { | |||
| RotarySwitch.loop(); | |||
| Encoder.tick(); | |||
| } | |||
| RotaryEncoder::Direction RotaryControler::getEncoderMove() { | |||
| RotaryEncoder::Direction dir = Encoder.getDirection(); | |||
| return dir; | |||
| } | |||
| @@ -0,0 +1,34 @@ | |||
| /* | |||
| * RotaryControler.h | |||
| * | |||
| * Created on: 04.02.2022 | |||
| * Author: FSmilari | |||
| */ | |||
| #ifndef ROTARYCONTROLER_H_ | |||
| #define ROTARYCONTROLER_H_ | |||
| #include "RotaryEncoder.h" | |||
| #include "ExEzButton.h" | |||
| class RotaryControler: public Loopable { | |||
| private: | |||
| RotaryEncoder Encoder; | |||
| ExEzButton RotarySwitch; | |||
| long position; | |||
| public: | |||
| RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin); | |||
| void tick(void); | |||
| void resetPosition(void); | |||
| bool isSwitchPressed(void); | |||
| bool isSwitchLongPressed(void); | |||
| long getPosition(void); | |||
| int getDirection(void); | |||
| RotaryEncoder::Direction getEncoderMove(); | |||
| void setDebounceTime(unsigned long time); | |||
| void loop(void) override; | |||
| }; | |||
| #endif /* ROTARYCONTROLER_H_ */ | |||
| @@ -0,0 +1,52 @@ | |||
| /* | |||
| * 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; | |||
| } | |||
| @@ -0,0 +1,32 @@ | |||
| /* | |||
| * TreePositionSwitch.h | |||
| * | |||
| * Created on: 21.12.2025 | |||
| * Author: FSmilari | |||
| */ | |||
| #ifndef TREEPOSITIONSWITCH_H_ | |||
| #define TREEPOSITIONSWITCH_H_ | |||
| #include "RotaryEncoder.h" | |||
| #include "ExEzButton.h" | |||
| class TreePositionSwitch: public Loopable { | |||
| private: | |||
| int actualPosition; | |||
| int Pos1_Pin; | |||
| int Pos2_Pin; | |||
| int Pos3_Pin; | |||
| unsigned long lastDebounceTime = 0; | |||
| unsigned long debounceTime = 50; // Standard 50 ms | |||
| int lastReadPosition = -1; | |||
| public: | |||
| TreePositionSwitch(int Pos1_Pin, int Pos2_Pin, int Pos3_Pin); | |||
| int getPosition(void); | |||
| void setDebounceTime(unsigned long time); | |||
| void loop(void) override; | |||
| }; | |||
| #endif /* TREEPOSITIONSWITCH_H_ */ | |||
| @@ -2,12 +2,13 @@ | |||
| //This is a automatic generated file | |||
| //Please do not modify this file | |||
| //If you touch this file your change will be overwritten during the next build | |||
| //This file has been generated on 2025-12-20 14:02:50 | |||
| //This file has been generated on 2025-12-21 14:22:01 | |||
| #include "Arduino.h" | |||
| #include "Arduino.h" | |||
| #include <LCDWIKI_GUI.h> | |||
| #include <LCDWIKI_SPI.h> | |||
| #include "RotaryControler.h" | |||
| void setup() ; | |||
| void loop() ; | |||