diff --git a/AppInventor/BluetoothTest.aia b/AppInventor/BluetoothTest.aia deleted file mode 100644 index 008ff2b..0000000 Binary files a/AppInventor/BluetoothTest.aia and /dev/null differ diff --git a/AppInventor/ESP32_BLE.aia b/AppInventor/ESP32_BLE.aia deleted file mode 100644 index 6f63f6c..0000000 Binary files a/AppInventor/ESP32_BLE.aia and /dev/null differ diff --git a/AppInventor/SimpleBTCoderacer/coderaceBT.aia b/AppInventor/SimpleBTCoderacer/coderaceBT.aia new file mode 100644 index 0000000..4d148fd Binary files /dev/null and b/AppInventor/SimpleBTCoderacer/coderaceBT.aia differ diff --git a/AppInventor/SimpleBTCoderacer/coderaceBT.apk b/AppInventor/SimpleBTCoderacer/coderaceBT.apk new file mode 100644 index 0000000..e406610 Binary files /dev/null and b/AppInventor/SimpleBTCoderacer/coderaceBT.apk differ diff --git a/Arduino/BTCoderacer/BTCoderacer.ino b/Arduino/BTCoderacer/BTCoderacer.ino index bcab148..5545595 100644 --- a/Arduino/BTCoderacer/BTCoderacer.ino +++ b/Arduino/BTCoderacer/BTCoderacer.ino @@ -5,6 +5,7 @@ //and also demonstrate that SerialBT have the same functionalities of a normal Serial #include "BluetoothSerial.h" +#include #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it @@ -13,13 +14,32 @@ BluetoothSerial SerialBT; bool motioncontrol = false; +String recvddata = ""; +int init_azimuth = 1000; +int azimuth = 0; + +int minroll = 20; +int roll = 20; +int maxroll = 90; +int minpitch = 10; +int pitch = 0; +int maxpitch = 90; + +int defaultleft = 200; +int left = 0; +int defaultright = 200; +int right = 0; + +CodeRacer coderacer; + void setup() { Serial.begin(115200); SerialBT.begin("ESP32test"); //Bluetooth device name Serial.println("The device started, now you can pair it with bluetooth!"); + coderacer.begin(); } -String recvddata = ""; + void loop() { if (Serial.available()) { @@ -43,6 +63,7 @@ void BTcontrol() if(recvddata.startsWith("motion_on")) { SerialBT.print("motion_ready"); + init_azimuth = 1000; motioncontrol = true; return; } @@ -51,6 +72,7 @@ void BTcontrol() { SerialBT.print("motion_disabled"); motioncontrol = false; + coderacer.stop_driving(); return; } @@ -71,6 +93,64 @@ void BTcontrol() String BTmotioncontrol(String recvddata) { + // split the string ... + String apr_substr=recvddata.substring(recvddata.indexOf("=")+1); + String a = apr_substr.substring(0,apr_substr.indexOf(";")); + String p = apr_substr.substring(apr_substr.indexOf(";")+1,apr_substr.lastIndexOf(";")); + String r = apr_substr.substring(apr_substr.lastIndexOf(";")+1); + + azimuth = a.toInt(); + pitch = p.toInt(); + roll = r.toInt(); + + if(init_azimuth == 1000) + { + init_azimuth = azimuth; + } + + azimuth = azimuth - init_azimuth; + if(abs(pitch) 0) + { + left = defaultleft+pitch; + if(left > 256) left = 256; + right = defaultright+pitch; + if(right > 256) right = 256; + coderacer.drive_forward(left,right); + } + else + { + left = defaultleft-pitch; + if(left > 256) left = 256; + right = defaultright-pitch; + if(right > 256) right = 256; + coderacer.drive_backward(left,right); + } + } + + + if(abs(roll) + +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); +} + +