4408浏览
楼主: 驴友花雕

[MP动手做] MicroPython动手做(18)——掌控板之声光传感器

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2020-4-27 09:50:12

mPython 图形编程

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-27 10:23:03

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-29 21:13: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]
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-29 21:16:48

A键声音波形

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-29 21:20:36

B键光线波形

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-29 21:23:47

mPython 图形编程

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-29 21:27:24

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-30 11:02:09

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]
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-30 11:05:30

MicroPython动手做(18)——掌控板之声光传感器图2

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-30 11:09:03

mPython 图形编程

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-4-30 11:54:54

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-5-5 16:49:51

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]
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-5-5 16:54:13

mPython X 图形编程


MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-5-5 17:16:50

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-5-5 20:17:00

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]
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-5-5 20:26:23

Mind+ 图形编程

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2020-5-5 20:52:24

MicroPython动手做(18)——掌控板之声光传感器图1
回复

使用道具 举报

12
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail