Last active
July 18, 2017 21:35
-
-
Save lucabelluccini/eb1b274d26cbc3a37fbd371619ec4040 to your computer and use it in GitHub Desktop.
Arduino 101 sketch to send a power signal to the UDOO x86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2016 Intel Corporation. All rights reserved. | |
* See the bottom of this file for the license terms. | |
*/ | |
#include <CurieBLE.h> | |
const int ledPin = 13; // set ledPin to use on-board LED | |
const int resetPin = 9; | |
const int pulseTime = 8; | |
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service | |
// create switch characteristic and allow remote device to read and write | |
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); | |
void setup() { | |
Serial.begin(9600); | |
pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output | |
pinMode(resetPin, OUTPUT); | |
digitalWrite(resetPin, HIGH); | |
// begin initialization | |
BLE.begin(); | |
// set the local name peripheral advertises | |
BLE.setLocalName("LEDCB"); | |
// set the UUID for the service this peripheral advertises | |
BLE.setAdvertisedService(ledService); | |
// assign event handlers for characteristic | |
switchChar.setEventHandler(BLEWritten, switchCharacteristicWritten); | |
// set an initial value for the characteristic | |
switchChar.setValue(0); | |
// add the characteristic to the service | |
ledService.addCharacteristic(switchChar); | |
// add service | |
BLE.addService(ledService); | |
// assign event handlers for connected, disconnected to peripheral | |
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); | |
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); | |
// start advertising | |
BLE.advertise(); | |
Serial.println(("Bluetooth device active, waiting for connections...")); | |
} | |
void loop() { | |
// poll for BLE events | |
BLE.poll(); | |
} | |
void blePeripheralConnectHandler(BLEDevice central) { | |
// central connected event handler | |
Serial.print("Connected event, central: "); | |
Serial.println(central.address()); | |
} | |
void blePeripheralDisconnectHandler(BLEDevice central) { | |
// central disconnected event handler | |
Serial.print("Disconnected event, central: "); | |
Serial.println(central.address()); | |
} | |
void sendPowerSignal() { | |
digitalWrite(resetPin, HIGH); | |
// UPDATE! Since BIOS 1.03 RC | |
// At least 5 transitions HIGH-LOW within a 100 ms | |
for(int i=0; i<5; i++) { | |
digitalWrite(resetPin, LOW); | |
delay(pulseTime); /* Reset pin goes LOW for 8ms */ | |
digitalWrite(resetPin, HIGH); | |
delay(pulseTime); /* Reset pin goes HIGH for 8ms */ | |
} | |
} | |
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { | |
// central wrote new value to characteristic, update LED | |
Serial.print("Characteristic event, written: "); | |
if (switchChar.value()) { | |
Serial.println("LED on"); | |
digitalWrite(ledPin, HIGH); | |
switchChar.setValue(0); | |
delay(1000); | |
sendPowerSignal(); | |
} else { | |
digitalWrite(ledPin, LOW); | |
Serial.println("LED off"); | |
} | |
} | |
/* | |
Copyright (c) 2016 Intel Corporation. All rights reserved. | |
This library is free software; you can redistribute it and/or | |
modify it under the terms of the GNU Lesser General Public | |
License as published by the Free Software Foundation; either | |
version 2.1 of the License, or (at your option) any later version. | |
This library is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
Lesser General Public License for more details. | |
You should have received a copy of the GNU Lesser General Public | |
License along with this library; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110- | |
1301 USA | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment