]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/SPP/SPP.ino
lufa: usb-usb: Use LUFA startup instead of cusotom
[max/tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / examples / Bluetooth / SPP / SPP.ino
1 /*
2  Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus
3  For more information visit my blog: http://blog.tkjelectronics.dk/ or
4  send me an e-mail:  kristianl@tkjelectronics.com
5  */
6
7 #include <SPP.h>
8 #include <usbhub.h>
9
10 // Satisfy the IDE, which needs to see the include statment in the ino too.
11 #ifdef dobogusinclude
12 #include <spi4teensy3.h>
13 #include <SPI.h>
14 #endif
15
16 USB Usb;
17 //USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19 BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20 /* You can create the instance of the class in two ways */
21 SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
22 //SPP SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so
23
24 bool firstMessage = true;
25
26 void setup() {
27   Serial.begin(115200);
28 #if !defined(__MIPSEL__)
29   while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
30 #endif
31   if (Usb.Init() == -1) {
32     Serial.print(F("\r\nOSC did not start"));
33     while (1); //halt
34   }
35   Serial.print(F("\r\nSPP Bluetooth Library Started"));
36 }
37 void loop() {
38   Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
39
40   if (SerialBT.connected) {
41     if (firstMessage) {
42       firstMessage = false;
43       SerialBT.println(F("Hello from Arduino")); // Send welcome message
44     }
45     if (Serial.available())
46       SerialBT.write(Serial.read());
47     if (SerialBT.available())
48       Serial.write(SerialBT.read());
49   }
50   else
51     firstMessage = true;
52 }