codetemplates/esp32_coderacer/lib/CodeRacer/examples/SimpleBTCoderacer/SimpleBTCoderacer.ino

57 lines
1.9 KiB
C++

// Full API description of the coderacer.h can be found here: https://fenoglio.pages.itsblue.de/coderacer/
// Repository with all needed data and users guide is here: https://git.itsblue.de/Fenoglio/coderacer/tree/master
// An example for a application to control the coderacer via bluetooth can be found here: https://git.itsblue.de/Fenoglio/coderacer/tree/master/AppInventor/SimpleBTCoderacer
// - this app was developed with MIT App Inventor and can be uploaded to your account to rework it.
#include <CodeRacer.h>
CodeRacer coderacer;
String recvddata = ""; //Variable in der der Bluetooth Befehl gespeichert wird
void setup() {
Serial.begin(115200);
coderacer.begin();
coderacer.bt_start("CodeRacer"); //Bluetooth für den Coderacer anschalten
coderacer.bt_enable_stopOnLostConnection(); //Coderacer anhalten, wenn 1 Sekunde nichts per Bluetooth empfangen wurde
coderacer.bt_addStringToIgnoreList("."); //das "." Zeichen wird beim empfangen ignoriert
}
void loop() {
// Prüfen ob Bluetooth Nachrichten angekommen sind und die gleich abholen ...
recvddata = coderacer.bt_getString(); //die Nachtricht merken (sie steht jetzt in recvdata und kann später benutzt werden)
if (recvddata != "") //wenn eine Nachricht empfangen wurde, in der was drin steht ...
{
Serial.println(recvddata);
if(recvddata == "stop")
{
coderacer.stop_driving();
}
if(recvddata == "vor")
{
coderacer.drive_forward(255,255);
}
if(recvddata.startsWith("rueck"))
{
coderacer.drive_backward(255,255);
}
if(recvddata.startsWith("links"))
{
coderacer.turn_left();
}
if(recvddata.startsWith("rechts"))
{
coderacer.turn_right();
}
}
delay(20);
}