Created
April 20, 2014 01:22
-
-
Save bwhite/11102443 to your computer and use it in GitHub Desktop.
[wearscript] Home automation
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
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(3, 2); // RX, TX | |
void setup() | |
{ | |
Serial.begin(57600); | |
while (!Serial) { | |
} | |
mySerial.begin(9600); | |
pinMode(4, OUTPUT); | |
} | |
void loop() | |
{ | |
if (mySerial.available()) { | |
char c = mySerial.read(); | |
if (c == '0') | |
digitalWrite(4, 0); | |
else if (c == '1') | |
digitalWrite(4, 1); | |
else | |
digitalWrite(4, !digitalRead(4)); | |
Serial.write(c); | |
} | |
if (Serial.available()) { | |
delay(10); // HACK | |
mySerial.write(Serial.read()); | |
} | |
} |
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
<html style="width:100%; height:100%; overflow:hidden"> | |
<body style="width:100%; height:100%; overflow:hidden; margin:0" bgcolor="#000"> | |
<img width="640" height="360" id="image" /> | |
<script> | |
function main() { | |
if (WS.scriptVersion(1)) return; | |
ADDR = '00:14:01:17:16:63'; | |
WS.bluetoothList(function (x) { | |
WS.log(JSON.stringify(x)); | |
setTimeout(function () {WS.bluetoothWrite(ADDR, '0')}, 2000); | |
}); | |
DB = {}; | |
DB[0] = function () { | |
WS.publish('urlopen', 'https://www.youtube.com/v/kdemFfbS5H0&autoplay=1&start=35'); | |
setTimeout(function () { | |
WS.cameraPhoto(); | |
}, 5500); | |
delete DB[0]; | |
} | |
function juice() { | |
WS.speechRecognize("I'm a Juicer!", function (msg) { | |
if (msg == "you're done") | |
WS.bluetoothWrite(ADDR, '0'); | |
else if (msg == 'juice it up') { | |
WS.bluetoothWrite(ADDR, '1'); | |
DB[1] = juice; | |
} | |
}); | |
delete DB[1]; | |
} | |
DB[1] = juice; | |
DB[2] = function () { | |
WS.createMedia('/sdcard/carrot.m4v', false) | |
setTimeout(WS.activityCreate, 5000); | |
delete DB[2]; | |
} | |
WS.cameraOnBackgroundUnsafe(1, 360, 640); | |
var model_ar = btoa(msgpack.pack([{'kw': {}, 'name': 'picarus.ARMarkerDetector'}]).map(function (x) {return String.fromCharCode(x)}).join('')); | |
model = new WS.PicarusModel(model_ar, function () { | |
model.processStream(function (tags) { | |
tags = msgpack.unpack(tags); | |
WS.log(JSON.stringify(tags)); | |
if (tags && tags[0].length) { | |
var id = String(tags[0][0]); | |
if (DB[id]) { | |
WS.wake(); | |
//WS.activityCreate(); | |
WS.say(String(id)); | |
DB[id](); | |
} | |
} | |
}); | |
}) | |
} | |
window.onload = main; | |
</script></body></html> |
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
{"name":""} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment