Commit 7eb84eef authored by a-j.towse's avatar a-j.towse

Add new file

parent c90bdaba
#include <ArduinoBLE.h>
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE led service
// BLE LED Switch Characteristic Uuid
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
const int ledPin = LED_BUILTIN; // pin to use for the LED
void setup() {
Serial.begin(9600);
while (!Serial);
// set LED pin to output mode
pinMode(ledPin, OUTPUT);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("LED");
BLE.setAdvertisedService(ledService);
// add the characteristic to the service
ledService.addCharacteristic(switchCharacteristic);
// add service
BLE.addService(ledService);
// set the initial value for the characeristic:
switchCharacteristic.writeValue(0);
// start advertising
BLE.advertise();
}
void loop() {
//listen for ble connections
BLEDevice central = BLE.central();
// if a central is connected to peripheral:
if (central) {
Serial.print("Connected to central: ");
// while the central is still connected to peripheral:
while (central.connected()) {
if (switchCharacteristic.written()) {
if (switchCharacteristic.value() > 5) { //target temp 5 degrees C
Serial.println("Not target temp");
digitalWrite(8,LOW);
digitalWrite(2, HIGH);
} else {
Serial.println(F("target temp achieved"));
digitalWrite(2,LOW);
digitalWrite(8,HIGH);
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment