import time
import random
# Thresholds
IMPACT_LIMIT = 2.5 # g-force
PM25_LIMIT = 35.0 # μg/m³
# --- Simulated Buzzer ---
class SimulatedBuzzer:
def __init__(self):
self.state = False
def high(self):
self.state = True
print("BUZZER: ON")
def low(self):
self.state = False
print("BUZZER: OFF")
buzzer = SimulatedBuzzer()
# --- Simulated PM2.5 Sensor (potentiometer) ---
def read_pm25():
"""Simulate PM2.5 reading."""
return round(random.uniform(10, 80), 2)
# --- Simulated MPU6050 ---
class SimulatedMPU6050:
def get_accel_data(self):
ax = random.uniform(-3, 3)
ay = random.uniform(-3, 3)
az = random.uniform(0, 3)
return ax, ay, az
mpu = SimulatedMPU6050()
# --- Simulated Nokia 5110 LCD ---
class SimulatedLCD:
def clear(self):
print("\n" + "-"*30)
def text(self, msg, x, y):
print(msg)
def show(self):
print("-"*30)
lcd = SimulatedLCD()
# --- Main loop ---
while True:
# Read PM2.5
pm25 = read_pm25()
# Read MPU6050 acceleration
ax, ay, az = mpu.get_accel_data()
total_g = round((ax**2 + ay**2 + az**2) ** 0.5, 2)
# Display readings
lcd.clear()
lcd.text(f"Impact: {total_g} g", 0, 0)
lcd.text(f"PM2.5: {pm25} ug/m³", 0, 1)
# Check alerts
alert_triggered = False
if total_g > IMPACT_LIMIT:
lcd.text("IMPACT ALERT!", 0, 3)
alert_triggered = True
if pm25 > PM25_LIMIT:
lcd.text("PM ALERT!", 0, 4)
alert_triggered = True
# Buzzer control
if alert_triggered:
buzzer.high()
else:
buzzer.low()
lcd.show()
time.sleep(1)
Loading
nokia-5110
nokia-5110