Skip to content

Commit

Permalink
updated blite.cpp and blite.h . Working. Fully testedgit status
Browse files Browse the repository at this point in the history
  • Loading branch information
DebaDr0na committed May 24, 2024
1 parent df671a1 commit 9e206ac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 44 deletions.
20 changes: 10 additions & 10 deletions examples/05_IoT_beebot_rc_car/05_IoT_beebot_rc_car.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions examples/05_IoT_beebot_rc_car/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -258,11 +258,11 @@ window.onload = init;
<button id="speed2" type="button" onclick="wc_onclickspd2();">MEDIUM</button>
<button id="speed3" type="button" onclick="wc_onclickspd3();">FAST</button>
</div>
<button id="wc_push" type="button" onclick="wc_onclickpush();">LIGHTS</button>
<button id="wc_push" type="button" onclick="wc_onclicklights();">LIGHTS</button>
<br>
<h style="font-size:17px; color:blue">POLARITY</h>
<button id="wc_servclck" type="button" onclick="wc_onclickservclck();">ReverseM1</button>
<button id="wc_servaclck" type="button" onclick="wc_onclickservaclck();">ReverseM2</button>
<button id="wc_revm12" type="button" onclick="wc_onclickrevm12();">ReverseM1</button>
<button id="wc_revm34" type="button" onclick="wc_onclickrevm34();">ReverseM2</button>
<br>
<br>
<div class="sponsor">Sponsored by <a href="https://buildybee.github.io/">Buidybee</a></div>
Expand Down
28 changes: 24 additions & 4 deletions src/blite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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();
Expand All @@ -166,6 +181,11 @@ void Blite::blinkLed(int c){
delay(500);
}
}

void Blite::lights(){
digitalWrite(IO1, !digitalRead(IO1));
}

int Blite::readADC(){
return analogRead(ADC1);
}
Expand Down
19 changes: 1 addition & 18 deletions src/blite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

0 comments on commit 9e206ac

Please sign in to comment.