From 9e206ac995c68d7e291547f8b1bde55b8a99e66f Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 24 May 2024 12:52:43 +0530 Subject: [PATCH] updated blite.cpp and blite.h . Working. Fully testedgit status --- .../05_IoT_beebot_rc_car.ino | 20 ++++++------- examples/05_IoT_beebot_rc_car/remote.h | 24 ++++++++-------- src/blite.cpp | 28 ++++++++++++++++--- src/blite.h | 19 +------------ 4 files changed, 47 insertions(+), 44 deletions(-) diff --git a/examples/05_IoT_beebot_rc_car/05_IoT_beebot_rc_car.ino b/examples/05_IoT_beebot_rc_car/05_IoT_beebot_rc_car.ino index 0b8820d..d6dfd1c 100644 --- a/examples/05_IoT_beebot_rc_car/05_IoT_beebot_rc_car.ino +++ b/examples/05_IoT_beebot_rc_car/05_IoT_beebot_rc_car.ino @@ -8,9 +8,9 @@ #define CMD_BACKWARD 2 #define CMD_LEFT 4 #define CMD_RIGHT 8 -#define CMD_PUSH 5 -#define CMD_SRVCLCK 6 -#define CMD_SRVACLCK 9 +#define CMD_LIGHT 5 +#define CMD_REVM12 6 +#define CMD_REVM34 9 #define CMD_SPD_1 10 #define CMD_SPD_2 11 #define CMD_SPD_3 12 @@ -76,16 +76,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) Serial.println("Turn Right"); myBot.turnRight(); break; - case CMD_PUSH: - Serial.println("Push button pressed"); - myBot.blinkLed(10); + case CMD_LIGHT: + Serial.println("Changing LIGHT status"); + myBot.lights(); break; - case CMD_SRVCLCK: - Serial.println("Turn servo clockwise"); + case CMD_REVM12: + Serial.println("Reverse polarity for M12"); myBot.reversePolarityM12(); break; - case CMD_SRVACLCK: - Serial.println("Turn servo anti-clockwise"); + case CMD_REVM34: + Serial.println("Reverse polarity for M34"); myBot.reversePolarityM34(); break; case CMD_SPD_1: diff --git a/examples/05_IoT_beebot_rc_car/remote.h b/examples/05_IoT_beebot_rc_car/remote.h index 5d51022..b4a60cf 100644 --- a/examples/05_IoT_beebot_rc_car/remote.h +++ b/examples/05_IoT_beebot_rc_car/remote.h @@ -123,9 +123,9 @@ var CMD_FORWARD = 1; var CMD_BACKWARD = 2; var CMD_LEFT = 4; var CMD_RIGHT = 8; -var CMD_PUSH = 5; -var CMD_SRVCLCK = 6; -var CMD_SRVACLCK = 9; +var CMD_LIGHT = 5; +var CMD_REVM12 = 6; +var CMD_REVM34 = 9; var CMD_SPD_1 = 10; var CMD_SPD_2 = 11; var CMD_SPD_3 = 12; @@ -208,17 +208,17 @@ function mouse_up(event) event.preventDefault(); } -function wc_onclickpush() +function wc_onclicklights() { - send_command(CMD_PUSH); + send_command(CMD_LIGHT); } -function wc_onclickservclck() +function wc_onclickrevm12() { - send_command(CMD_SRVCLCK); + send_command(CMD_REVM12); } -function wc_onclickservaclck() +function wc_onclickrevm34() { - send_command(CMD_SRVACLCK); + send_command(CMD_REVM34); } function wc_onclickspd1() { @@ -258,11 +258,11 @@ window.onload = init; - +
POLARITY - - + +

diff --git a/src/blite.cpp b/src/blite.cpp index 3b1778f..8a742eb 100644 --- a/src/blite.cpp +++ b/src/blite.cpp @@ -19,10 +19,22 @@ int Blite::getIO(const char * io){ } void Blite::reversePolarityM12(){ - this->defineM12(false); + if (this->m2 == M2){ + this->m2 = M1; + this->m1 = M2; + } else { + this->m1 = M1; + this->m2 = M2; + } } void Blite::reversePolarityM34(){ - this->defineM34(false); + if (this->m3 == M3){ + this->m4 = M3; + this->m3 = M4; + } else { + this->m3 = M3; + this->m4 = M4; + } } void Blite::turnM12(bool direction){ @@ -139,9 +151,12 @@ void Blite::setup(){ pinMode(M2,OUTPUT); pinMode(M3,OUTPUT); pinMode(M4,OUTPUT); + pinMode(IO1,OUTPUT); this->stopMotor(); - this->defineM12(true); - this->defineM34(true); + this->m1 = M1; + this->m2 = M2; + this->m3 = M3; + this->m4 = M4; this->speed = 255; this->display.init(); this->display.flipScreenVertically(); @@ -166,6 +181,11 @@ void Blite::blinkLed(int c){ delay(500); } } + +void Blite::lights(){ + digitalWrite(IO1, !digitalRead(IO1)); +} + int Blite::readADC(){ return analogRead(ADC1); } diff --git a/src/blite.h b/src/blite.h index e64078d..121836f 100644 --- a/src/blite.h +++ b/src/blite.h @@ -49,6 +49,7 @@ void stopM34(); int getIO(const char * io); bool buttonPressed(); void blinkLed(int c); +void lights(); int readADC(); void setupServer(String &html_content); @@ -66,24 +67,6 @@ ESP8266WebServer webServer = ESP8266WebServer(80); SSD1306Wire display = SSD1306Wire(0x3c, I2C_SDA, I2C_SCL); bool serverSetupDone = false; -void defineM12(bool polarity){ - if (this->m2 == M2){ - this->m2 = M1; - this->m1 = M2; - } else { - this->m1 = M1; - this->m2 = M2; - } -}; -void defineM34(bool polarity){ - if (this->m3 == M3){ - this->m4 = M3; - this->m3 = M4; - } else { - this->m3 = M3; - this->m4 = M4; - } -}; }; #endif #endif \ No newline at end of file