Add Compass example and dont strip spaces on messages

This commit is contained in:
Nick O'Leary 2016-03-04 23:15:59 +00:00
parent 9301ab6c97
commit 53c9c834b9
2 changed files with 2 additions and 1 deletions

View File

@ -0,0 +1 @@
[{"id":"8a52215e.75ade","type":"rpi-sensehat out","z":"ec37e354.13c82","name":"","x":460,"y":39,"wires":[]},{"id":"f0e76645.0f1898","type":"rpi-sensehat in","z":"ec37e354.13c82","name":"","motion":true,"env":false,"stick":false,"x":90,"y":39,"wires":[["a96a3875.5695c8"]]},{"id":"a96a3875.5695c8","type":"function","z":"ec37e354.13c82","name":"Compass","func":"// A port of the Compass example provided by\n// the Sense HAT python library\n// https://github.com/RPi-Distro/python-sense-hat/tree/master/examples\n\nvar led_loop = [4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8, 0, 1, 2, 3];\nvar led_degree_ratio = led_loop.length / 360.0;\nvar dir_inverted = 360 - msg.payload.compass;\nled_index = Math.floor(led_degree_ratio * dir_inverted);\noffset = led_loop[led_index]\nvar y = Math.floor(offset / 8);\nvar x = offset % 8;\nvar prev_x = context.get('prev_x');\nvar prev_y = context.get('prev_y');\n\nmsg.payload = '';\nif (x != prev_x || y != prev_y) {\n msg.payload = prev_x+\",\"+prev_y+\",off,\"\n}\nmsg.payload += x+\",\"+y+\",blue\";\n\ncontext.set('prev_x',x);\ncontext.set('prev_y',y);\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":270,"y":39,"wires":[["8a52215e.75ade"]]}]

View File

@ -157,7 +157,7 @@ def process_command(data):
for p in range(0,len(s),5):
SH.set_pixel(int(s[p]),int(s[p+1]),int(s[p+2]),int(s[p+3]),int(s[p+4]))
elif data[0] == "T":
data = data[1:].strip()
data = data[1:]
tcol = (255,255,255)
bcol = (0,0,0)
speed = 0.1