课程设计1:设计一个抢答器满足如下要求:
1,可以同时满足3人抢答需求
2,最先完成抢答的人,其编号显示在数码管上(后按下的人,不显示其编号)
3,设计一个复位按键,可重新开始新一轮抢答(数码管消隐)
程序设计流程图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#基础代码,在此代码基础上完善程序完成课程设计要求之功能 from gpiozero import LEDBoard,Button from time import sleep from signal import pause #from tkinter import * button3 = Button(16) button2 = Button(20) button4 = Button(21) button1 = Button(26) leds = LEDBoard(2, 3, 4, 14, 17,27,22,23,active_high=False) M7G= [ (0, 0, 0, 0, 0,0, 0,0), (1, 1, 1, 1,1, 1,0,0), (0, 1, 1, 0, 0,0, 0,0), (1, 1, 0, 1, 1,0, 1,0), (1, 1, 1, 1,0, 0,1,0), (0, 1, 1, 0,0, 1,1,0), (1, 0, 1, 1,0, 1,1,0), (1, 0, 1, 1,1, 1,1,0), (1, 1, 1, 0,0, 0,0,0), (1, 1, 1, 1,1, 1,1,0), (1, 1, 1, 1,0, 1,1,0), ] leds.value = M7G[0] #初始值全消隐 lockval = 0 #记录锁定状态变量 #定义Button的回调函数 def helloButton(): global lockval if button1.is_pressed: leds.value = M7G[2] elif button2.is_pressed: leds.value = M7G[3] elif button3.is_pressed: leds.value = M7G[4] elif button4.is_pressed:#复位按键 #leds.value = M7G[5] #print(button1.value) button1.when_pressed = helloButton button2.when_pressed = helloButton button3.when_pressed = helloButton button4.when_pressed = helloButton pause() |
转载请注明:徐自远的乱七八糟小站 » 课程设计1:设计一个抢答器