覆盆子Pi和Pi-Lite的万圣节快乐

1

It’每年的那个时候,疯狂的发明家开始创建万圣节主题的电子项目。一世’我从未设法组织过一个季节性项目,但今年我决定尝试一下。

所以今年我决定接受’我了解了Pi-Lite,并创建了一个简单的万圣节项目,我可以将它贴在窗户上,旁边还有我们更传统的雕刻南瓜。

这篇文章来自我之前的Pi-Lite文章:

TPi-Lite万圣节快乐示例o重新创建这个项目’ll need :

  • 树莓派
  • Pi-Lite
  • SD卡(我使用了最新的Raspbian映像)
  • 电源供应
  • 我的Python脚本

蟒蛇脚本

以下脚本将显示动画对象,然后滚动“Happy Halloween !”在屏幕上。重复直到按CTRL-C。

#!/usr/bin/env 蟒蛇

import sys
import serial
import time

# Define lists which contain frames of animations
face   = ['000000000000000000010011000011000100011000110000010110000110110000110110000010110011000110011000100010011000000000000000000000',
          '000000000000000000010000011011000110011000110000010110000110110000110110000010110011000110011000110010000011000000000000000000']
bat    = ['010000000011000000001100000000110000110110000011111011001111100001111100011111011110110000000110000001100000011000000010000000',
          '000000100000001100000011000000110000110110001011111010001111100001111100011111010110110001000110000000011000000001100000000100']
ghost  = ['000000000000000000000011111001100001010000010100100010100000001100100001100000010010000010001100001000011111000000000000000000',
          '000000000000000000000011111001100010010000010100000001100100001100000010100100010010000001001100001000011111000000000000000000']
spider = ['001001000010010010100100101010101000001011110000111001000111000000111000000111001001011110010101000100100101010010010001001000',
          '010010010100100101101001000100101010011011101000111000000111000000111000000111000011011101100101010101001000100100101010010010']

# Combine into dictionary object
objects = {'face':face,'bat':bat,'ghost':ghost,'spider':spider}

# Define text message to scroll
message = "Happy Halloween !\r"

# Configure Pi serial port
s = serial.Serial()
s.baudrate = 9600
s.timeout = 0
s.port = "/dev/ttyAMA0"

def showObject(name,count,delay):
  # Function to 显示 frames from a specified object
  # name  - object to 显示
  # count - number of times to 显示 object
  # delay - ms to wait between frames
  object = objects[name]for x in range(count):
    for frame in range(len(object)):
      command = "$$$F" + object[frame]+ "\r"
      s.write(command)
      时间睡眠(delay)
  # Clear 显示
  s.write("$$$ALL,OFF\r")

try:
    # Open serial port
    s.open()
except serial.SerialException, e:
    sys.stderr.write("could not open port %r: %s\n" % (port, e))
    sys.exit(1)

# Turn off all  LED s
s.write("$$$ALL,OFF\r")
time.sleep(0.5)

try:

  while True:
    # Get list of object names from dictionary
    mykeys = objects.keys()

    # Loop through each object
    for x in range(len(mykeys)):
      showObject(mykeys[x],5,0.5)
      时间睡眠(1)
      s.write(message)
      # Wait for scrolling message
      时间睡眠(8)

except KeyboardInterrupt:
  print("Quit")

这是正在运行的脚本的视频:

脚本下载

除了剪切以上脚本之外,您还可以使用以下命令将其直接下载到您的Pi:

wget //bitbucket.org/MattHawkinsUK/rpispy-pi-lite/raw/master/pi_lite_happy_halloween.py

或者,如果您在Pi上使用Git,则可以通过在BitBucket上克隆我的Pi-Lite存储库来获取我的所有Pi-Lite示例脚本:

git clone //bitbucket.org/MattHawkinsUK/rpispy-pi-lite.git

修改项

您可以通过多种方式修改和改进此脚本。您可以更改滚动消息,但请确保调整“time.sleep”延迟比赛。有关我这次如何估算的更多详细信息, 你好世界滚动文本发布。粗略估计,这是您的消息中每个字符0.5秒。

您还可以通过定义新列表并将其添加到字典中来添加其他对象。要为每帧生成126个字符串,您可以使用 14×9 LED 矩阵精灵生成器 (在新窗口/标签中打开)。

万圣节快乐!

分享。

1条评论

  1. 非常感谢,这正是我让Xmas前进所需要的…

    对于那些需要的人,在这里’我动画的雪落:


    snow = ['000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    '000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    '000000000000000000100000000010000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    '001000000000000000000000000010000000101000000010000000000000000100000000000000000000000000000000000000000000000000000000000000',
    '001010000000100000000000000000000000001000000010100000001000000100000000010000000100000000000000000000000000000000000000000000',
    '000010000000101000000010000000000000100000000000100000001010000000100000010000000101000000010000000000000000000000000000000000',
    '010000000000001000000010100000001000100000000010000000100010000000101000000010000001000000010100000001000000000000000000000000',
    '010100000001000000100000100000001010000000100010000000101000000010001000000010100000001000000100000001010000000100000000000000',
    '000100000001010000100100000010000010100000101000000010001000000010100000001000100000001010000000100000010000000101000000010000',
    '000000000000010000000101000010010000101000001010000010000000001000100000001010000000100010000000101000000010000001000000010100',
    '000000000000000000000001000000010100001001000010100000001000001000000000000010000000101000000010001000000010000000001000000100',
    '000000000000000000000000000000000100000001010000100100001010000000100000000000000000001000000010100000001000000000001000000000',
    '000000000000000000000000000000000000000000010000000101000010010000101000000010000000000000000000100000001010000000100000000000',
    '000000000000000000000000000000000000000000000000000001000000010000001001000010100000001000000000000000000010000000101000000010',
    '000000000000000000000000000000000000000000000000000000000000000000000001000000100000001010000000100000000000000000001000000010',
    '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000101000000010000000000000000000',
    '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000010000000001000000000',
    '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000',
    '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000']

发表评论

该网站使用Akismet减少垃圾邮件。 了解如何处理您的评论数据.