使用 BLE 與 LinkIt 7697 開發板互動



LinkIt 7697 code,可於 Arduino IDE 編譯燒錄

 #include <LBLE.h>#include <LBLEPeriphral.h>// Define a simple GATT service with only 1 characteristicLBLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214");LBLECharacteristicInt switchCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", LBLE_READ | LBLE_WRITE);void setup() {// Initialize LED pinpinMode(LED_BUILTIN, OUTPUT);digitalWrite(LED_BUILTIN, LOW);//Initialize serial and wait for port to open: Serial.begin(9600);// Initialize BLE subsystem LBLE.begin();while (!LBLE.ready()) {delay(100);} Serial.println("BLE ready"); Serial.print("Device Address = ["); Serial.print(LBLE.getDeviceAddress()); Serial.println("]");// configure our advertisement data.// In this case, we simply create an advertisement that represents an// connectable device with a device name LBLEAdvertisementData advertisement; advertisement.configAsConnectableDevice("BLE LED");// Configure our device's Generic Access Profile's device name// Ususally this is the same as the name in the advertisement data. LBLEPeripheral.setName("BLE LED");// Add characteristics into ledService ledService.addAttribute(switchCharacteristic);// Add service to GATT server (peripheral) LBLEPeripheral.addService(ledService);// start the GATT server - it is now // available to connect LBLEPeripheral.begin();// start advertisment LBLEPeripheral.advertise(advertisement);}void loop() {delay(100);if (switchCharacteristic.isWritten()) {const char value = switchCharacteristic.getValue();switch (value) {case 1:digitalWrite(LED_BUILTIN, HIGH);break;case 0:digitalWrite(LED_BUILTIN, LOW);break;default: Serial.println("Unknown value written");break;}}}

曾吉弘,
2017年4月14日 晚上10:41
v.1
曾吉弘,
2017年4月14日 晚上10:42
v.1