IOT Buzzer+Button

# 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_PAS_BUZZ)

loco_iot.enable(msg.SUBTYPE_SW_1)

loco_iot.enable(msg.SUBTYPE_SW_2)

loco_iot.enable(msg.SUBTYPE_SW_3)


C = [523 , 1000]

E = [659 , 1000]

G = [784 , 1000]


# Start Listening for Control/Request Messages

loco_iot.start()


# Infinite Loop: Press STOP to end the loop.

while True:

btn_dict1 = loco_iot.getData(msg.SUBTYPE_SW_1)

print(btn_dict1)

if(btn_dict1 == {'Button 1':0}):

loco_iot.setData(msg.SUBTYPE_PAS_BUZZ, [523])

print("C button pressed")

else:

print("C Button NOT Pressed")

time.sleep(0.5)


#Red

btn_dict2 = loco_iot.getData(msg.SUBTYPE_SW_2)

print(btn_dict2)

if(btn_dict2 == {'Button 2':0}):

loco_iot.setData(msg.SUBTYPE_PAS_BUZZ, [659])

print("E button pressed")

else:

print("E Button NOT Pressed")

time.sleep(0.5)

#Green

btn_dict3 = loco_iot.getData(msg.SUBTYPE_SW_3)

print(btn_dict3)

if(btn_dict3 == {'Button 3':0}):

loco_iot.setData(msg.SUBTYPE_PAS_BUZZ, [784])

print("G button pressed")

else:

print("G Button NOT Pressed")

time.sleep(0.5)


# Pause program execution for the buzzer duration

time.sleep(1)


# Close Connection to the Microcontroller

loco_iot.close()