makecode-python定时器,1小时

def on_button_pressed_a():
    global duration1, localx, localy
    duration1 += 1
    if duration1 > 10:
        basic.clear_screen()
        duration1 = 0
    localx = (duration1 - 1) % 5
    localy = Math.floor((duration1 - 1) / 5)
    led.plot_brightness(localx, localy, 255)
input.on_button_pressed(Button.A, on_button_pressed_a)
 
def on_button_pressed_ab():
    global duration10, x, y
    duration10 += 1
    if duration10 > 5:
        basic.clear_screen()
        duration10 = 0
    x = duration10 - 1
    y = 4
    led.plot_brightness(x, y, 255)
input.on_button_pressed(Button.AB, on_button_pressed_ab)
 
def on_button_pressed_b():
    global startTime
    startTime = input.running_time()
    basic.show_string("Go")
input.on_button_pressed(Button.B, on_button_pressed_b)
 
def on_gesture_screen_up():
    global endTime, passTime, duration, showLeft
    endTime = input.running_time()
    passTime = endTime - startTime
    duration = duration1 + duration10 * 10
    if passTime <= duration * 60000:
        showLeft = (duration * 60000 - passTime) / 60000
        basic.show_string(convert_to_text(showLeft).substr(04))
    basic.pause(1000)
    basic.clear_screen()
input.on_gesture(Gesture.SCREEN_UP, on_gesture_screen_up)
 
duration = 0
y = 0
x = 0
localy = 0
localx = 0
duration10 = 0
showLeft = 0
passTime = 0
duration1 = 0
endTime = 0
startTime = 0
timeLeft = 0
localx2 = 0
localy2 = 0
startTime = 0
endTime = 0
duration1 = 0
passTime = 0
showLeft = 0
duration10 = 0
basic.show_icon(IconNames.HAPPY)
basic.pause(500)
basic.clear_screen()
 
def on_forever():
    global endTime, passTime, duration
    basic.pause(10000)
    endTime = input.running_time()
    passTime = endTime - startTime
    duration = duration1 + duration10 * 10
    if passTime > duration * 60000:
        music.play_melody("G A B G A F G E "120)
basic.forever(on_forever)

加入VIP


如果你想系统学习编程涉及到的知识点,或者希望有人解答你在深度学习编程时遇到问题,加入VIP是个很不错的选择

立马 了解一下