from microbit import *
import radio
radio.config(group=17)
compass.calibrate()
radio.on()
while True:
if button_a.was_pressed():
display.scroll(compass.get_field_strength())
if compass.get_field_strength() < 100000:
display.show(Image.DIAMOND_SMALL)
radio.send('door open')
else:
display.clear()
radio.send('door closed')
sleep(2000)
报警端代码:
from microbit import *
import music
import radio
radio.config(group=17)
radio.on()
while True:
message = radio.receive()
if message:
if message == 'door open':
display.show(Image.NO)
music.play(["C4:4"])
if message == 'door closed':
display.show(Image.YES)
# Python uses nanoteslas to measure magnetism.
# Experiment with different numbers depending on the
# strength of your magnet, which you can read by
# pressing button A.
from microbit import *
while True:
if button_a.was_pressed():
display.scroll(compass.get_field_strength())
if compass.get_field_strength() < 200000:
display.show(Image.ANGRY)