File tree Expand file tree Collapse file tree 2 files changed +87
-0
lines changed Expand file tree Collapse file tree 2 files changed +87
-0
lines changed Original file line number Diff line number Diff line change
1
+ ../ stage .py
Original file line number Diff line number Diff line change
1
+ import board
2
+ import analogio
3
+ import stage
4
+ import keypad
5
+ import audiocore
6
+ import audiopwmio
7
+ import time
8
+ import supervisor
9
+
10
+
11
+ K_O = 0x01 # A
12
+ K_X = 0x02 # B
13
+ K_SELECT = 0x04 # X
14
+ K_START = 0x08 # Y
15
+ K_Z = 0x08 # Y
16
+ K_DOWN = 0x10
17
+ K_LEFT = 0x20
18
+ K_RIGHT = 0x40
19
+ K_UP = 0x80
20
+
21
+
22
+ class _Buttons :
23
+ def __init__ (self ):
24
+ self .keys = keypad .Keys ((
25
+ board .SW_A ,
26
+ board .SW_B ,
27
+ board .SW_X ,
28
+ board .SW_Y ,
29
+ board .SW_DOWN ,
30
+ board .SW_LEFT ,
31
+ board .SW_RIGHT ,
32
+ board .SW_UP
33
+ ), value_when_pressed = False , pull = True , interval = 0.05 )
34
+ self .last_state = 0
35
+ self .event = keypad .Event (0 , False )
36
+ self .last_z_press = None
37
+
38
+ def get_pressed (self ):
39
+ buttons = self .last_state
40
+ events = self .keys .events
41
+ while events :
42
+ if events .get_into (self .event ):
43
+ bit = 1 << self .event .key_number
44
+ if self .event .pressed :
45
+ buttons |= bit
46
+ self .last_state |= bit
47
+ else :
48
+ self .last_state &= ~ bit
49
+ if buttons & K_Z :
50
+ now = time .monotonic ()
51
+ if self .last_z_press :
52
+ if now - self .last_z_press > 2 :
53
+ supervisor .set_next_code_file (None )
54
+ supervisor .reload ()
55
+ else :
56
+ self .last_z_press = now
57
+ else :
58
+ self .last_z_press = None
59
+ return buttons
60
+
61
+ class _Audio :
62
+ last_audio = None
63
+
64
+ def __init__ (self ):
65
+ self .muted = True
66
+ self .buffer = bytearray (128 )
67
+ self .audio = audiopwmio .PWMAudioOut (board .AUDIO )
68
+
69
+ def play (self , audio_file , loop = False ):
70
+ if self .muted :
71
+ return
72
+ self .stop ()
73
+ wave = audiocore .WaveFile (audio_file , self .buffer )
74
+ self .audio .play (wave , loop = loop )
75
+
76
+ def stop (self ):
77
+ self .audio .stop ()
78
+
79
+ def mute (self , value = True ):
80
+ self .muted = value
81
+
82
+
83
+ audio = _Audio ()
84
+ display = board .DISPLAY
85
+ buttons = _Buttons ()
86
+ battery = analogio .AnalogIn (board .BAT_SENSE )
You can’t perform that action at this time.
0 commit comments