楼主: 驴友花雕
|
[MP动手做] MicroPython动手做(18)——掌控板之声光传感器 |
9、A键声音波形,B键光线波形 [mw_shl_code=applescript,false]#MicroPython动手做(18)——掌控板之声光传感器 #A键声音波形,B键光线波形 import time from mpython import * time.sleep_ms(50);print(('__TITLE', '声光波形'));time.sleep_ms(50) while True: if button_a.value() == 0: print((sound.read(),)) if button_b.value() == 0: print((light.read(),)) oled.fill(0) oled.DispChar('声音', 35, 16, 1) oled.DispChar((str(sound.read())), 65, 16, 1) oled.DispChar('光线', 35, 32, 1) oled.DispChar((str(light.read())), 65, 32, 1) oled.show() [/mw_shl_code] |
10、同时测量声光环境的实时波形 [mw_shl_code=python,false]#MicroPython动手做(18)——掌控板之声光传感器 #同时测量声光环境的实时波形 from mpython import * import time oled.fill(0) oled.DispChar(' 声光值数据采集', 0, 16, 1) oled.DispChar(' 按A开始 按B结束', 0, 32, 1) oled.show() time.sleep_ms(50);print(('__TITLE', '声音值', '光线值'));time.sleep_ms(50) while True: while button_a.value() == 0: while not button_b.value() == 0: print((sound.read(), light.read())) time.sleep_ms(100)[/mw_shl_code] |
11、声控RGB灯环 通过声音传感器检测到音乐声音的大小,并将其转换为亮灯的数量。 #MicroPython动手做(18)——掌控板之声光传感器 #声控RGB灯环 [mw_shl_code=applescript,false]#MicroPython动手做(18)——掌控板之声光传感器 #声控RGB灯环 from mpython import * import neopixel my_rgb = neopixel.NeoPixel(Pin(Pin.P8), n=24, bpp=3, timing=1) def upRange(start, stop, step): while start <= stop: yield start start += abs(step) def downRange(start, stop, step): while start >= stop: yield start start -= abs(step) while True: oled.fill(0) oled.DispChar("声音大小", 0, 0, 1) oled.DispChar((str(sound.read())), 0, 16, 1) oled.show() sheng = sound.read() // 140 if sheng == 0: my_rgb.fill( (0, 0, 0) ) my_rgb.write() else: for i in (0 <= int(sheng)) and upRange(0, int(sheng), 1) or downRange(0, int(sheng), 1): my_rgb = (0, 50, 0) my_rgb.write()[/mw_shl_code] |
12、十段音量柱状图形显示 //MicroPython动手做(18)——掌控板之声光传感器 //十段音量柱状图形显示 [mw_shl_code=applescript,false]//MicroPython动手做(18)——掌控板之声光传感器 //十段音量柱状图形显示 #include <MPython.h> // 动态变量 volatile float mind_n_HengZuoBiao; // 主程序开始 void setup() { mPython.begin(); display.lineWidth(5); } void loop() { mind_n_HengZuoBiao = 16; for (int index = 0; index < 10; index++) { display.line(mind_n_HengZuoBiao, 55, mind_n_HengZuoBiao, (map((sound.read()), 0, 4095, 50, 0))); delay(100); mind_n_HengZuoBiao += 10; yield(); } display.fillScreen(0); }[/mw_shl_code] |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed