LED on 13 with Teensy LC barely lights up at all with one of my switches but...

Status
Not open for further replies.

IPFreely

Member
I'm just doing basic momentary switching with two tactile switches, nothing fancy. Originally I was using a dual membrane style switch for it and I had everything functioning properly. The problem is, in the final enclosure they don't sit right and are too bendy so I am hoping to use a small pcb instead with two tactile switches on it.

The issue is this: Using two momentary tactile switches causes onboard pin 13 LED to be very dim with pin 15 switch and the other switch is bright (pin 18) when I trigger them (they are usually off). With the dual membrane however, the LED functions normally on both. (currently there are only two switches) I have tried reversing switches, wires, pins, pretty much everything I can think of to test and it keeps doing it regardless of configuration. BUT when I put the membrane back on it works fine. I have seen a slight improvement on the dim LED by swapping to a different pin on the microcontroller but they still won't even out. MIDI command changes seem to function fine, however. I don't really need LEDs but I feel like it indicates some issue that I'm not accounting for. I have a feeling someone here may have encountered this at some point and might know what to check for it. Is there some weird grounding consideration on the unused side of the switch or something? I know the membrane provides some extra resistance where the tactile has none but adding a similar resistor seems to not change things. I am using the pullup scheme so I shouldn't need extra resistors. I don't understand the issue but I'm sure it's something I'm overlooking. Anyone had this isuue?? Ideas? (note: I have swapped in all new wires and switches and get the same result.)

Thanks!

Code:

#include <ResponsiveAnalogRead.h>


const int channel = 1;

const int LEDA = 13;
const int LEDB = 13;
const int buttonPinA = 15;
const int buttonPinB = 18;
int buttonStateA = 0;
int buttonStateB = 0;
int lastButtonStateA = 0;
int lastButtonStateB = 0;
int toggleStateA = 0;
int toggleStateB = 0;
// const int controllerA0 = 10; // 10 = pan position
const int controllerA9 = 11; // 11 = volume/expression

void setup () {
pinMode (buttonPinA, INPUT_PULLUP);
pinMode (LEDA, OUTPUT);
pinMode (buttonPinB, INPUT_PULLUP);
pinMode (LEDB, OUTPUT);
}

// int previousA0 = -1;
int previousA9 = -1;

elapsedMillis msec = 0;

void loop () {
buttonStateA = digitalRead (buttonPinA);
buttonStateB = digitalRead (buttonPinB);

if (msec >= 20) {
msec = 0;
// int n0 = analogRead(A0) / 8;
int n1 = analogRead(A9) / 8;

// check whether the input is LOW (button pressed)
if (buttonStateA == LOW){
digitalWrite (LEDA,HIGH); // turn LED on
}else{
digitalWrite (LEDA,LOW);
}

if (buttonStateA != lastButtonStateA && buttonStateA == 1 && toggleStateA == 0) {
usbMIDI.sendControlChange (1, 127, 1);
delay (50);
toggleStateA = 1;
}
else if (buttonStateA != lastButtonStateA && buttonStateA == 1 && toggleStateA == 1) {
usbMIDI.sendControlChange (1, 0, 1);
delay (50);
toggleStateA = 0;
}
lastButtonStateA = buttonStateA;

// check whether the input is LOW (button pressed)
if (buttonStateB == LOW){
digitalWrite (LEDB,HIGH); // turn LED on
}else{
digitalWrite (LEDB,LOW);
}

if (buttonStateB != lastButtonStateB && buttonStateB == 1 && toggleStateB == 0) {
usbMIDI.sendControlChange (2, 127, 1);
delay (50);
toggleStateB = 1;
}
else if (buttonStateB != lastButtonStateB && buttonStateB == 1 && toggleStateB == 1) {
usbMIDI.sendControlChange (2, 0, 1);
delay (50);
toggleStateB = 0;
}
lastButtonStateB = buttonStateB;

// if (n0 != previousA0) {
// usbMIDI.sendControlChange(controllerA0, n0, channel);
// previousA0 = n0;
// }
if (n1 != previousA9) {
usbMIDI.sendControlChange(controllerA9, n1, channel);
previousA9 = n1;
}
}
while (usbMIDI.read()) {
} // MIDI Controllers should discard incoming MIDI messages.
}
 
Status
Not open for further replies.
Back
Top