Update arduino code
This commit is contained in:
parent
925200252d
commit
fc5893f714
2 changed files with 45 additions and 5 deletions
|
@ -44,6 +44,10 @@ void loop() {
|
||||||
}
|
}
|
||||||
Serial.write(Bluetooth.read());
|
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
|
// Read from Arduino Serial Monitor and send it to the HC-05
|
||||||
if (Serial.available()) {
|
if (Serial.available()) {
|
||||||
|
@ -85,8 +89,7 @@ unsigned long build_packet(void) {
|
||||||
return built_packet;
|
return built_packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintBits32(unsigned long u)
|
void PrintBits32(unsigned long u) {
|
||||||
{
|
|
||||||
char str[34];
|
char str[34];
|
||||||
str[32] = '\n';
|
str[32] = '\n';
|
||||||
str[33] = 0;
|
str[33] = 0;
|
||||||
|
|
|
@ -1,9 +1,46 @@
|
||||||
void setup() {
|
#include <SoftwareSerial.h>
|
||||||
// put your setup code here, to run once:
|
|
||||||
|
|
||||||
|
// 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() {
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue