-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
145 lines (126 loc) · 4.21 KB
/
code.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import time
import board
import digitalio
import usb_midi
import adafruit_midi
import neopixel
from adafruit_midi.note_on import NoteOn
from adafruit_midi.note_off import NoteOff
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
print("Default output MIDI channel:", midi.out_channel + 1)
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, pixel_order=neopixel.RGB) # onboard neopixel
pixel.brightness = 1
pixel.fill((5,0,0))
# A BUTTON
button_pinA = board.GP6
buttonA = digitalio.DigitalInOut(button_pinA)
buttonA.direction = digitalio.Direction.INPUT
buttonA.pull = digitalio.Pull.UP
buttonA_pressed = False
# B BUTTON
button_pinB = board.GP2
buttonB = digitalio.DigitalInOut(button_pinB)
buttonB.direction = digitalio.Direction.INPUT
buttonB.pull = digitalio.Pull.UP
buttonB_pressed = False
# C BUTTON
button_pinC = board.GP0
buttonC = digitalio.DigitalInOut(button_pinC)
buttonC.direction = digitalio.Direction.INPUT
buttonC.pull = digitalio.Pull.UP
buttonC_pressed = False
# PREV BUTTON
button_pinPREV = board.GP5
buttonPREV = digitalio.DigitalInOut(button_pinPREV)
buttonPREV.direction = digitalio.Direction.INPUT
buttonPREV.pull = digitalio.Pull.UP
buttonPREV_pressed = False
# STOP BUTTON
button_pinSTOP = board.GP3
buttonSTOP = digitalio.DigitalInOut(button_pinSTOP)
buttonSTOP.direction = digitalio.Direction.INPUT
buttonSTOP.pull = digitalio.Pull.UP
buttonSTOP_pressed = False
# NEXT BUTTON
button_pinNEXT = board.GP1
buttonNEXT = digitalio.DigitalInOut(button_pinNEXT)
buttonNEXT.direction = digitalio.Direction.INPUT
buttonNEXT.pull = digitalio.Pull.UP
buttonNEXT_pressed = False
# GO BUTTON
button_pinGO = board.GP4
buttonGO = digitalio.DigitalInOut(button_pinGO)
buttonGO.direction = digitalio.Direction.INPUT
buttonGO.pull = digitalio.Pull.UP
buttonGO_pressed = False
while True:
if not buttonA.value and not buttonA_pressed:
midi.send(NoteOn(44, 120))
print("A pressed")
buttonA_pressed = True
pixel.fill((0,0,255))
elif buttonA.value and buttonA_pressed:
midi.send(NoteOff(44, 120))
print("A released")
buttonA_pressed = False
pixel.fill((0,0,0))
if not buttonB.value and not buttonB_pressed:
midi.send(NoteOn(45, 120))
print("B pressed")
buttonB_pressed = True
pixel.fill((0,0,255))
elif buttonB.value and buttonB_pressed:
midi.send(NoteOff(45, 120))
print("B released")
buttonB_pressed = False
pixel.fill((0,0,0))
if not buttonC.value and not buttonC_pressed:
midi.send(NoteOn(46, 120))
print("C pressed")
buttonC_pressed = True
pixel.fill((0,0,255))
elif buttonC.value and buttonC_pressed:
midi.send(NoteOff(46, 120))
print("C released")
buttonC_pressed = False
pixel.fill((0,0,0))
if not buttonPREV.value and not buttonPREV_pressed:
midi.send(NoteOn(47, 120))
print("PREV pressed")
buttonPREV_pressed = True
pixel.fill((255,100,0))
elif buttonPREV.value and buttonPREV_pressed:
midi.send(NoteOff(47, 120))
print("PREV released")
buttonPREV_pressed = False
pixel.fill((0,0,0))
if not buttonSTOP.value and not buttonSTOP_pressed:
midi.send(NoteOn(48, 120))
print("STOP pressed")
buttonSTOP_pressed = True
pixel.fill((255,0,0))
elif buttonSTOP.value and buttonSTOP_pressed:
midi.send(NoteOff(48, 120))
print("STOP released")
buttonSTOP_pressed = False
pixel.fill((0,0,0))
if not buttonNEXT.value and not buttonNEXT_pressed:
midi.send(NoteOn(49, 120))
print("NEXT pressed")
buttonNEXT_pressed = True
pixel.fill((255,100,0))
elif buttonNEXT.value and buttonNEXT_pressed:
midi.send(NoteOff(49, 120))
print("NEXT released")
buttonNEXT_pressed = False
pixel.fill((0,0,0))
if not buttonGO.value and not buttonGO_pressed:
midi.send(NoteOn(50, 120))
print("GO pressed")
buttonGO_pressed = True
pixel.fill((0,255,0))
elif buttonGO.value and buttonGO_pressed:
midi.send(NoteOff(50, 120))
print("GO released")
buttonGO_pressed = False
pixel.fill((0,0,0))