Skip to content

Commit

Permalink
added light, polarity change buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
DebaDr0na committed May 23, 2024
1 parent 8294747 commit df671a1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 19 deletions.
31 changes: 30 additions & 1 deletion 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,13 +8,18 @@
#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_SPD_1 10
#define CMD_SPD_2 11
#define CMD_SPD_3 12

Blite myBot;
WebSocketsServer webSocket = WebSocketsServer(81);

void setup(){
myBot.setup();
myBot.reversePolarityM12();
Serial.begin(115200);
delay(1000);
if (myBot.buttonPressed()){
Expand Down Expand Up @@ -71,6 +76,30 @@ 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);
break;
case CMD_SRVCLCK:
Serial.println("Turn servo clockwise");
myBot.reversePolarityM12();
break;
case CMD_SRVACLCK:
Serial.println("Turn servo anti-clockwise");
myBot.reversePolarityM34();
break;
case CMD_SPD_1:
Serial.println("Speed set to 100");
myBot.setSpeed(80);
break;
case CMD_SPD_2:
Serial.println("Speed set to 175");
myBot.setSpeed(160);
break;
case CMD_SPD_3:
Serial.println("Speed set to 255");
myBot.setSpeed(255);
break;
default:
Serial.println("Unknown command");
}
Expand Down
40 changes: 31 additions & 9 deletions examples/05_IoT_beebot_rc_car/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const char *REMOTE_HTML_CONTENT = R"=====(
<html>
<head>
<title>ESP8266 Control Car via Web</title>
<p>
Connection : <span id="ws_state" style="color:blue">closed</span>
<button id="wc_conn" type="button" onclick="wc_onclick();">Connect</button><br>
</p>
<meta name="viewport" content="width=device-width, initial-scale=0.7, maximum-scale=1, user-scalable=no">
<style type="text/css">
body { text-align: center; font-size: 24px;}
Expand Down Expand Up @@ -122,6 +126,9 @@ var CMD_RIGHT = 8;
var CMD_PUSH = 5;
var CMD_SRVCLCK = 6;
var CMD_SRVACLCK = 9;
var CMD_SPD_1 = 10;
var CMD_SPD_2 = 11;
var CMD_SPD_3 = 12;
var img_name_lookup = {
[CMD_STOP]: "stop",
[CMD_FORWARD]: "up",
Expand Down Expand Up @@ -213,6 +220,18 @@ function wc_onclickservaclck()
{
send_command(CMD_SRVACLCK);
}
function wc_onclickspd1()
{
send_command(CMD_SPD_1);
}
function wc_onclickspd2()
{
send_command(CMD_SPD_2);
}
function wc_onclickspd3()
{
send_command(CMD_SPD_3);
}

function send_command(cmd)
{
Expand All @@ -233,17 +252,20 @@ window.onload = init;
<div id="8" class="arrow right"></div>
<div id="4" class="arrow left"></div>
</div>
<p>
WebSocket : <span id="ws_state" style="color:blue">closed</span>
<button id="wc_conn" type="button" onclick="wc_onclick();">Connect</button><br>
</p>
<button id="wc_push" type="button" onclick="wc_onclickpush();">Push</button>
<h style="font-size:17px; color:blue">SERVO</h>
<button id="wc_servclck" type="button" onclick="wc_onclickservclck();">Clockwise</button>
<button id="wc_servaclck" type="button" onclick="wc_onclickservaclck();">AntiClockwise</button>
<div id="5" class="speedControl">
<h style="font-size:17px; color:blue">SPEED</h>
<button id="speed1" type="button" onclick="wc_onclickspd1();">SLOW</button>
<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>
<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>
<br>
<br>
<div class="sponsor">Sponsored by <a href="https://paulsayan.wixsite.com/buildybee">Buidybee</a></div>
<div class="sponsor">Sponsored by <a href="https://buildybee.github.io/">Buidybee</a></div>
</body>
</html>
)=====";
2 changes: 1 addition & 1 deletion src/blite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void Blite::setup(){
this->stopMotor();
this->defineM12(true);
this->defineM34(true);
this->speed = 100;
this->speed = 255;
this->display.init();
this->display.flipScreenVertically();
this->display.clear();
Expand Down
16 changes: 8 additions & 8 deletions src/blite.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ SSD1306Wire display = SSD1306Wire(0x3c, I2C_SDA, I2C_SCL);
bool serverSetupDone = false;

void defineM12(bool polarity){
if (polarity){
this->m1 = M1;
this->m2 = M2;
} else {
if (this->m2 == M2){
this->m2 = M1;
this->m1 = M2;
} else {
this->m1 = M1;
this->m2 = M2;
}
};
void defineM34(bool polarity){
if (polarity){
this->m3 = M3;
this->m4 = M4;
} else {
if (this->m3 == M3){
this->m4 = M3;
this->m3 = M4;
} else {
this->m3 = M3;
this->m4 = M4;
}
};
};
Expand Down

0 comments on commit df671a1

Please sign in to comment.