8、实时测量声光强度(垂直柱状条)
#MicroPython动手做(18)——掌控板之声光传感器
#实时测量声光强度(垂直柱状条)
from mpython import *
import math
myUI = UI(oled)
while True:
s = ((100 - 0) / (2500 - 0)) * (sound.read() - 0) + 0
g = ((100 - 0) / (4059 - 0)) * (light.read() - 0) + 0
oled.fill(0)
oled.DispChar('声', 16, 1, 1)
oled.DispChar('强', 16, 16, 1)
oled.DispChar('度', 16, 32, 1)
oled.DispChar((str(math.floor(((100 - 0) / (2500 - 0)) * (sound.read() - 0) + 0))), 16, 48, 1)
myUI.stripBar(36, 4, 12, 56, s, 0, 1)
oled.DispChar('光', 80, 1, 1)
oled.DispChar('强', 80, 16, 1)
oled.DispChar('度', 80, 32, 1)
oled.DispChar((str(math.floor(((100 - 0) / (4059 - 0)) * (light.read() - 0) + 0))), 80, 48, 1)
myUI.stripBar(100, 4, 12, 56, g, 0, 1)
oled.show()
|