Arduino 101
#include <CurieBLE.h>#include <stdlib.h>
#define LEDr 6
#define LEDg 5
#define LEDb 3
BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming)
BLEService ControlLED("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE AnalogRead Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedIntCharacteristic LEDStatus("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite );
int incom = 0;
int r, g, b ;
void setup() {
Serial.begin(9600);
// set Light pin to output mode
// set advertised local name and service UUID:
blePeripheral.setLocalName("ControlLED");
blePeripheral.setAdvertisedServiceUuid(ControlLED.uuid());
// add service and characteristic:
blePeripheral.addAttribute(ControlLED);
blePeripheral.addAttribute(LEDStatus);
// begin advertising BLE Light service:
blePeripheral.begin();
Serial.println("BLE AnalogRead service.");
pinMode(LEDr, OUTPUT);
pinMode(LEDg, OUTPUT);
pinMode(LEDb, OUTPUT);
}
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()) {
//Serial.println(LEDStatus.written());
if (LEDStatus.written())
{
incom = LEDStatus.value();//110225101/255
r = incom / 1000000 ;//110
g = (incom / 1000 - r * 1000) ; //110225-110000=225
b = (incom - r * 1000000 - g * 1000) ; //110225101-110000000-2250000=101
Serial.println(incom);
Serial.println(r);
Serial.println(g);
Serial.println(b);
analogWrite(LEDr, r);
analogWrite(LEDg, g);
analogWrite(LEDb, b);
delay(10);
}
}
pinMode(LEDr, LOW);
pinMode(LEDg, LOW);
pinMode(LEDb, LOW);
delay(100);
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
|
BLE_Arduino101_RGBblink.ino
getPixelColor_BLE.aia
QUANTUM BINARY SIGNALS
답글삭제Get professional trading signals sent to your mobile phone daily.
Follow our signals today and gain up to 270% daily.