import time
import random
from machine import Pin
# Virtual GPIO pins for HX711 load cells
DOUT_1 = 4
SCK_1 = 5
DOUT_2 = 6
SCK_2 = 7
# Threshold weight for triggering patient movement detection and catch pin
THRESHOLD_WEIGHT = 50 # Adjust as needed
# Virtual GPIO pin for pulse oximeter alarm
ALARM_PIN = 12
def setup():
# Initialize virtual GPIO pins
global dout_1, sck_1, dout_2, sck_2, alarm_pin
dout_1 = Pin(DOUT_1, Pin.IN)
sck_1 = Pin(SCK_1, Pin.OUT)
dout_2 = Pin(DOUT_2, Pin.IN)
sck_2 = Pin(SCK_2, Pin.OUT)
alarm_pin = Pin(ALARM_PIN, Pin.OUT)
# No setup needed for simulation
pass
def measure_weight():
# Simulate weight measurements for each load cell
weight_1 = random.uniform(0, 100) # Replace with actual weight measurement logic
weight_2 = random.uniform(0, 100) # Replace with actual weight measurement logic
return weight_1, weight_2
def check_patient_movement():
weight_1, weight_2 = measure_weight()
if weight_1 > THRESHOLD_WEIGHT or weight_2 > THRESHOLD_WEIGHT:
print("Patient movement detected!")
spo2 = random.randint(90, 100) # Simulate SpO2 reading
heart_rate = random.randint(60, 100) # Simulate heart rate reading
print("SpO2:", spo2, "%, Heart Rate:", heart_rate, "bpm")
if spo2 < 90 or heart_rate > 100: # Adjust thresholds as needed
trigger_alarm()
trigger_catch_pin()
def trigger_alarm():
print("Alarm triggered!")
alarm_pin.on()
time.sleep(5) # Alarm duration
alarm_pin.off()
def trigger_catch_pin():
print("Catch pin triggered to prevent falling!")
def main():
setup()
while True:
check_patient_movement()
time.sleep(1) # Adjust frequency of checking as needed
if __name__ == "__main__":
main()