Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bounce.h>
- boolean debugging=false;
- int midiChannel=3;
- int buttons[16]= {
- 26, 22, 5, 27,
- 25, 21, 2, 0,
- 24, 20, 7, 3,
- 23, 19, 9, 4
- };
- int leds[16] = {
- 18,41,15,10,
- 38,42,11,12,
- 39,43,16,13,
- 40,44,17,14
- };
- // variables to store values
- Bounce *buttonState[16];
- // the setup routine runs once when you press reset:
- void setup() {
- //arcade buttons
- for (int i=0;i<16;i++) {
- pinMode(buttons[i], INPUT_PULLUP);
- buttonState[i]= new Bounce(buttons[i], 5);
- pinMode(leds[i], OUTPUT);
- }
- }
- // the loop routine runs over and over again forever:
- void loop() {
- //read buttons
- for (int i=0;i<16;i++) {
- if (buttonState[i]->update()) {//state changed
- if (buttonState[i]->read()==LOW) {//is pressed
- midiNoteOnOff(true, i+26*16 + 4);
- digitalWrite(leds[i], HIGH);
- }
- else {
- midiNoteOnOff(false, i+26*16 + 4);
- digitalWrite(leds[i], LOW);
- }
- }
- }//end loop
- }
- // function to handle noteon outgoing messages
- void midiNoteOnOff(boolean s, int n) {
- if (s) {
- if (debugging) {//debbuging enabled
- Serial.print("Button ");
- Serial.print(n);
- Serial.println(" pressed.");
- }
- else {
- usbMIDI.sendNoteOn(n, 127, midiChannel);
- }
- }
- else {
- if (debugging) {//debbuging enabled
- Serial.print("Button ");
- Serial.print(n);
- Serial.println(" released.");
- }
- else {
- usbMIDI.sendNoteOff(n, 0, midiChannel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement