diff --git a/examples/HC05/HC05.ino b/examples/HC05/HC05.ino index 26f817e7..d8e79fc5 100644 --- a/examples/HC05/HC05.ino +++ b/examples/HC05/HC05.ino @@ -21,9 +21,14 @@ void setup() { } void loop() { - // read data incoming from Serial port and write them to bluetooth // HC05 supports all methods of the Serial class + // read data incoming from Serial port and write them to Bluetooth while(Serial.available() > 0) { bluetooth.write(Serial.read()); } + + // read data incoming from Bluetooth and write them to Serial port + while(bluetooth.available() > 0) { + Serial.write(bluetooth.read()); + } } diff --git a/examples/JDY08/JDY08.ino b/examples/JDY08/JDY08.ino index abe642b8..80436182 100644 --- a/examples/JDY08/JDY08.ino +++ b/examples/JDY08/JDY08.ino @@ -19,12 +19,14 @@ void setup() { } void loop() { - // read data incoming from Serial port and write them to bluetooth // JDY08 supports all methods of the Serial class + // read data incoming from Serial port and write them to Bluetooth while(Serial.available() > 0) { - ble.write(Serial.read()); + bluetooth.write(Serial.read()); } - while(ble.available() > 0) { - Serial.write(ble.read()); + + // read data incoming from Bluetooth and write them to Serial port + while(bluetooth.available() > 0) { + Serial.write(bluetooth.read()); } } diff --git a/src/ISerial.cpp b/src/ISerial.cpp index 21c1e331..0ae9ca47 100644 --- a/src/ISerial.cpp +++ b/src/ISerial.cpp @@ -1,7 +1,7 @@ #include "ISerial.h" -ISerial::ISerial() { - +ISerial::ISerial(Module* mod) { + _mod = mod; } void ISerial::begin(long speed) { diff --git a/src/ISerial.h b/src/ISerial.h index 27520412..bc271078 100644 --- a/src/ISerial.h +++ b/src/ISerial.h @@ -10,7 +10,7 @@ class ISerial { public: - ISerial(); + ISerial(Module* mod); void begin(long); bool listen(); diff --git a/src/modules/HC05.cpp b/src/modules/HC05.cpp index ba73ed15..0dc409d3 100644 --- a/src/modules/HC05.cpp +++ b/src/modules/HC05.cpp @@ -1,7 +1,7 @@ #include "HC05.h" -HC05::HC05(Module* module) { - _mod = module; +HC05::HC05(Module* mod) : ISerial(mod) { + } void HC05::begin(long speed) { diff --git a/src/modules/HC05.h b/src/modules/HC05.h index 0459d934..d85b2263 100644 --- a/src/modules/HC05.h +++ b/src/modules/HC05.h @@ -6,7 +6,7 @@ class HC05: public ISerial { public: // constructor - HC05(Module* module); + HC05(Module* mod); // basic methods void begin(long speed); diff --git a/src/modules/JDY08.cpp b/src/modules/JDY08.cpp index 80f8c6d2..36a759dd 100644 --- a/src/modules/JDY08.cpp +++ b/src/modules/JDY08.cpp @@ -1,7 +1,7 @@ #include "JDY08.h" -JDY08::JDY08(Module* module) { - _mod = module; +JDY08::JDY08(Module* mod) : ISerial(mod) { + } void JDY08::begin(long speed) { diff --git a/src/modules/JDY08.h b/src/modules/JDY08.h index db72e191..eb1b62e1 100644 --- a/src/modules/JDY08.h +++ b/src/modules/JDY08.h @@ -6,7 +6,7 @@ class JDY08: public ISerial { public: // constructor - JDY08(Module* module); + JDY08(Module* mod); // basic methods void begin(long speed);