script that changes colour on led lights depending on the cords


In [68]:
import os
import json
import socket
import getpass
import time
import unicornhat as uh


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-68-ba0e3d9ed62a> in <module>()
      4 import getpass
      5 
----> 6 import unicornhat as uh

/usr/local/lib/python2.7/dist-packages/unicornhat.py in <module>()
     11 
     12 ws2812 = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
---> 13 ws2812.begin()
     14 
     15 def clean_shutdown():

/usr/local/lib/python2.7/dist-packages/neopixel.pyc in begin(self)
    105                 resp = ws.ws2811_init(self._leds)
    106                 if resp != 0:
--> 107                         raise RuntimeError('ws2811_init failed with code {0}'.format(resp))
    108 
    109         def show(self):

RuntimeError: ws2811_init failed with code -1

In [ ]:
#uh.brightness(1)

In [3]:
gethos = socket.gethostname()
#geusr = getpass.getuser()

In [4]:
#geusr


Out[4]:
'wcmckee'

In [5]:
gethos


Out[5]:
'zincwhite'

In [33]:
lisdirz = '/home/wcmckee/sellcoffee/'

In [34]:
os.listdir(lisdirz)


Out[34]:
['imgs',
 'localhost.txt',
 'hostnames',
 'index.html',
 'revcoffee.py',
 'recentarchive',
 'usernames',
 'config.cfg',
 'comps.json',
 'minutes.json',
 'pass',
 'style.css',
 'minlim',
 'touch.json',
 'products',
 'mins',
 'archive']

In [38]:
optouch = open(lisdirz + 'touch.json', 'r')

In [39]:
#(optouch.read())

In [ ]:


In [ ]:


In [40]:
opjsza = json.loads(optouch.read())

print opjsza


{u'y': u'0.216110229492', u'x': u'0.999969482422', u'z': u'0.0990295410156'}

In [55]:
ycord = opjsza['y']

In [56]:
ycord


Out[56]:
u'0.216110229492'

In [57]:
xcord = opjsza['x']

In [58]:
zcord = opjsza['z']

In [59]:
touchval = opjsza.values()

In [60]:
for touchv in touchval:
    print touchv[:3]
    print opjsza.keys()


0.2
[u'y', u'x', u'z']
0.9
[u'y', u'x', u'z']
0.0
[u'y', u'x', u'z']

In [ ]:
#turn into rgb

In [71]:
sycord = ycord[3]

In [72]:
szcord = zcord[3]

In [73]:
zycord = ycord[3]

In [78]:
isyc = int(sycord)

In [79]:
szrc = int(szcord)

In [84]:
if isyc == 8 or 9:
    isyc = 7
    
if szrc == 8 or 9:
    szrc = 7

In [85]:
isyc


Out[85]:
7

In [88]:
adzerp = str(isyc) + str(0)

In [91]:
zyarp = str(szrc) + str(0)

In [90]:
sycintz = int(adzerp)

In [92]:
zycintz = int(zyarp)

In [87]:
#uh.brightness(1)

#uh.set_pixel(isyc, szrc, 102, 63, 105)

#uh.show()

In [93]:
uh.brightness(int('0.')+ szrc)

while 1 == 1:
    for ext in range(8):
            uh.set_pixel(ext,ext, sycintz, zycintz, 105)
            for supz in range(8):
                        uh.set_pixel(ext, ext, sycintz, zycintz, 105)

    #os.system('python /home/wcmckee/github/signinlca/usertime.py')
    uh.show()
    time.sleep(1)

#UH.show()
time.sleep(1)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-93-86266d5599c0> in <module>()
----> 1 UH.brightness(1)
      2 
      3 while 1 == 1:
      4     for ext in range(8):
      5             uh.set_pixel(ext,ext, sycintz, zycintz, 105)

NameError: name 'UH' is not defined

In [ ]: