Update arduino code

This commit is contained in:
Carson 2022-04-03 21:24:15 -06:00
parent 925200252d
commit fc5893f714
2 changed files with 45 additions and 5 deletions

View file

@ -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;

View file

@ -1,9 +1,46 @@
void setup() {
// put your setup code here, to run once:
#include <SoftwareSerial.h>
// 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);
}