制作会说话的Dalek(神秘博士中的人物)。平时显示一个笑脸,按下A键显示哭脸,并随机说话。
- 网站包括了一个在线模拟器,可以直接运行查看效果。
代码: 全选
# turn your microbit into a ticklish talking darlek
# connect a speaker to pins 0 and 1
from microbit import *
import speech
import random
# add your own messages to this list
messages = ["Leave me alone", "Oooh, that tickles", "Exterminate", "Ho ho ho", "Stop it", "I'll get you for that", "He he he", "Please. No more tickles"]
# loop forever
while True:
# show a happy face until you press A to tickle it
display.show(Image.HAPPY)
sleep(100)
# check if A has been pressed
if button_a.was_pressed():
# choose a random message
message = random.choice(messages)
display.show(Image.SAD)
speech.say(message)