Micropython学习交流群 学习QQ群:786510434 提供多种固件下载和学习交流。

Micropython-扇贝物联 QQ群:31324057 扇贝物联是一个让你与智能设备沟通更方便的物联网云平台

Micropython学习交流群 学习QQ群:468985481 学习交流ESP8266、ESP32、ESP8285、wifi模块开发交流、物联网。

Micropython老哥俩的IT农场分享QQ群:929132891 为喜欢科创制作的小白们分享一些自制的计算机软硬件免费公益课程,由两位多年从事IT研发的中年大叔发起。

Micropython ESP频道

micropython esp32c3 演奏马里奥1-1以及如何使用无缘蜂鸣器


演奏马里奥1-1以及如何使用无缘蜂鸣器


B站视频教程:[micropython]演奏马里奥1-1以及如何使用无缘蜂鸣器_哔哩哔哩_bilibili

from machine import PWM,Pin
import time
import _thread
beep = PWM(Pin(2),freq=50000,duty=500)
#cdefgab
s2 = [50000,262 ,294, 330 ,349 ,392 ,220 ,247 ]
s3 = [50000,523,587,659,698,784,440,494]
s4 = [50000,1044, 1175 ,1318, 1397 ,1568 ,880 ,988]
def play(level,power = 1,deltatime = 200):
    if power == 0:
        beep.freq(s2[level])
    elif power == 1:
        beep.freq(s3[level])
    elif power == 2:
        beep.freq(s4[level])
    time.sleep_ms(deltatime)
    beep.freq(50000)
def plays(l):
    for i in l:
        if len(i) == 3:
            play(i[0],i[1],i[2])
        else:
            play(i[0],i[1])
def test():
    plays([(3,2),(3,2),(0,2),(3,2),(0,2),(1,2),(3,2),(0,2),(5,2),(0,2,500)])
    plays([(1,2,600),(5,1,600),(3,1,600),(6,1,400),(7,1,400),(7,1),(6,1,400)])
    plays([(5,1),(3,2,400),(5,2),(6,2,400),(4,2),(5,2,400),(3,2,400),(1,2),(2,2),(7,1)])
    plays([(1,2,600),(5,1,600),(3,1,600),(6,1,400),(7,1,400),(7,1),(6,1,400)])
    plays([(5,1),(3,2,400),(5,2),(6,2,400),(4,2),(5,2,400),(3,2,400),(1,2),(2,2),(7,1)])
_thread.start_new_thread(test,())



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 ESP56.com All Rights Reserved

执行时间: 0.0093538761138916 seconds