from sense_hat import SenseHat
from time import sleep, strftime
sense = SenseHat()
# ------------------------------------------------
# DATA
# ------------------------------------------------
# Colours
colours = {
'r' : [255, 0, 0],
# Add orange, yellow, green, blue, indigo, violet here
'o' : [255, 125, 0],
'y' : [255, 255, 0],
'g' : [0, 255, 0],
'b' : [0, 0, 255],
'i' : [75, 0, 130],
'v' : [51, 2, 170],
'n' : [135, 80, 22],
'w' : [255, 255, 255],
'e' : [0, 0, 0] # e stands for empty/black
}
# Pictures
with open("pictures.txt", "r") as f:
all_pics = f.readlines()
# ------------------------------------------------
# FUNCTIONS
# ------------------------------------------------
# Display a given picture string on the sense HAT
# ------------------------------------------------
def display_pic(pic_string):
# Get rid of newline and split the line into a list
pic_string = pic_string.strip("\n")
pic_string = pic_string.split(",")
# Look up each letter in the dictionary of colours and add it to the list
pic_list = []
for letter in pic_string:
pic_list.append(colours[letter])
# Display the pixel colours from the file
sense.set_pixels(pic_list)
# ------------------------------------------------
# MAIN PROGRAM
# ------------------------------------------------
sense.clear()
display_pic(all_pics[7]
it show this-----> SyntaxError: unexpected EOF while parsing
这段代码是为了在覆盆子pi上显示图像感觉HAT请告诉我解决这个问题。谢谢你我如何编辑代码。我按照raspberry pi网站上的说明进行操作。我正在使用感觉HAT制作一个降临节日历,我希望它能让感觉HAT显示图片。
答案 0 :(得分:0)
将a)添加到最后一行
display_pic(all_pics [7])