From fc5893f7149a3dd933d42073290e7da0d7383bca Mon Sep 17 00:00:00 2001 From: Carson Date: Sun, 3 Apr 2022 21:24:15 -0600 Subject: [PATCH] Update arduino code --- arduino_controller/arduino_controller.ino | 7 ++-- arduino_maze/arduino_maze.ino | 43 +++++++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/arduino_controller/arduino_controller.ino b/arduino_controller/arduino_controller.ino index 7ae2260..71f34a6 100644 --- a/arduino_controller/arduino_controller.ino +++ b/arduino_controller/arduino_controller.ino @@ -44,6 +44,10 @@ void loop() { } Serial.write(Bluetooth.read()); } + else { + //Serial.println("Bluetooth unavailable, waiting 2 secs"); + //delay(2000); + } // Read from Arduino Serial Monitor and send it to the HC-05 if (Serial.available()) { @@ -85,8 +89,7 @@ unsigned long build_packet(void) { return built_packet; } -void PrintBits32(unsigned long u) -{ +void PrintBits32(unsigned long u) { char str[34]; str[32] = '\n'; str[33] = 0; diff --git a/arduino_maze/arduino_maze.ino b/arduino_maze/arduino_maze.ino index 95c2b6e..ad9b0e8 100644 --- a/arduino_maze/arduino_maze.ino +++ b/arduino_maze/arduino_maze.ino @@ -1,9 +1,46 @@ -void setup() { - // put your setup code here, to run once: +#include +// TX/RX +SoftwareSerial Bluetooth(11, 10); + +void setup() { + Serial.begin(38400); + Serial.println("Serial Started"); + Bluetooth.begin(38400); + Serial.println("Send 's' to sniff packets, 'h' to halt packets:"); + delay(2000); + } +unsigned long pack = 0; + void loop() { - // put your main code here, to run repeatedly: + // Read from HC-05 and send data to the Arduino Serial Monitor + if (Bluetooth.available()) { + Serial.write(Bluetooth.read()); + } + // Read from Arduino Serial Monitor and send it to the HC-05 + if (Serial.available()) { + char com = Serial.read(); + Serial.write(com); + if (com == 's') { + Serial.println(); + PrintBits32(pack); + } + Bluetooth.write(com); + } +} + +void PrintBits32(unsigned long u) { + char str[34]; + str[32] = '\n'; + str[33] = 0; + for (int i = 31; i >= 0; i--) + { + str[i] = '0' + (u & 1); + u >>= 1; + } + + Serial.print(str); }