Pages: [1]   Go Down
Author Topic: programming my teensyduino arcade buttonbox  (Read 933 times)
0 Members and 1 Guest are viewing this topic.
Gouda, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 7
wat een ander niet wil dat geschiedt, doe dat snel voordat ie het ziet
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey there!
I've just finished my 20x pushbutton arcadebox http://flic.kr/p/btJKcq And i've done some programming with teensyduino using the midi-protocol with the inside push-resistor, so far so good, but of the 20 buttons only 16 are working As a absolute beginner i don't have a clue what i'm doing to be honest. I do have some experience converting raw hid information to midi events trough junxion. But i prefer to have 16 buttons as note on/off messages and the other 4 to recall 1 of 4 banks of 16. Without the hassle of using other software.... Is there someone who can help me out? Again, i'm an absolute beginner...
Logged

dj, producer, vj, painter, manic creative individual

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 497
Posts: 19051
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Show your code?
Logged


Gouda, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 7
wat een ander niet wil dat geschiedt, doe dat snel voordat ie het ziet
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, here's what i got so far, the buttons on pin 0,22,21 and 37 are not working like the others, but as said, i want to get them to work as 4 bank recalls of the other 16 buttons, i really don't have any programming experience so i'm stuck....



#include <MIDI.h>

/* Buttons to USB MIDI Example

   You must select MIDI from the "Tools > USB Type" menu

   This example code is in the public domain.
*/

#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 13;

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button1 = Bounce(1, 4);  // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 4);  // which is appropriate for good
Bounce button3 = Bounce(3, 4);  // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 4);
Bounce button5 = Bounce(5, 4);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 4);  // to rapid touch, you can
Bounce button7 = Bounce(7, 4);  // increase this time.
Bounce button8 = Bounce(8, 4);
Bounce button9 = Bounce(9, 4);
Bounce button10 = Bounce(10, 4);
Bounce button11 = Bounce(11, 4);
Bounce button12 = Bounce(12, 4);
Bounce button13 = Bounce(13, 4);
Bounce button14 = Bounce(14, 4);
Bounce button15 = Bounce(15, 4);
Bounce button16 = Bounce(16, 4);
Bounce button17 = Bounce(17, 4);
Bounce button18 = Bounce(18, 4);
Bounce button19 = Bounce(19, 4);
Bounce button20 = Bounce(20, 4);


