制作会说话的Dalek

micro:bit编程、教学、展示
STEM
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

制作会说话的Dalek

#1

帖子 shaoziyang »

来自http://blog.withcode.uk/2016/12/code-yo ... on-speech/

制作会说话的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)

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章