If Button Exercise
# 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 Button Hardware Configuration
loco_iot.enable(msg.SUBTYPE_SW_1)
# Start Listening for Control/Request Messages
loco_iot.start()
# Infinite Loop: Press cancel to end the loop.
while True:
# Request Button State Data
btn_dict1 = loco_iot.getData(msg.SUBTYPE_SW_1)
print(btn_dict1)
if(btn_dict1 == {'Button 1':0}):
print("Button Pressed")
else:
print("button NOT pressed")
time.sleep(0.5)
# Close Connection to the Microcontroller
loco_iot.close()