Chris Dragptta
Member
Added two buttons and a pot.
Okay, next step is to add two buttons, program one of them to decrease the midi note value (defined as an integer, number 61, which corresponds to the note c# which is the note the wind instrument plays when no buttons are pushed. The two buttons I've added decrement this number by either 1 or 2. ButtonA is linked to digital pin 6, and ButtonB is linked to digital pin 9. The code compiles and acts like the buttons are always being pressed. That is, its starts on the note C# (midi note number 61), and decrements by three each time, because it thinks for some reason the buttons are being pressed. I read on an arduino page that the buttons need pullup resistors. I wasn't sure which ones to use, but read further that the code could emulate a resistor if you use "PULLUP" in the code. I also verified that the button is wired correctly, that is never straight across but diagonally. One side of button is linked to AGND, and the other , either 6 or 9.
So why does the teensy always return a pin state of HIGH whether button is pressed or not?
Here are some pictures:
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
// constants won't change.
const int channel =1; // They're used here to set pin numbers:
const int buttonPinA = 6; // the number of the pushbutton pin
const int buttonPinB = 9; // the number of the pushbutton pin
// variables will change:
int buttonStateA = 0; // variable for reading the pushbuttonA status
int buttonStateB = 0; // variable for reading the pushbuttonB status
int note = 61; //C# (no fingers pressed.)
void setup() {
MIDI.begin(MIDI_CHANNEL_OFF);
pinMode(buttonPinA, INPUT_PULLUP); // initialize the pushbutton pins as an inputs:
pinMode(buttonPinB, INPUT_PULLUP);
}
void loop()
{
buttonStateA = digitalRead(buttonPinA);
if (buttonStateA == HIGH)
{ note = note -1; }
buttonStateB = digitalRead(buttonPinB);
if (buttonStateB == HIGH)
{note = note -2; }
MIDI.sendNoteOn(note, 100, channel);
delay(200);
MIDI.sendNoteOff(note, 100, channel);
delay(1000);
}
I changed them and it's working but like one of those optical illusions that looks like an old woman and a young woman, I"m only seeing it one way. So thanks! I'm sure I'll get into trouble again very quickly.
Okay, next step is to add two buttons, program one of them to decrease the midi note value (defined as an integer, number 61, which corresponds to the note c# which is the note the wind instrument plays when no buttons are pushed. The two buttons I've added decrement this number by either 1 or 2. ButtonA is linked to digital pin 6, and ButtonB is linked to digital pin 9. The code compiles and acts like the buttons are always being pressed. That is, its starts on the note C# (midi note number 61), and decrements by three each time, because it thinks for some reason the buttons are being pressed. I read on an arduino page that the buttons need pullup resistors. I wasn't sure which ones to use, but read further that the code could emulate a resistor if you use "PULLUP" in the code. I also verified that the button is wired correctly, that is never straight across but diagonally. One side of button is linked to AGND, and the other , either 6 or 9.
So why does the teensy always return a pin state of HIGH whether button is pressed or not?
Here are some pictures:
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
// constants won't change.
const int channel =1; // They're used here to set pin numbers:
const int buttonPinA = 6; // the number of the pushbutton pin
const int buttonPinB = 9; // the number of the pushbutton pin
// variables will change:
int buttonStateA = 0; // variable for reading the pushbuttonA status
int buttonStateB = 0; // variable for reading the pushbuttonB status
int note = 61; //C# (no fingers pressed.)
void setup() {
MIDI.begin(MIDI_CHANNEL_OFF);
pinMode(buttonPinA, INPUT_PULLUP); // initialize the pushbutton pins as an inputs:
pinMode(buttonPinB, INPUT_PULLUP);
}
void loop()
{
buttonStateA = digitalRead(buttonPinA);
if (buttonStateA == HIGH)
{ note = note -1; }
buttonStateB = digitalRead(buttonPinB);
if (buttonStateB == HIGH)
{note = note -2; }
MIDI.sendNoteOn(note, 100, channel);
delay(200);
MIDI.sendNoteOff(note, 100, channel);
delay(1000);
}
Attachments
Last edited: