6、简易钱包防丢磁感应报警器(钱包里放置一块强磁片)
离开一段距离,磁场强度小于8,则声光报警
#MicroPython动手做(21)——掌控板之磁场传感器
#简易钱包防丢磁感应报警器(钱包里放置一块强磁片)
from mpython import *
import time
import music
while True:
magnetic.peeling()
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
oled.fill(0)
oled.DispChar('磁场强度', 0, 16, 1)
oled.DispChar((str(magnetic.get_field_strength())), 0, 32, 1)
oled.show()
if magnetic.get_field_strength() < 8:
rgb.fill((int(255), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
music.pitch(523, 300)
music.pitch(988, 300)
else:
music.stop()
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
time.sleep(1)
|