RadioLib/examples/HC05/HC05_Basic/HC05_Basic.ino

44 wiersze
1.0 KiB
Arduino
Czysty Zwykły widok Historia

2018-07-03 10:01:37 +00:00
/*
2019-02-08 14:58:29 +00:00
RadioLib HC05 Example
2018-07-23 10:43:12 +00:00
This example sends data using HC05 Bluetooth module.
HC05 works exactly like a Serial line, data are sent to the paired device.
2019-06-02 13:02:12 +00:00
The default pairing code for HC05 is 1234 or 1111.
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
2018-07-23 10:43:12 +00:00
*/
2018-07-03 10:01:37 +00:00
// include the library
2019-02-08 14:58:29 +00:00
#include <RadioLib.h>
2018-07-03 10:01:37 +00:00
2019-06-02 13:02:12 +00:00
// HC05 has the following connections:
// TX pin: 9
// RX pin: 8
HC05 bluetooth = new Module(9, 8);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//HC05 bluetooth = RadioShield.ModuleA;
2018-07-03 10:01:37 +00:00
void setup() {
Serial.begin(9600);
2018-07-11 15:41:01 +00:00
// initialize HC05
// baudrate: 9600 baud
2018-07-03 10:01:37 +00:00
bluetooth.begin(9600);
}
void loop() {
// HC05 supports all methods of the Serial class
2018-07-16 17:13:24 +00:00
// read data incoming from Serial port and write them to Bluetooth
2018-07-23 10:43:12 +00:00
while (Serial.available() > 0) {
2018-07-03 10:01:37 +00:00
bluetooth.write(Serial.read());
}
2018-07-23 10:43:12 +00:00
2018-07-16 17:13:24 +00:00
// read data incoming from Bluetooth and write them to Serial port
2018-07-23 10:43:12 +00:00
while (bluetooth.available() > 0) {
2018-07-16 17:13:24 +00:00
Serial.write(bluetooth.read());
}
2018-07-03 10:01:37 +00:00
}