-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (60 loc) · 2.45 KB
/
main.py
File metadata and controls
69 lines (60 loc) · 2.45 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def circle(circleColor: number, milliseconds: number):
for led3 in range(60):
haloDisplay.set_zip_led_color(led3, circleColor)
haloDisplay.show()
basic.pause(milliseconds)
haloDisplay.set_zip_led_color(led3, kitronik_halo_hd.colors(ZipLedColors.BLACK))
# Press button A to decrease the brightness of the LED
def on_button_pressed_a():
global brightness
if brightness > 0:
brightness += -1
haloDisplay.set_brightness(brightness)
input.on_button_pressed(Button.A, on_button_pressed_a)
# Press button B to increase the brightness of the LED
def on_button_pressed_ab():
basic.show_string("Brightness:")
basic.show_number(brightness)
input.on_button_pressed(Button.AB, on_button_pressed_ab)
# Press button B to increase the brightness of the LED
def on_button_pressed_b():
global brightness
if brightness < 255:
brightness += 1
haloDisplay.set_brightness(brightness)
input.on_button_pressed(Button.B, on_button_pressed_b)
def on_gesture_shake():
basic.show_string("Hey!")
input.on_gesture(Gesture.SHAKE, on_gesture_shake)
# On the shake event, display the elapsed time in minutes.
def on_microbit_id_gesture_mes_device_shaken():
basic.show_number(minutes)
control.on_event(EventBusSource.MICROBIT_ID_GESTURE,
EventBusValue.MES_DEVICE_GESTURE_DEVICE_SHAKEN,
on_microbit_id_gesture_mes_device_shaken)
minutes = 0
haloDisplay: kitronik_halo_hd.ZIPHaloHd = None
colors: List[number] = []
brightness = 0
led2 = 0
brightness = 128
colors.append(kitronik_halo_hd.colors(ZipLedColors.RED))
colors.append(kitronik_halo_hd.colors(ZipLedColors.ORANGE))
colors.append(kitronik_halo_hd.colors(ZipLedColors.YELLOW))
colors.append(kitronik_halo_hd.colors(ZipLedColors.GREEN))
colors.append(kitronik_halo_hd.colors(ZipLedColors.BLUE))
colors.append(kitronik_halo_hd.colors(ZipLedColors.INDIGO))
colors.append(kitronik_halo_hd.colors(ZipLedColors.VIOLET))
colors.append(kitronik_halo_hd.colors(ZipLedColors.PURPLE))
colors.append(kitronik_halo_hd.colors(ZipLedColors.WHITE))
haloDisplay = kitronik_halo_hd.create_zip_halo_display(60)
minutes = 0
haloDisplay.set_brightness(brightness)
haloDisplay.clear()
while True:
for color in colors:
circle(color, 1000)
minutes += 1
# Simulate the shake event so that the micro:bit displays the elapsed time in minutes.
control.raise_event(EventBusSource.MICROBIT_ID_GESTURE,
EventBusValue.MES_DEVICE_GESTURE_DEVICE_SHAKEN)