from synapse.platforms import * BUZZER_PIN = 0 #pin 2 LED_RED_PIN = 11 #pin 13 LED_GREEN_A_PIN = 13 #pin 15 LED_GREEN_B_PIN = 14 #pin 16 BUTTON_PIN_A = 15 #pin 17 BUTTON_PIN_B = 12 #pin 14 SWITCH_PIN = 17 #pin 19 @setHook(HOOK_STARTUP) def startupEvent(): #Buzzer setPinDir(BUZZER_PIN, True) #Switch setPinDir(SWITCH_PIN, False) setPinPullup(SWITCH_PIN, True) #Button A setPinDir(BUTTON_PIN_A, False) setPinPullup(BUTTON_PIN_A, True) #Button B setPinDir(BUTTON_PIN_B, False) setPinPullup(BUTTON_PIN_B, True) #LED Green A setPinDir(LED_GREEN_A_PIN, True) #LED Green B setPinDir(LED_GREEN_B_PIN, True) #LED Red setPinDir(LED_RED_PIN, True) writePin(LED_RED_PIN, True) #Monitor button for press monitorPin(BUTTON_PIN_A, True) #Monitor button for press monitorPin(BUTTON_PIN_B, True) @setHook(HOOK_GPIN) def buttonEvent(pinNum, isSet): #If button pressed, turn off LED, buzzer if pinNum == BUTTON_PIN_A: if not isSet: writePin(LED_GREEN_A_PIN, False) writePin(BUZZER_PIN, False) #If button pressed, turn on LED (test) if pinNum == BUTTON_PIN_B: if not isSet: writePin(LED_GREEN_B_PIN, True) #Trigger alert (LED/buzzer) def triggerAlert(): #Turn on LED writePin(LED_GREEN_A_PIN, True) #If buzzer enabled if (readPin(SWITCH_PIN) == False): #Turn on buzzer writePin(BUZZER_PIN, True) #### Handle Events ### #Doorbell ring def doorbell_ring_handle(): triggerAlert()