From 1e7a41f86ccb3e010be4034d1d6246a8e36c1fa6 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 7 Oct 2023 23:28:26 +0200 Subject: [PATCH] add encodeur test --- include/Program.h | 4 ++-- src/Program.cpp | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/Program.h b/include/Program.h index 5209e17..205afc3 100644 --- a/include/Program.h +++ b/include/Program.h @@ -5,7 +5,7 @@ #include #include "DiscordAPI.h" -#include "Encoder.h" +#include "SwitchableEncodeur.h" @@ -24,7 +24,7 @@ private: /** * Encoder object */ - Encoder* encoder; + SwitchableEncodeur* encoder; /** * Old encoder position diff --git a/src/Program.cpp b/src/Program.cpp index 452d653..a51c432 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -1,9 +1,12 @@ #include "Program.h" + Program::Program() { - // Startup + + // Startup Serial Serial.begin(MONITOR_SPEED); + // Startup WiFi WiFi.begin(WSSID, PASS); Serial.print("Connecting to "); @@ -12,7 +15,8 @@ Program::Program() { int i = 0; while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect delay(1000); - Serial.print(++i); Serial.print(' '); + Serial.print(++i); + Serial.print(' '); } Serial.println('\n'); @@ -20,21 +24,19 @@ Program::Program() { Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer - - + // Startup Discord API this->discord = new DiscordAPI(DISCORD_HOOK); delay(1000); Serial.println(this->discord->sendHeure("10h", "18h")); - this->encoder = new Encoder(ENCODER_DT, ENCODER_CLK); - - this->oldPosition = -999; + // Startup Encoder + this->encoder = new SwitchableEncodeur(ENCODER_DT, ENCODER_CLK, ENCODER_SWITCH, 3); } void Program::loop() { - long newPosition = this->encoder->read()/4; - if (newPosition != this->oldPosition) { - this->oldPosition = newPosition; - Serial.println(newPosition); + if(this->encoder->update()){ + Serial.print(this->encoder->getValue()); + Serial.print(" "); + Serial.println(this->encoder->getMenu()); } }