http://dev.classmethod.jp/hardware/ble-genuino-101/
ExamplesのBLEを使う
#include <CurieBLE.h> BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming) BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEUnsignedCharCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); const int ledPin = 13; // pin to use for the LED void setup() { Serial.begin(9600); // set LED pin to output mode pinMode(ledPin, OUTPUT); // set advertised local name and service UUID: blePeripheral.setLocalName("LED"); blePeripheral.setAdvertisedServiceUuid(ledService.uuid()); // add service and characteristic: blePeripheral.addAttribute(ledService); blePeripheral.addAttribute(switchCharacteristic); // set the initial value for the characeristic: switchCharacteristic.setValue(0); // begin advertising BLE service: blePeripheral.begin(); Serial.println("BLE LED Peripheral"); } void loop() { // listen for BLE peripherals to connect: BLECentral central = blePeripheral.central(); // if a central is connected to peripheral: if (central) { Serial.print("Connected to central: "); // print the central's MAC address: Serial.println(central.address()); // while the central is still connected to peripheral: while (central.connected()) { // if the remote device wrote to the characteristic, // use the value to control the LED: if (switchCharacteristic.written()) { if (switchCharacteristic.value()) { // any value other than 0 Serial.println("LED on"); digitalWrite(ledPin, HIGH); // will turn the LED on } else { // a 0 value Serial.println(F("LED off")); digitalWrite(ledPin, LOW); // will turn the LED off } } } // when the central disconnects, print it out: Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } }
BLEのAndroidアプリ
nRF Connect
https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp
Byteで0x00、0x01(あるいはuint8で0, 1)を送るとLEDをON/OFFできる