makecode-python定时器,1小时
def on_button_pressed_a():
global duration1, localy1, localx1
duration1 += 1
if duration1 > 10:
basic.clear_screen()
duration1 = 0
return
localy1 = Math.floor((duration1 - 1) / 5)
localx1 = (duration1 - 1) % 5
led.plot_brightness(localx1, localy1, 255)
input.on_button_pressed(Button.A, on_button_pressed_a)
def on_gesture_shake():
global duration15, localx3, localy3
duration15 += 1
if duration15 > 5:
basic.clear_screen()
duration15 = 0
localx3 = duration15 - 1
localy3 = 3
led.plot(localx3, localy3)
input.on_gesture(Gesture.SHAKE, on_gesture_shake)
def on_button_pressed_ab():
global duration10, localx2, localy2
duration10 += 1
if duration10 > 5:
basic.clear_screen()
duration10 = 0
return
localx2 = duration10 - 1
localy2 = 4
led.plot_brightness(localx2, localy2, 255)
input.on_button_pressed(Button.AB, on_button_pressed_ab)
def on_button_pressed_b():
global beginTime
beginTime = 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 - beginTime
duration = duration1 + duration10 * 10
if passTime <= duration * 60000:
showLeft = (duration * 60000 - passTime) / 60000
basic.show_string(convert_to_text(showLeft).substr(0, 4))
input.on_gesture(Gesture.SCREEN_UP, on_gesture_screen_up)
showLeft = 0
duration = 0
passTime = 0
endTime = 0
beginTime = 0
localy2 = 0
localx2 = 0
duration10 = 0
localy3 = 0
localx3 = 0
duration15 = 0
localx1 = 0
localy1 = 0
duration1 = 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 - beginTime
duration = duration1 + duration10 * 10
if passTime > duration * 60000:
music.play_melody("G A B G A F G E ", 120)
basic.forever(on_forever)