Indicator lights for push button

Thread Starter

seayaker

Joined Jan 27, 2009
54
This is a simplified sketch for an Arduino midi controller, I want to add indicator lights to the buttons so that they turn on/off with the note on/off commands I tried adding pinMode(13, OUTPUT); to the setup, and then digitalWrite(13, HIGH); and digitalWrite(13, LOW); to the loop but the lights still don't work any suggestions?

#include <Bounce.h>

const int channel = 1;

Bounce button0 = Bounce(0, 5);

void setup() {

pinMode(0, INPUT_PULLUP);

}

void loop() {

button0.update();


if (button0.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4
}


if (button0.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel); // 60 = C4
}

while (usbMIDI.read()) {

}
}
 

Thread Starter

seayaker

Joined Jan 27, 2009
54
Only 1 button is connected to pin 0 with the led connected to pin 13, I just need to adjust the code to turn the led on/off with the note on/off
 

danadak

Joined Mar 10, 2018
3,577
Show the code where you did the writes to the LED pin.

Is the LED polarity correct in circuit ? Circuit looks like -

Drive high to turn on -




Regards, Dana.
 

Thread Starter

seayaker

Joined Jan 27, 2009
54
Show the code where you did the writes to the LED pin.

Is the LED polarity correct in circuit ? Circuit looks like -

Drive high to turn on -




Regards, Dana.
Show the code where you did the writes to the LED pin.

Is the LED polarity correct in circuit ? Circuit looks like -

Drive high to turn on -




Regards, Dana.
Show the code where you did the writes to the LED pin.

Is the LED polarity correct in circuit ? Circuit looks like -

Drive high to turn on -




Regards, Dana.
This is how I was told to do it but it only lights the led when I hold the button down I need it to turn on/off with the note commands. If you press the button while it's off it will turn it on, if you press it while it's on it will turn it off. I'm using a teensy 3.2 which uses 3.3v so no resistor is needed for the led.


#include <Bounce.h>

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


Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);
Bounce button2 = Bounce(2, 5);


void setup() {

pinMode(13, OUTPUT);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);

}

void loop() {

button0.update();
button1.update();
button2.update();


if (button0.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4
digitalWrite(13, HIGH);
}
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4
}


if (button0.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel);// 60 = C4
digitalWrite(13, LOW);
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(62, 0, channel); // 62 = D4
}

while (usbMIDI.read()) {
}
}
Show the code where you did the writes to the LED pin.

Is the LED polarity correct in circuit ? Circuit looks like -

Drive high to turn on -




Regards, Dana.
Show the code where you did the writes to the LED pin.

Is the LED polarity correct in circuit ? Circuit looks like -

Drive high to turn on -




Regards, Dana.

#include <Bounce.h>

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


Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);
Bounce button2 = Bounce(2, 5);


void setup() {

pinMode(13, OUTPUT);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);

}

void loop() {

button0.update();
button1.update();
button2.update();


if (button0.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4
digitalWrite(13, HIGH);
}
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4
}


if (button0.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel);// 60 = C4
digitalWrite(13, LOW);
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(62, 0, channel); // 62 = D4
}

while (usbMIDI.read()) {
}
}
 

Attachments

danadak

Joined Mar 10, 2018
3,577
Try a test case where you simply flash the LED,

Code:
int ledPin = 13;                 // LED connected to digital pin 13

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}
Regards, Dana.
 

Wolframore

Joined Jan 21, 2019
1,253
Did you declare the buttons? You have code all over the place. I’m surprised it compiled.

Add in setup( )

int button0 = 0;

Etc...
 
Top