fix some bug for led in handbit.py
@@ -11,24 +11,32 @@ class led:
self.val = 1
self.pin = pin
def setbrightness(n,val):
+ global rgb
if n in (0,1,2) and 0 <= val <= 1023:
if val == 0:
rgb[n] = (0,0,0)
+ rgb.write()
else:
val = val // 20 + 1
rgb[n] = (val,val,val)
+ rgb.write()
def setonoff(n,val):
+ global rgb
if n in (0,1,2):
if(val == -1):
- if rgb[n] != (0,0,0):
+ if rgb[n] == (0,0,0):
rgb[n] = (50,50,50)
+ rgb.write()
else:
rgb[n] = (0,0,0)
+ rgb.write()
else:
rgb[n] = (50*val, 50*val, 50*val)
+ rgb.write()
def getonoff(n):
+ global rgb
if n in (0,1,2):
- return (rgb[n][0]+rgb[n][1]+rgb[n][2])//3
+ return int(bool((rgb[n][0]+rgb[n][1]+rgb[n][2])))
class Button:
def __init__(self, pin):
