micropython运行机制_MicroPython 2020年11月更新

extmod/nimble/nimble.mk: Add -Wno-old-style-declaration.

extmod/btstack/btstack.mk: Add -Wimplicit-fallthrough=0.

tests/micropython/extreme_exc.py: Unlink alloc'd lists earlier in chain.

stm32: Support C++ code and user C modules written in C++.

stm32/boards: Factor out common data/bss/heap/stack linker sections.

py/binary: Fix sign extension setting wide integer on 32-bit archs.

extmod/moductypes: Fix storing to (U)INT64 arrays on 32-bit archs.

py/mpz: Do sign extension in mpz_as_bytes for negative values.

lib/utils/pyexec: Add MICROPY_BOARD hooks before/after executing code.

stm32/boardctrl: Define MICROPY_BOARD_EARLY_INIT alongside others.

stm32: Add MICROPY_BOARD calls in various places in stm32_main.

stm32/main: Move update_reset_mode to outside the soft-reset loop.

extmod/nimble: Make stm32 and unix NimBLE ports use synchronous events.

extmod/modbluetooth: Re-instate optional no-ringbuf modbluetooth.

extmod/nimble: Poll startup directly rather than using NimBLE sem.

extmod/modbluetooth: Combine gattc-data-available callbacks into one.

unix: Make mp_hal_delay_ms run MICROPY_EVENT_POLL_HOOK.

unix: Handle pending events/scheduler in MICROPY_EVENT_POLL_HOOK.

extmod/modbluetooth: Make UUID type accessible outside modbluetooth.c.

tests/run-multitests.py: Add a -p flag to run permutations of instances.

tests/multi_bluetooth: Improve reliability of event waiting.

tests/run-multitests.py: Fix diff order, show changes relative to truth.

stm32/rtc: Validate the RTC prescaler on boot and change if incorrect.

stm32/Makefile: Allow boards to extend all SRC variables.

extmod/machine_mem: Only allow integers in machine.memX subscript.

esp32/machine_pin: Reset pin if init sets mode.

stm32/Makefile: Make the generation of `firmware.bin` explicit.

tools/makeqstrdefs.py: Run qstr preprocessing in parallel.

esp32,esp8266: Remove "FAT" from warning message in inisetup.py.

stm32/rfcore: Depend on NimBLE only when BLE enabled.

stm32/rfcore: Don't send HCI ACL cmds while another is pending.

stm32/flash: Implement WB55 flash locking.

stm32/rfcore: Make RX IRQ schedule the NimBLE handler.

tests/multi_bluetooth: Add a test for WB55 concurrent flash access.

tests/multi_bluetooth: Change dict index-and-del to pop, to clear event.

extmod/nimble/modbluetooth_nimble: Fix build when l2cap unavailable.

tests/multi_bluetooth: Add L2CAP channels multi-test.

docs/library/ubluetooth.rst: Add docs for L2CAP channels.

extmod/modbluetooth: Add API for L2CAP channels.

extmod/machine_i2c: Add init protocol method for generic I2C bindings.

nrf/README: Describe Pin numbering scheme for nRF52840.

github/workflows: Run unix and qemu-arm workflows when tests change.

README: Update badges for new GitHub Actions workflows.

tests/run-tests: Update skipped tests on CI for GitHub Actions.

travis: Stop using Travis for CI.

github/workflows: Add workflows for all CI tasks, builds and tests.

tools/ci.sh: Add helper script to run CI tasks.

py/mpprint: Prevent case fall-through when assert is disabled.

tests/extmod: Add vfs_posix.py test for uos.VfsPosix class.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Micropython 中使用蜂鸣器播放音频可以通过 PWM 信号调制,实现不同频率的声音。以下是使用 ESP32 板载蜂鸣器的示例代码: ```python import machine import time # 定义蜂鸣器引脚 buzzer_pin = machine.Pin(12, machine.Pin.OUT) # 定义 PWM 频率 pwm_frequency = 1000 # 定义不同频率对应的占空比 pwm_duty_cycle = { 262: 50, # 中音 Do 294: 50, # 中音 Re 330: 50, # 中音 Mi 349: 50, # 中音 Fa 392: 50, # 中音 Sol 440: 50, # 中音 La 494: 50, # 中音 Si } # 播放音符 def play_note(frequency): buzzer_pwm = machine.PWM(buzzer_pin, freq=pwm_frequency, duty=pwm_duty_cycle.get(frequency)) time.sleep(0.5) # 持续时间 buzzer_pwm.deinit() # 播放音乐 def play_music(music_notes): for note in music_notes: play_note(note) # 定义音乐 music = [262, 294, 330, 262, 262, 294, 330, 262, 330, 349, 392, 330, 349, 392, 392, 440, 392, 349, 330, 262, 330, 392, 440, 330, 392, 440, 494, 440, 392, 349, 392, 440, 494, 440, 392, 349, 330, 262, 294, 330, 262, 262, 294, 330, 262] # 播放音乐 play_music(music) ``` 该示例代码中,我们通过 `machine.PWM` 方法生成一个 PWM 信号,并设置频率和占空比。然后通过 `time.sleep` 方法控制蜂鸣器持续时间,最后通过 `PWM.deinit` 方法停止 PWM 信号输出。 在 `play_note` 函数中,我们通过 `pwm_duty_cycle.get(frequency)` 获取不同频率对应的占空比,然后生成一个 PWM 信号,并播放对应频率的音符。 在 `play_music` 函数中,我们遍历音乐列表,并通过 `play_note` 函数播放每个音符。如果需要播放其他音乐,只需要修改 `music` 列表即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值