File tree 3 files changed +102
-0
lines changed
3 files changed +102
-0
lines changed Original file line number Diff line number Diff line change
1
+ ../ pew .py
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 audiobusio
2
+ import audiocore
3
+ import board
4
+ import busio
5
+ import digitalio
6
+ import displayio
7
+ import busdisplay
8
+ import fourwire
9
+ import keypad
10
+ import microcontroller
11
+ import os
12
+ import supervisor
13
+ import time
14
+
15
+
16
+ K_X = 0x10
17
+ K_O = 0x20
18
+ K_Z = 0x40
19
+ K_START = 0x40
20
+ K_SELECT = 0x80
21
+ K_DOWN = 0x08
22
+ K_LEFT = 0x04
23
+ K_RIGHT = 0x02
24
+ K_UP = 0x01
25
+
26
+
27
+ class _Buttons :
28
+ def __init__ (self ):
29
+ self .keys = keypad .Keys ((
30
+ board .BUTTON_UP ,
31
+ board .BUTTON_RIGHT ,
32
+ board .BUTTON_LEFT ,
33
+ board .BUTTON_DOWN ,
34
+ board .BUTTON_X ,
35
+ board .BUTTON_O ,
36
+ board .BUTTON_Z ,
37
+ ),
38
+ value_when_pressed = False ,
39
+ )
40
+ self .last_state = 0
41
+ self .event = keypad .Event (0 , False )
42
+ self .last_z_press = None
43
+
44
+ def get_pressed (self ):
45
+ buttons = self .last_state
46
+ events = self .keys .events
47
+ while events :
48
+ if events .get_into (self .event ):
49
+ bit = 1 << self .event .key_number
50
+ if self .event .pressed :
51
+ buttons |= bit
52
+ self .last_state |= bit
53
+ else :
54
+ self .last_state &= ~ bit
55
+ if buttons & K_Z :
56
+ now = time .monotonic ()
57
+ if self .last_z_press :
58
+ if now - self .last_z_press > 2 :
59
+ os .chdir ('/' )
60
+ supervisor .set_next_code_file (None )
61
+ supervisor .reload ()
62
+ else :
63
+ self .last_z_press = now
64
+ else :
65
+ self .last_z_press = None
66
+ return buttons
67
+
68
+
69
+ class _Audio :
70
+ last_audio = None
71
+
72
+ def __init__ (self ):
73
+ self .muted = True
74
+ self .buffer = bytearray (128 )
75
+ self .gain = digitalio .DigitalInOut (board .AUDIO_GAIN )
76
+ self .gain .switch_to_output (value = 0 )
77
+ self .audio = audiobusio .I2SOut (
78
+ board .AUDIO_BCLK ,
79
+ board .AUDIO_LRCLK ,
80
+ board .AUDIO_DATA ,
81
+ )
82
+
83
+ def play (self , audio_file , loop = False ):
84
+ if self .muted :
85
+ return
86
+ self .stop ()
87
+ wave = audiocore .WaveFile (audio_file , self .buffer )
88
+ self .audio .play (wave , loop = loop )
89
+
90
+ def stop (self ):
91
+ self .audio .stop ()
92
+
93
+ def mute (self , value = True ):
94
+ self .muted = value
95
+
96
+ board .DISPLAY .auto_refresh = False
97
+
98
+ display = board .DISPLAY
99
+ buttons = _Buttons ()
100
+ audio = _Audio ()
You can’t perform that action at this time.
0 commit comments