树莓派Pico W:LED与多段7段数码管显示项目实践
1. 树莓派Pico W LED项目
1.1 骰子模拟项目
骰子模拟项目通过按下按钮触发,程序会生成一个1到6之间的随机数,然后根据这个随机数点亮对应的LED组合,模拟骰子的点数。以下是该项目的代码:
# The program jumps here after the button is pressed
#
def DICE():
n = random.randint(1, 6)
# generate a random number
pattern = DICE_NO[n]
# find the pattern
Port_Output(pattern)
# turn ON required LEDs
utime.sleep(3)
# wait for 3 seconds
Port_Output(0)
# turn OFF all LEDs
return
#
# Configure PORT to all outputs
#
Configure_Port()
#
# Main program loop, check if Button is pressed
#
while True:
if Button.value() == 0:
# Button pressed?
DICE()
# Call DICE
pass
# Do nothing
超级会员免费看
订阅专栏 解锁全文
67

被折叠的 条评论
为什么被折叠?