void setup() {
  // Configure the pins for input mode with pullup resistors.
  // The pushbuttons connect from each pin to ground.  When
  // the button is pressed, the pin reads LOW because the button
  // shorts it to ground.  When released, the pin reads HIGH
  // because the pullup resistor connects to +5 volts inside
  // the chip.  LOW for "on", and HIGH for "off" may seem
  // backwards, but using the on-chip pullup resistors is very
  // convenient.  The scheme is called "active low", and it's
  // very commonly used in electronics... so much that the chip
  // has built-in pullup resistors!
  pinMode(37, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(22, INPUT_PULLUP);
  pinMode(21, INPUT_PULLUP);
  pinMode(20, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
}

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();
  button10.update();
  button11.update();
  button12.update();
  button13.update();
  button14.update();
  button15.update();
  button16.update();
  button17.update();
  button18.update();
  button19.update();
  button20.update();

  // Check each button for "falling" edge.
  // Send a MIDI Note On message when each button presses
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
 
  if (button1.fallingEdge()) {
    usbMIDI.sendNoteOn(27, 99, channel);  // 27 = D#1
  }
  if (button2.fallingEdge()) {
    usbMIDI.sendNoteOn(28, 99, channel);  // 28 = E1
  }
  if (button3.fallingEdge()) {
    usbMIDI.sendNoteOn(29, 99, channel);  // 29 = F1
  }
  if (button4.fallingEdge()) {
    usbMIDI.sendNoteOn(30, 99, channel);  // 30 = F#1
  }
  if (button5.fallingEdge()) {
    usbMIDI.sendNoteOn(31, 99, channel);  // 31 = G1
  }
  if (button6.fallingEdge()) {
    usbMIDI.sendNoteOn(32, 99, channel);  // 32 = G#1
  }
  if (button7.fallingEdge()) {
    usbMIDI.sendNoteOn(33, 99, channel);  // 33 = A1
  }
  if (button8.fallingEdge()) {
    usbMIDI.sendNoteOn(34, 99, channel);  // 34 = A#1
  }
  if (button9.fallingEdge()) {
    usbMIDI.sendNoteOn(35, 99, channel);  // 35 = B1
  }
  if (button10.fallingEdge()) {
    usbMIDI.sendNoteOn(36, 99, channel);  // 36 = C2
  }
  if (button11.fallingEdge()) {
    usbMIDI.sendNoteOn(37, 99, channel);  // 37 = C#2
  }
  if (button12.fallingEdge()) {
    usbMIDI.sendNoteOn(38, 99, channel);  // 38 = D2
  }
  if (button13.fallingEdge()) {
    usbMIDI.sendNoteOn(39, 99, channel);  // 39 = D#2
  }
  if (button14.fallingEdge()) {
    usbMIDI.sendNoteOn(40, 99, channel);  // 40 = E2
  }
  if (button15.fallingEdge()) {
    usbMIDI.sendNoteOn(41, 99, channel);  // 41 = F2
  }
  if (button16.fallingEdge()) {
    usbMIDI.sendNoteOn(42, 99, channel);  // 42 = F#2
  }
  if (button17.fallingEdge()) {
    usbMIDI.sendNoteOn(43, 99, channel);  // 43 = G2
  }
  if (button18.fallingEdge()) {
    usbMIDI.sendNoteOn(44, 99, channel);  // 44 = G#2
  }
  if (button19.fallingEdge()) {
    usbMIDI.sendNoteOn(45, 99, channel);  // 45 = A2
  }
  if (button20.fallingEdge()) {
    usbMIDI.sendNoteOn(46, 99, channel);  // 46 = A#2
  }
  // Check each button for "rising" edge
  // Send a MIDI Note Off message when each button releases
  // For many types of projects, you only care when the button
  // is pressed and the release isn't needed.
  // rising = low (pressed - button connects pin to ground)
  //          to high (not pressed - voltage from pullup resistor)
  if (button1.risingEdge()) {
    usbMIDI.sendNoteOff(27, 0, channel);  // 27 = D#1
  }
  if (button2.risingEdge()) {
    usbMIDI.sendNoteOn(28, 0, channel);  // 28 = E1
  }
  if (button3.risingEdge()) {
    usbMIDI.sendNoteOn(29, 0, channel);  // 29 = F1
  }
  if (button4.risingEdge()) {
    usbMIDI.sendNoteOn(30, 0, channel);  // 30 = F#1
  }
  if (button5.risingEdge()) {
    usbMIDI.sendNoteOn(31, 0, channel);  // 31 = G1
  }
  if (button6.risingEdge()) {
    usbMIDI.sendNoteOn(32, 0, channel);  // 32 = G#1
  }
  if (button7.risingEdge()) {
    usbMIDI.sendNoteOn(33, 0, channel);  // 33 = A1
  }
  if (button8.risingEdge()) {
    usbMIDI.sendNoteOn(34, 0, channel);  // 34 = A#1
  }
  if (button9.risingEdge()) {
    usbMIDI.sendNoteOn(35, 0, channel);  // 35 = B1
  }
  if (button10.risingEdge()) {
    usbMIDI.sendNoteOn(36, 0, channel);  // 36 = C2
  }
  if (button11.risingEdge()) {
    usbMIDI.sendNoteOn(37, 0, channel);  // 37 = C#2
  }
  if (button12.risingEdge()) {
    usbMIDI.sendNoteOn(38, 0, channel);  // 38 = D2
  }
  if (button13.risingEdge()) {
    usbMIDI.sendNoteOn(39, 0, channel);  // 39 = D#2
  }
  if (button14.risingEdge()) {
    usbMIDI.sendNoteOn(40, 0, channel);  // 40 = E2
  }
  if (button15.risingEdge()) {
    usbMIDI.sendNoteOn(41, 0, channel);  // 41 = F2
  }
  if (button16.risingEdge()) {
    usbMIDI.sendNoteOn(42, 0, channel);  // 42 = F#2
  }
  if (button17.risingEdge()) {
    usbMIDI.sendNoteOn(43, 0, channel);  // 43 = G2
  }
  if (button18.risingEdge()) {
    usbMIDI.sendNoteOn(44, 0, channel);  // 44 = G#2
  }
  if (button19.risingEdge()) {
    usbMIDI.sendNoteOn(45, 0, channel);  // 45 = A2
  }
  if (button20.risingEdge()) {
    usbMIDI.sendNoteOn(46, 0, channel);  // 46 = A#2
  } 
 
}
Logged

dj, producer, vj, painter, manic creative individual

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 497
Posts: 19051
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Logged


Gouda, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 7
wat een ander niet wil dat geschiedt, doe dat snel voordat ie het ziet
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry for my late response, It's almost perfect. As said, i got a 4x5 button grid and only 16 buttons are working (sending midi note on/off messages) although 2 buttons are having some issues. They are sending out more then one message but i'm pretty sure this is a programming issue. My device would be perfect if i could use the other 4 buttons to recall one of 4 banks of 16 buttons. That's like having 4 drummachines in my setup....

Here's my code so far, it took me 3 days so a little help is more then welcome...

Code:
#include <MIDI.h>

/* Buttons to USB MIDI Example

   You must select MIDI from the "Tools > USB Type" menu

   This example code is in the public domain.
*/

#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 13;

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5);  // which is appropriate for good
Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5);  // to rapid touch, you can
Bounce button7 = Bounce(7, 5);  // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);
Bounce button12 = Bounce(12, 5);
Bounce button13 = Bounce(13, 5);
Bounce button14 = Bounce(14, 5);
Bounce button15 = Bounce(15, 5);
Bounce button16 = Bounce(16, 5);
Bounce button17 = Bounce(17, 5);
Bounce button18 = Bounce(18, 5);
Bounce button19 = Bounce(19, 5);
Bounce button20 = Bounce(20, 5);


