回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页
best-icon

【童心向党】党史学习机 简单

头像 Hockel 2021.06.21 1624 4

步骤1 前言

历史是一面镜子,它可以折射过去,也可以昭示未来。历史也是一部教科书,让我们在过去中得到经验和教育,为未来的发展做出准备。学习党史,让我们时刻不忘老一辈革命先烈的牺牲和奉献,也让我们更清楚地意识到自己身上的使命和任务。

作为祖国的下一代,要坚定信念、发奋学习、立志报国,从小事做起,从了解一个党史故事开始,从做一个有关党史的科创项目开始,用党的精神鞭策自己,使自己不断进步,时刻做好接班人的准备!

project-image

步骤2 视频演示

材料清单

  • 掌控板+掌控宝 X1 链接
  • MP3模块 X1
  • 声音传感器 X1 链接
  • 激光切割亚格力 X1

步骤3 电路连接

project-image

步骤4 制作步骤

①用lasermaker设计该项目的模型

project-image

②:设计好的模型,进行激光切割!

project-image

③:开始对切割好的模型进行组装

project-image
project-image
project-image
project-image
project-image

步骤5 设计blynk APP

project-image

步骤6 程序编写

初始化操作:

1、设置wifi名称和密码,

2、设置blynk的授权码

3、定义RGB灯引脚

4、初始化MP3引脚

5、logo显示

project-image

对blynk的音乐组件进行程序设计:

project-image

对灯带相关组件进行程序编写:

project-image

对党史文本框音乐选择进行程序编写

project-image
代码
from mpython import *

import network

my_wifi = wifi()

my_wifi.connectWiFi('Erised', 'yiruosi88')

import ntptime

import blynklib

blynk = blynklib.Blynk('GJZQIuafyg4uL20GCZHcbWochaz8chqE', server='39.98.114.122', port=8080)

@blynk.handle_event("connect")
def connect_handler():
    print('Blynk connected')

@blynk.handle_event("disconnect")
def connect_handler():
    print('Blynk disconnected')

import neopixel

my_rgb = neopixel.NeoPixel(Pin(Pin.P13), n=15, bpp=3, timing=1)

from bluebit import *

import _thread

import framebuf

import font.digiface_44

@blynk.handle_event('write V0')
def write_virtual_pin_handler(pin, _value):
    global year, state, j, i
    for i in range(0, len(_value)):
        try: _value[i] = eval(_value[i])
        except: pass
    if len(_value) == 1: _value = _value[0]
    print(_value)
    if _value == 'play':
        mp3.play()
    elif _value == 'stop':
        mp3.pause()
    elif _value == 'prev':
        year = year + -1
        mp3.playPrev()
        oled.fill(0)
        display_font(font.digiface_44, (str(year)), 8, 8, False, 2)
        oled.show()
    else:
        mp3.playNext()
        year = year + 1
        oled.fill(0)
        display_font(font.digiface_44, (str(year)), 8, 8, False, 2)
        oled.show()

@blynk.handle_event('write V1')
def write_virtual_pin_handler(pin, _value):
    global year, state, j, i
    for i in range(0, len(_value)):
        try: _value[i] = eval(_value[i])
        except: pass
    if len(_value) == 1: _value = _value[0]
    my_rgb.brightness(_value / 100)
    my_rgb.write()

@blynk.handle_event('write V2')
def write_virtual_pin_handler(pin, _value):
    global year, state, j, i
    for i in range(0, len(_value)):
        try: _value[i] = eval(_value[i])
        except: pass
    if len(_value) == 1: _value = _value[0]
    print(_value)
    print(_value[1])
    for j in range(15):
        my_rgb[j] = (_value[0], _value[1], _value[2])
    my_rgb.write()

@blynk.handle_event('write V3')
def write_virtual_pin_handler(pin, _value):
    global year, state, j, i
    for i in range(0, len(_value)):
        try: _value[i] = eval(_value[i])
        except: pass
    if len(_value) == 1: _value = _value[0]
    if _value == 1:
        for i in range(15):
            my_rgb[i] = (255, 0, 0)
        my_rgb.write()
    else:
        my_rgb.fill( (0, 0, 0) )
        my_rgb.write()
        my_rgb.write()

