Final answer:
Design a security system using a microbit by programming it to utilize its built-in sensors, such as the accelerometer for detecting shakes and the light sensor for detecting light levels. Include code to reset the alarm and display which sensor was triggered.
Step-by-step explanation:
Designing a Microbit Security System
To design a security system using a microbit as a hub, you will need to program it to interact with onboard sensors such as the accelerometer (shake sensor) and light sensor. The accelerometer can detect movement which may signify an intrusion, while the light sensor can detect changes in light intensity which could also indicate someone entering a room.
Here's a simple example of how this might be coded:
from microbit import *
# Define variables to keep track of which sensor was triggered last
last_triggered_sensor = None
# Function to update the display
def update_display(sensor_name):
display.clear()
display.scroll(sensor_name)
while True:
# Checking for accelerometer shake
if accelerometer.was_gesture('shake'):
last_triggered_sensor = 'SHAKE'
update_display(last_triggered_sensor)
# Checking the light level
light_level = display.read_light_level()
if light_level > threshold:
last_triggered_sensor = 'LIGHT'
update_display(last_triggered_sensor)
# Button A to reset the alarm
if button_a.is_pressed():
last_triggered_sensor = None
update_display('RESET')
You would need to set a threshold value for the light intensity that, when exceeded, triggers the alarm. The 'RESET' message appears when the alarm is reset using Button A on the microbit.