void setup() {
  // Configure the pins for input mode with pullup resistors.
  // The pushbuttons connect from each pin to ground.  When
  // the button is pressed, the pin reads LOW because the button
  // shorts it to ground.  When released, the pin reads HIGH
  // because the pullup resistor connects to +5 volts inside
  // the chip.  LOW for "on", and HIGH for "off" may seem
  // backwards, but using the on-chip pullup resistors is very
  // convenient.  The scheme is called "active low", and it's
  // very commonly used in electronics... so much that the chip
  // has built-in pullup resistors!
  pinMode(37, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(22, INPUT_PULLUP);
  pinMode(21, INPUT_PULLUP);
  pinMode(20, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
}

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();
  button10.update();
  button11.update();
  button12.update();
  button13.update();
  button14.update();
  button15.update();
  button16.update();
  button17.update();
  button18.update();
  button19.update();
  button20.update();

  // Check each button for "falling" edge.
  // Send a MIDI Note On message when each button presses
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
 
  if (button1.fallingEdge()) {
    usbMIDI.sendNoteOn(51, 99, channel);  // 51 = D#3
  }
  if (button2.fallingEdge()) {
    usbMIDI.sendNoteOn(54, 99, channel);  // 54 = F#3
  }
  if (button3.fallingEdge()) {
    usbMIDI.sendNoteOn(58, 99, channel);  // 58 = A#3
  }
  if (button4.fallingEdge()) {
    usbMIDI.sendNoteOn(50, 99, channel);  // 50 = D3
  }
  if (button5.fallingEdge()) {
    usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
  }
  if (button6.fallingEdge()) {
    usbMIDI.sendNoteOn(32, 99, channel);  // 32 = G#1
  }
  if (button7.fallingEdge()) {
    usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
  }
  if (button8.fallingEdge()) {
    usbMIDI.sendNoteOn(57, 99, channel);  // 57 = A3
  }
  if (button9.fallingEdge()) {
    usbMIDI.sendNoteOn(53, 99, channel);  // 53 = F3
  }
  if (button10.fallingEdge()) {
    usbMIDI.sendNoteOn(49, 99, channel);  // 49 = C#3
  }
  if (button11.fallingEdge()) {
    usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
  }
  if (button12.fallingEdge()) {
    usbMIDI.sendNoteOn(56, 99, channel);  // 56 = G#3
  }
  if (button13.fallingEdge()) {
    usbMIDI.sendNoteOn(52, 99, channel);  // 52 = E3
  }
  if (button14.fallingEdge()) {
    usbMIDI.sendNoteOn(40, 99, channel);  // 40 = E2
  }
  if (button15.fallingEdge()) {
    usbMIDI.sendNoteOn(41, 99, channel);  // 41 = F2
  }
  if (button16.fallingEdge()) {
    usbMIDI.sendNoteOn(42, 99, channel);  // 42 = F#2
  }
  if (button17.fallingEdge()) {
    usbMIDI.sendNoteOn(48, 99, channel);  // 48 = C3
  }
  if (button18.fallingEdge()) {
    usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
  }
  if (button19.fallingEdge()) {
    usbMIDI.sendNoteOn(59, 99, channel);  // 59 = B3
  }
  if (button20.fallingEdge()) {
    usbMIDI.sendNoteOn(55, 99, channel);  // 55 = G3
  }
  // Check each button for "rising" edge
  // Send a MIDI Note Off message when each button releases
  // For many types of projects, you only care when the button
  // is pressed and the release isn't needed.
  // rising = low (pressed - button connects pin to ground)
  //          to high (not pressed - voltage from pullup resistor)
  if (button1.risingEdge()) {
    usbMIDI.sendNoteOff(51, 0, channel);  // 51 = D#3
  }
  if (button2.risingEdge()) {
    usbMIDI.sendNoteOff(54, 0, channel);  // 54 = F#3
  }
  if (button3.risingEdge()) {
    usbMIDI.sendNoteOff(58, 0, channel);  // 58 = A#3
  }
  if (button4.risingEdge()) {
    usbMIDI.sendNoteOff(50, 0, channel);  // 50 = D3
  }
  if (button5.risingEdge()) {
    usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
  }
  if (button6.risingEdge()) {
    usbMIDI.sendNoteOff(32, 0, channel);  // 32 = G#1
  }
  if (button7.risingEdge()) {
    usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
  }
  if (button8.risingEdge()) {
    usbMIDI.sendNoteOff(57, 0, channel);  // 57 = A3
  }
  if (button9.risingEdge()) {
    usbMIDI.sendNoteOff(53, 0, channel);  // 53 = F3
  }
  if (button10.risingEdge()) {
    usbMIDI.sendNoteOff(49, 0, channel);  // 49 = C#3
  }
  if (button11.risingEdge()) {
    usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
  }
  if (button12.risingEdge()) {
    usbMIDI.sendNoteOff(56, 0, channel);  // 56 = G#3
  }
  if (button13.risingEdge()) {
    usbMIDI.sendNoteOff(52, 0, channel);  // 52 = E3
  }
  if (button14.risingEdge()) {
    usbMIDI.sendNoteOff(40, 0, channel);  // 40 = E2
  }
  if (button15.risingEdge()) {
    usbMIDI.sendNoteOff(41, 0, channel);  // 41 = F2
  }
  if (button16.risingEdge()) {
    usbMIDI.sendNoteOff(42, 0, channel);  // 42 = F#2
  }
  if (button17.risingEdge()) {
    usbMIDI.sendNoteOff(48, 0, channel);  // 48 = C3
  }
  if (button18.risingEdge()) {
    usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
  }
  if (button19.risingEdge()) {
    usbMIDI.sendNoteOff(59, 0, channel);  // 59 = B3
  }
  if (button20.risingEdge()) {
    usbMIDI.sendNoteOff(55, 0, channel);  // 55 = G3
  }
 
}
Logged

dj, producer, vj, painter, manic creative individual

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 497
Posts: 19051
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't help thinking as I look at that code that an array, and a loop, would make everything much easier.
Logged


Gouda, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 7
wat een ander niet wil dat geschiedt, doe dat snel voordat ie het ziet
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for your response, but an array and a loop don't say anything to me, i'm an absolute beginner and have zero experience in programming. Any idea where to find info on this?
Logged

dj, producer, vj, painter, manic creative individual

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 497
Posts: 19051
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And i've done some programming ...

...

Quote
i'm an absolute beginner and have zero experience in programming

You lost me there.
Logged


Gouda, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 7
wat een ander niet wil dat geschiedt, doe dat snel voordat ie het ziet
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

haha, i understand you're confused but most of the code is just simply copy/pasted, all i changed are the midi note numbers so that they correspond with the grid in a ableton live drumrack. But to be honest, i don't really have a clue what i'm doing.
Logged

dj, producer, vj, painter, manic creative individual

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 
Quote
although 2 buttons are having some issues

 Add serial print statements to each of your if statements to show if your button was shown as being pushed.
 
Code:
if (buttonX.fallingEdge()) {

 
Code:
Serial.print("button x has been pressed ");
Logged


Pages: [1]   Go Up
Jump to: