p17_Bluetooth.ino 696 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. Demo code for Project 17 - bluetooth
  3. by Maker Studio
  4. */
  5. #include "EB_Bluetooth.h"
  6. #include <SoftwareSerial.h>
  7. //EB_Bluetooth(RX, TX, INT)
  8. EB_Bluetooth myBluetooth(11,10,9);
  9. void setup()
  10. {
  11. Serial.begin(9600);
  12. myBluetooth.begin();
  13. if(myBluetooth.setName("MakerStudio")){
  14. Serial.println("Set Bluetooth Name Ok");
  15. }else{
  16. Serial.println("Set Bluetooth Name Failed");
  17. }
  18. Serial.println("Waiting to be connected");
  19. }
  20. void loop()
  21. {
  22. char dat;
  23. if(myBluetooth.connected()){
  24. if(myBluetooth.available()){
  25. dat = myBluetooth.read();
  26. Serial.print(dat);
  27. }
  28. if(Serial.available()){
  29. dat = Serial.read();
  30. myBluetooth.print(dat);
  31. }
  32. }
  33. }