4、磁感应开关控制RGB
#MicroPython动手做(21)——掌控板之指南针模块
#磁感应开关控制RGB
from mpython import *
import time
while True:
magnetic.peeling()
oled.fill(0)
oled.DispChar("磁场强度", 39, 15, 1)
oled.DispChar((str(magnetic.get_field_strength())), 33, 35, 1)
oled.show()
if int(magnetic.get_field_strength()) > 200:
rgb.fill((int(255), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
oled.fill(0)
oled.DispChar("三颗红灯 开", 26, 20, 1)
oled.show()
time.sleep(1)
else:
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
|