Hi there,
I’ve got this rascal blu-tacked up by my desk:
I can get it to recognise gestures, and record light/colours, but not seemingly at the same time
If I put the gesture first, then it will happily pick that up, but stop reading colours
, or if I put the colour reading up, then it will do that, but not recognise any gestures. I’ve tried having them in separate files, that wipes out the colours too. If it keep the “apds.color_data_ready” part in the loop, then everything stops, or if I take it, then the values never change
is it either/or, or am I missing something. I thought about going multithreaded, communicating between the processes with queues, but there’s limits
Has anyone managed to do the 2 simultaneously?
thanks
Toby
i2c = busio.I2C(board.SCL, board.SDA)
int_pin = digitalio.DigitalInOut(board.D5)
apds = APDS9960(i2c, interrupt_pin=int_pin)
apds.enable_proximity = True
apds.enable_gesture = True
apds.enable_color = True
def publish(client, metric, value):
topic =f"home/tele/{metric}/livingroom/desk"
print (f"publishing: {topic}:{value}")
client.publish(topic, value)
def getReadTime(seconds):
return datetime.now() + timedelta(0,seconds)
def postToIFTT(event):
r = requests.get(f')
while not apds.color_data_ready:
time.sleep(0.005)
readTime = getReadTime(0)
while True:
try:
gesture = apds.gesture()
if gesture == 0x01:
print("up")
publish(mqttClient,"gesture","up")
postToIFTT('desk_up')
elif gesture == 0x02:
print("down")
publish(mqttClient,"gesture","down")
postToIFTT('desk_down')
elif gesture == 0x03:
print("left")
publish(mqttClient,"gesture","left")
postToIFTT('desk_left')
elif gesture == 0x04:
print("right")
publish(mqttClient,"gesture","right")
postToIFTT('desk_right')
if datetime.now() > readTime:
# while not apds.color_data_ready:
# time.sleep(0.005)
r, g, b, c = apds.color_data
print(f"red: {r}, green: {g}, blue: {b}, clear: {c}")
publish(mqttClient,"red",r)
publish(mqttClient,"green",g)
publish(mqttClient,"blue",b)
publish(mqttClient,"clear",c)
colourTemp=colorutility.calculate_color_temperature(r, g, b)
lightLux=colorutility.calculate_lux(r, g, b)
publish(mqttClient,"colourTemp",colourTemp)
publish(mqttClient,"lightLux",lightLux)
readTime = getReadTime(sleepSeconds)
except Exception as error:
logger.error(error.args[0])
print("error: "+ error)
1 post - 1 participant