|
1 | 1 | Arduino
|
2 | 2 | =======
|
| 3 | + |
| 4 | +Using an Arduino with WearScript you can integrate all varieties of sensors, input devices, LEDs, etc. In the wearscript-arduino repo we have an example manager.py that connects to the Arduino over a serial connection. There are folders of examples (described below) that contain both a wearscript and an arduino file (you flash the arduino yourself). |
| 5 | + |
| 6 | +To start the manager in client mode (i.e., it connects to the Go server, see PubSub for details) use the following. |
| 7 | + |
| 8 | +.. code-block:: guess |
| 9 | +
|
| 10 | + python manager.py --serialport /dev/ttyACM0 client <client endpoint here> |
| 11 | +
|
| 12 | +
|
| 13 | +To start the manager in server mode (e.g., Glass connect directly to this script, bypassing the Go server) use the following. See PubSub for details on how to get Glass to connect locally and caveats of doing so. |
| 14 | + |
| 15 | +.. code-block:: guess |
| 16 | +
|
| 17 | + python manager.py --serialport /dev/ttyACM0 server <server port here> |
| 18 | +
|
| 19 | +Basic |
| 20 | +----- |
| 21 | + |
| 22 | +Connected to an Arduino (tested with Uno and Due), the following uses the scroll gesture to control a servo on Pin 9 and an LED on pin 13 (both specified in the .ino file). We access them by sending data of the form ["arduinobasic", device, value] where devices index contiguously into servo pins then LEDs (i.e., binary pin, need not control an LED) specified in the .ino file. For Servos the value is written directly to the servo and for LEDs any non-zero value is "on" and zero is "off". |
| 23 | + |
| 24 | +.. code-block:: guess |
| 25 | +
|
| 26 | + <html style="width:100%; height:100%; overflow:hidden"> |
| 27 | + <body style="width:100%; height:100%; overflow:hidden; margin:0" bgcolor="#000000"><script> |
| 28 | + function main() { |
| 29 | + if (WS.scriptVersion(1)) return; |
| 30 | + WS.serverConnect('{{WSUrl}}', function () { |
| 31 | + WS.gestureCallback('onScroll', function (v, v2, v3) { |
| 32 | + var v = Math.min(180, Math.max(0, v / 6)); |
| 33 | + WS.publish('arduinobasic', 0, Math.round(v)); |
| 34 | + }); |
| 35 | + WS.gestureCallback('onGesture', function (v) { |
| 36 | + if (v == 'TAP') |
| 37 | + WS.publish('arduinobasic', 3, 0); |
| 38 | + else if (v == 'TWO_TAP') |
| 39 | + WS.publish('arduinobasic', 3, 1); |
| 40 | + }); |
| 41 | + }); |
| 42 | + } |
| 43 | + window.onload = main; |
| 44 | + </script></body></html> |
| 45 | +
|
| 46 | +Neopixel |
| 47 | +--------- |
| 48 | + |
| 49 | + |
0 commit comments