Skip to content

Instantly share code, notes, and snippets.

@bwhite
Created April 19, 2014 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwhite/11074650 to your computer and use it in GitHub Desktop.
Save bwhite/11074650 to your computer and use it in GitHub Desktop.
[wearscript] AR Tag + Power Tail
#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());
}
}
<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;
DB = {};
WS.cameraOnBackgroundUnsafe(1, 360, 640);
var model_ar = btoa(msgpack.pack([{'kw': {}, 'name': 'picarus.ARMarkerDetector'}]).map(function (x) {return String.fromCharCode(x)}).join(''));
LAST_ID = undefined;
ADDR = '00:14:01:17:16:63';
WS.gestureCallback('onEyeGesture', function () {
WS.say('blink')
WS.bluetoothWrite(ADDR, '2');
});
model = new WS.PicarusModel(model_ar, function () {
model.processStream(function (tags) {
tags = msgpack.unpack(tags);
WS.log(JSON.stringify(tags));
WS.log(JSON.stringify(DB));
if (tags && tags[0].length) {
var id = String(tags[0][0]);
if (!DB[id]) {
DB[id] = {setup: false};
WS.wake();
WS.speechRecognize('Name the tag', function (data) {
WS.cameraPhoto(function (path) {
DB[id].setup = true;
DB[id].label = data;
DB[id].photo = path;
});
});
} else if (DB[id].setup) {
WS.wake();
WS.activityCreate();
LAST_ID = id;
WS.say(DB[id].label);
document.getElementById('image').setAttribute('src', 'file://' + DB[id].photo);
}
}
});
})
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment