Membrane Switch

The membrane switch is a fancy way of saying keypad/ anything with buttons.

# Imports

import LocoIOT

import LocoIOT_Communicator as MSG

import time



# USB Port Address

usb_str = "COM5"


def main():


# Create Class Instances

loco_iot = LocoIOT.LocoIOT()

msg = MSG.IOT_Codes()


# Connect to Controller Through USB Connection

loco_iot.connect(usb_str)


# Enable Ultrasonic Sensor Hardware Configuration

loco_iot.enable(msg.SUBTYPE_KEYPAD)


# Send Start Flag

loco_iot.start()


# Loop for an Arbitrary Duration

currentPass = ""

fileObj = open('Password1.txt', 'r+')

progPass = fileObj.readline()

fileObj.strip('/n')

fileObj.close()

passEntered = False


while (passEntered == False):

# Request Tilt Switch State Data

keypad_dict = loco_iot.getData(msg.SUBTYPE_KEYPAD)

if keypad_dict != '/0':


if (keypad_dict["Keypad"] == '#'):

currentPass = currentPass + keypad_dict['Keypad']


if(currentPass == progPass):

fileObj = open('passFile.txt', 'r+')

passEntered = True

print("Welcome_User")

fileObj.close()

else:

currentPass = currentPass + keypad_dict['Keypad']


else:

return

# Print Button Dictionary

print(keypad_dict)

# Short Arbitrary Delay

time.sleep(0.5)


newPass = ""

passUpdated = False

while (passUpdated == False):

key_dict = loco_iot.getData(msg.SUBTYPE_KEYPAD)

if (key_dict["Keypad"] != '\0'):

print(keypad_dict)

if (keypad_dict["Keypad"] == '#'):

fileObj.seek(0)

fileObj.write("newPass")

passUpdated = True

print("password changed")


elif (keypad_dict["Keypad"] == '*'):

fileObj.close()

return

else:

newPass = keypad_dict

print("Update failed")

# Short Arbitrary Delay

time.sleep(0.5)


# Close USB Connection to Controller

loco_iot.close()