p0 = MPythonPin(0, PinMode.ANALOG)

def make_rainbow(_neopixel, _num, _bright, _offset):
    _rgb = ((255,0,0), (255,127,0), (255,255,0), (0,255,0), (0,255,255), (0,0,255), (136,0,255), (255,0,0))
    for i in range(_num):
        t = 7 * i / _num
        t0 = int(t)
        r = round((_rgb[t0][0] + (t-t0)*(_rgb[t0+1][0]-_rgb[t0][0]))*_bright)>>8
        g = round((_rgb[t0][1] + (t-t0)*(_rgb[t0+1][1]-_rgb[t0][1]))*_bright)>>8
        b = round((_rgb[t0][2] + (t-t0)*(_rgb[t0+1][2]-_rgb[t0][2]))*_bright)>>8
        _neopixel[(i + _offset) % _num] = (r, g, b)

@blynk.handle_event('write V4')
def write_virtual_pin_handler(pin, _value):
    global year, state, j, i
    for i in range(0, len(_value)):
        try: _value[i] = eval(_value[i])
        except: pass
    if len(_value) == 1: _value = _value[0]
    print(_value)
    mp3.volume = _value

@blynk.handle_event('write V5')
def write_virtual_pin_handler(pin, _value):
    global year, state, j, i
    for i in range(0, len(_value)):
        try: _value[i] = eval(_value[i])
        except: pass
    if len(_value) == 1: _value = _value[0]
    print(_value)
    year = _value
    mp3.play_song((_value - 1919))
    oled.fill(0)
    display_font(font.digiface_44, (str(_value)), 8, 8, False, 2)
    oled.show()

mp3 = MP3(Pin.P16)

image_picture = Image()

def display_font(_font, _str, _x, _y, _wrap, _z=0):
    _start = _x
    for _c in _str:
        _d = _font.get_ch(_c)
        if _wrap and _x > 128 - _d[2]: _x = _start; _y += _d[1]
        if _c == '1' and _z > 0: oled.fill_rect(_x, _y, _d[2], _d[1], 0)
        oled.blit(framebuf.FrameBuffer(bytearray(_d[0]), _d[2], _d[1],
        framebuf.MONO_HLSB), (_x+int(_d[2]/_z)) if _c=='1' and _z>0 else _x, _y)
        _x += _d[2]

def thread_1():
    global year, state, j, i
    while True:
        if state == 1:
            make_rainbow(my_rgb, 15, ((p0.read_analog() + 1) / 40.96), 1)
            my_rgb.write()
        else:
            pass
ntptime.settime(8, "time.windows.com")
my_rgb.brightness(50 / 100)
my_rgb.write()
mp3.volume = 15
oled.fill(0)
oled.blit(image_picture.load('one.bmp', 0), (-5), 0)
oled.show()
state = 0
year = 0
_thread.start_new_thread(thread_1, ())
while True:
    blynk.run()

步骤7 总结

这样子,我们的党史学习机就做好了!在制作过程中遇到了一些问题:

Q:在下载党史音乐的时候,如果批量下载网页中的音频文件?

A:我们利用python的知识进行了网页批量的下载,具体教程详情:【mind+】python模式下批量爬取音频文件

Q:在设计进行党史音乐选取的时候:导入SD卡文件不能安照文件命名顺序播放?

A:我们需要先在电脑端进行排序,然后全选复制到SD卡内。问题就解决啦!

更多项目教程欢迎订阅个人博客:www.hockel.club

微信公众号:跟着hockel玩科创

project-image

评论

user-avatar
  • 虾虾^0^

    虾虾^0^2021.08.10

    0
    • 张登乾

      张登乾2021.06.22

      学习了

      0
      • WSY

        WSY2021.06.22

        好创意!

        0
        • 画家方

          画家方2021.06.22

          0