Skip to content

Commit

Permalink
Add Arduino BLE Set / Get LED Code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcherHuang committed Jul 7, 2017
1 parent d11fb3d commit 2d7a339
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified AppInventor/.DS_Store
Binary file not shown.
84 changes: 84 additions & 0 deletions Arduino/BLE_LED_Set_Get/BLE_LED_Set_Get.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
This example configures LinkIt 7697 to act as a simple GATT server with 1 characteristic.
To use it, open AppInventor project:
*
Build & install it on Android id
created Mar 2017
*/
#include <LBLE.h>
#include <LBLEPeriphral.h>

// Define a simple GATT service with only 1 characteristic
LBLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214");
LBLECharacteristicInt switchCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", LBLE_READ | LBLE_WRITE);

void setup() {

// Initialize LED pin
pinMode(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();
Serial.println(value);
switch (value) {
case 1:
digitalWrite(LED_BUILTIN, HIGH);
break;
case 0:
digitalWrite(LED_BUILTIN, LOW);
break;
default:
Serial.println("Unknown value written");
break;
}
switchCharacteristic.setValue(digitalRead(LED_BUILTIN));
}

}

0 comments on commit 2d7a339

Please sign in to comment.