Mini-Project 2 RGB LED's+ Buttons
# Module Import
import LocoIOT
import time
# Class Instances Creation
loco_iot = LocoIOT.LocoIOT()
msg = LocoIOT.IOT_Codes()
# Initiate Connection to the Microcontroller
loco_iot.connect()
# Enable Passive Buzzer Hardware Configuration
loco_iot.enable(msg.SUBTYPE_RGB)
loco_iot.enable(msg.SUBTYPE_PAS_BUZZ)
loco_iot.enable(msg.SUBTYPE_SW_1)
loco_iot.enable(msg.SUBTYPE_SW_2)
# Start Listening for Control/Request Messages
loco_iot.start()
C = [523, 1000]
# Infinite Loop: Press STOP to end the loop.
#Blue
while True:
# Request and Print Button State Data
btn_dict1 = loco_iot.getData(msg.SUBTYPE_SW_1)
print(btn_dict1)
if(btn_dict1 == {'Button 1':0}):
dim = [0, 0, 255]
loco_iot.setData(msg.SUBTYPE_RGB, dim)
print("Blue Button Pressed")
else:
dim = [255, 0, 0]
loco_iot.setData(msg.SUBTYPE_RGB, dim)
print("Blue Button NOT Pressed")
time.sleep(1)
#Green
btn_dict2 = loco_iot.getData(msg.SUBTYPE_SW_2)
print(btn_dict2)
if(btn_dict2 == {'Button 2':0}):
dim = [0, 255, 0]
loco_iot.setData(msg.SUBTYPE_RGB, dim)
print("Green Button Pressed")
else:
dim = [255, 0, 0]
loco_iot.setData(msg.SUBTYPE_RGB, dim)
print("Green Button NOT Pressed")
time.sleep(1)
#Buzzer
if(btn_dict1 == {'Button 1':0}) and (btn_dict2 == {'Button 2':0}):
loco_iot.setData(msg.SUBTYPE_PAS_BUZZ, 523)
print("Buzzer Buttons Pressed")
else:
print("Buzzer Buttons NOT Pressed")
time.sleep(1)
# Pause program execution for the buzzer duration
time.sleep(1)
# Close Connection to the Microcontroller
loco_iot.close()