I'm attempting to make a controller for a DSP processor that wants to see it's preset selection pins pulled low. FWIW, they are pulled up to 5V by 100k resistors.
My sketch uses one button to select between the 8 presets and another button to toggle between the selected preset and preset #1 which is configured as a bypass; no change to the audio. For bench testing I have LEDs connected to the outputs with a single 300 Ohm dropping resistor to 5V as only one output will be on at a time. The sketch works, but the voltage drop measured at the Nano outputs is much too high; 800mV and up. The drop also increases at each output in sequence by 350mV. The drop at the last output is 3.44V which puts it very close to not triggering the preset selection. Very strange.
Even stranger, using the exact same hardware and output configuration, but a different sketch, (pretty much a one button per preset selection) the voltage drop at each output is an identical 250mV.
So my question is, what's wrong with my sketch and what about it causes the odd voltage drops? Thank you in advance for your inputs/guidance.
// RPM_footswitch_x8_v2_F
// mchambers 6/19/2025
// for Nano
// a sequential counter that drives RPM preset control inputs, with bypass function (preset1)
// Sketch works but voltage drop on outputs is too high and increases from D9 to D2
// D9=0.8V, D8=1.13V, D7=1.45V, D6=1.81V, D5=2.27V, D4=2.66V, D3=3.04V, D2=3.44V
// Can the problem be saving the last bypass/select state? I don't think they need to be saved.
// Removing the last state save makes it almost impossible to get one preset increment; switch bounce
// Increasing the delay to 200 fixed the one increment issue
// The Vdrop is better: 1V to 3V range; but still terrible. Should be 0.25V or less
// Removing the "if xxxState == LOW" shifts the Vdrop: 0.8V to 3.5V = back to square one
// As the Select switch is pressed, the selected output has less voltage drop for an instant; WTF?
// Constants won't change:
const int bypass = A0;
const int select = A1;
const int preset1 = 9;
const int preset2 = 8;
const int preset3 = 7;
const int preset4 = 6;
const int preset5 = 5;
const int preset6 = 4;
const int preset7 = 3;
const int preset8 = 2;
byte presetPin[] = {2, 3, 4, 5, 6, 7, 8, 9};
// Variables will change:
int bypassPushCounter = 0; // counter for the number of Bypass button presses
int bypassState = HIGH; // current state of the Bypass button
int lastBypassState = HIGH; // previous state of the Bypass button
int selectPushCounter = 1; // counter for the number of Select button presses
int selectState = HIGH; // current state of the Select button
int lastSelectState = HIGH; // previous state of the Select button
int lastPreset = preset1;
void setup() {
pinMode(bypass, INPUT_PULLUP);
pinMode(select, INPUT_PULLUP);
pinMode(preset1, OUTPUT);
pinMode(preset2, OUTPUT);
pinMode(preset3, OUTPUT);
pinMode(preset4, OUTPUT);
pinMode(preset5, OUTPUT);
pinMode(preset6, OUTPUT);
pinMode(preset7, OUTPUT);
pinMode(preset8, OUTPUT);
}
void presetOffAll() {
for (int i = 0 ; i < sizeof(presetPin); i++) {
digitalWrite(presetPin[i], HIGH);
}
}
void loop() {
// read the Bypass switch:
bypassState = digitalRead(bypass);
if (bypassState != lastBypassState) {
if (bypassState == LOW) {
bypassPushCounter++;
}
// save the current Bypass state as the last state, for the next time through the loop
lastBypassState = bypassState;
// Delay a little bit to avoid bouncing
delay(200);
}
if (bypassPushCounter == 1) { // Bypass mode
digitalWrite(lastPreset, HIGH);
digitalWrite(preset1, LOW);
}
if (bypassPushCounter == 2) { // non Bypass mode
digitalWrite(preset1, HIGH);
digitalWrite(lastPreset, LOW);
}
if (bypassPushCounter > 2) {
bypassPushCounter = 1;
digitalWrite(lastPreset, HIGH);
digitalWrite(preset1, LOW);
}
// read the Select switch:
selectState = digitalRead(select);
if (selectState != lastSelectState) {
if (selectState == LOW) {
selectPushCounter++;
}
// save the current Select state as the last state, for the next time through the loop
lastSelectState = selectState;
// Delay a little bit to avoid bouncing
delay(200);
}
if (selectPushCounter == 1) {
presetOffAll();
digitalWrite(preset1, LOW);
lastPreset = preset1;
}
if (selectPushCounter == 2) {
presetOffAll();
digitalWrite(preset2, LOW);
lastPreset = preset2;
}
if (selectPushCounter == 3) {
presetOffAll();
digitalWrite(preset3, LOW);
lastPreset = preset3;
}
if (selectPushCounter == 4) {
presetOffAll();
digitalWrite(preset4, LOW);
lastPreset = preset4;
}
if (selectPushCounter == 5) {
presetOffAll();
digitalWrite(preset5, LOW);
lastPreset = preset5;
}
if (selectPushCounter == 6) {
presetOffAll();
digitalWrite(preset6, LOW);
lastPreset = preset6;
}
if (selectPushCounter == 7) {
presetOffAll();
digitalWrite(preset7, LOW);
lastPreset = preset7;
}
if (selectPushCounter == 8) {
presetOffAll();
digitalWrite(preset8, LOW);
lastPreset = preset8;
}
if (selectPushCounter > 8) {
presetOffAll();
selectPushCounter = 1;
digitalWrite(preset1, LOW);
lastPreset = preset1;
}
}