Skip to content

Instantly share code, notes, and snippets.

@bwhite
Last active August 29, 2015 14:00
Show Gist options
  • Save bwhite/11488328 to your computer and use it in GitHub Desktop.
Save bwhite/11488328 to your computer and use it in GitHub Desktop.
[wearscript] Beacon Powertail
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); // RX, TX
unsigned long timeOff = 0;
void setup()
{
Serial.begin(57600);
while (!Serial) {
}
mySerial.begin(9600);
pinMode(4, OUTPUT);
}
void loop()
{
if (timeOff < millis() && digitalRead(4) == 1) {
digitalWrite(4, 0);
}
if (mySerial.available()) {
char c = mySerial.read();
if (c == '2')
if (digitalRead(4) == 0)
c = '1';
else
c = '0';
if (c == '0') {
timeOff = 0;
digitalWrite(4, 0);
} else if (c == '1') {
timeOff = 4294967295;
digitalWrite(4, 1);
} else if (c == '3') {
timeOff = millis() + 5000;
digitalWrite(4, 1);
}
if (Serial.available()) {
delay(10); // HACK
mySerial.write(Serial.read());
}
}
}
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function main() {
if (WS.scriptVersion(1)) return;
var addr = '00:00:12:06:57:19';
WS.beaconOn();
WS.subscribe('ibeacon', function (channel, uuid, rssid, major, minor, proximity) {
if (proximity != 3) {
WS.beaconOff();
WS.bluetoothPair(addr, function () {
WS.bluetoothWrite(addr, '3');
WS.beaconOn();
});
}
//WS.log(channel + ' ' + uuid + ' ' + rssid + ' ' + major + ' ' + minor + ' ' + proximity);
//WS.say(proximity)
});
WS.gestureCallback('onGestureSWIPE_LEFT', function () {
WS.bluetoothWrite(addr, '0');
});
WS.gestureCallback('onGestureSWIPE_RIGHT', function () {
WS.bluetoothWrite(addr, '3');
});
}
window.onload = main;
</script>
</body>
</html>
{"name":"Beacon Powertail"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment