I've written this code to function the following way;
Pot1 - controls led blink rate
Pot2 - controls either blink rate or digital pot
Pot3 - controls digital pot
A 3-position toggle determines whether pot 2 controls the blink rate or the digital pot (left or right), with the centre position (both pins HIGH) allowing them to be controlled by their respective pots with no effect.
The problem I have is when the toggle is in the left position allowing pot 2 to control the blink rate, pot 1 still has some influence causing an unsteady/glitching blink rate.
#include <DigiPotX9Cxxx.h>
DigiPot digiPot(2, 1, 19);
int pot1 = A3;
int pot2 = A0;
int pot3 = A4;
int leftToggle = 15;
int rightToggle = 14;
int led = 24;
unsigned long timeMuteChanged = millis();
unsigned long period;
boolean ledOn = false;
void setup() {
pinMode(leftToggle, INPUT_PULLUP);
pinMode(rightToggle, INPUT_PULLUP);
pinMode(led, OUTPUT);
}
void loop() {
int LT = digitalRead(leftToggle);
int RT = digitalRead(rightToggle);
int onVal1 = analogRead(pot1);
int offVal1 = analogRead(pot1);
int onVal2 = analogRead(pot2);
int offVal2 = analogRead(pot2);
int onVal3 = analogRead(pot3);
int offVal3 = analogRead(pot3);
onVal1 = map(onVal1, 0, 1023, 50, 250);
offVal1 = map(offVal1, 0, 1023, 50, 250);
onVal2 = map(onVal2, 0, 1023, 50, 250);
offVal2 = map(offVal2, 0, 1023, 50, 250);
onVal3 = map(onVal3, 0, 1023, 50, 250);
offVal3 = map(offVal3, 0, 1023, 50, 250);
if (millis() - timeMuteChanged >= period) {
ledOn = !ledOn;
timeMuteChanged = millis();
digitalWrite(led, ledOn);
if (LT == LOW) {
period = ledOn ? onVal2 : offVal2;
}
if (LT == HIGH) {
period = ledOn ? onVal1 : offVal1;
}
}
if (RT == LOW) {
int potVal = analogRead(pot2);
potVal = map(potVal, 0, 1023, 0, 99);
digiPot.set(potVal);
}
if (RT == HIGH) {
int potVal = analogRead(pot3);
potVal = map(potVal, 0, 1023, 0, 99);
digiPot.set(potVal);
}
}