from machine import Pin
from time import sleep
# Power Plant Earthquake Emergency Shutdown System
# Wokwi Raspberry Pi Pico version
# Button = Control Board
button = Pin(21, Pin.IN, Pin.PULL_DOWN)
# LEDs = Emergency Board
red_led = Pin(20, Pin.OUT) # Alarm LED
green_led = Pin(19, Pin.OUT) # Normal/OK LED
# This simulates the MongoDB/mLab cloud document:
# Original lab document: {"alarm": false}
alarm_database = {
"alarm": False
}
previous_button_state = button.value()
print("Power Plant Earthquake Emergency Shutdown System started")
print("Wokwi version: MongoDB is simulated using a local JSON dictionary")
print("Press the button to trigger the alarm")
while True:
# CONTROL BOARD LOGIC
# Read the button state
button_state = button.value()
# If button state changes, update the simulated database
if button_state != previous_button_state:
alarm_database["alarm"] = True if button_state == 1 else False
print("Control Board updated database:", alarm_database)
previous_button_state = button_state
# EMERGENCY BOARD LOGIC
# Read the alarm value from the simulated database
alarm = alarm_database["alarm"]
if alarm:
red_led.value(1)
green_led.value(0)
print("Emergency Board reads alarm=True: RUN RUN RUN")
else:
red_led.value(0)
green_led.value(1)
print("Emergency Board reads alarm=False: OK")
sleep(1)