Hi! I am fairly new to Arduino. I am trying to control three potentiometers with an Arduino Micro that will output to MIDI, but I've run into a issue in the code that I can't seem to figure out. Any help would be very appreciated.
I keep getting an error message that reads, "Compilation error: 'responsivePot' was not declared in this scope".
Again, I'm new to this, but would love to learn. I've been researching the issue and can't find a solution so I figured I would reach out for pointers. Code included below:
#include "MIDIUSB.h" // Include the MIDIUSB library for MIDI communication
#include <ResponsiveAnalogRead.h> // Include the ResponsiveAnalogRead library from https://github.com/dxinteractive/ResponsiveAnalogRead
const int N_POTS = 3;
int potPin[N_POTS] = { A0, A1, A2};
int potCC[N_POTS] = { 4, 5, 6 };
int analogtRead[N_POTS] = { 0 };
int potState[N_POTS] = { 0 };
int potPState[N_POTS] = { 0 };
int midiState[N_POTS] = { 0 };
int midiPState[N_POTS] = { 0 };
byte potThreshold = 3;
const int POT_TIMEOUT = 300;
unsigned long pPotTime[N_POTS];
unsigned long potTimer[N_POTS];
float snapMultiplier = 0.01;
ResponsiveAnalogRead analog1(A1, true);
ResponsiveAnalogRead analog2(A2, true);
ResponsiveAnalogRead analog3(A3, true);
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
for (int i = 0; i < N_POTS; i++) {
responsivePot[i] = ResonsiveAnalogRead(A0, true, snapMultiplier);
responsivePot[i].setAnalogResolution(1023);
responsivePot[i] = ResonsiveAnalogRead(A1, true, snapMultiplier);
responsivePot[i].setAnalogResolution(1023);
responsivePot[i] = ResonsiveAnalogRead(A2, true, snapMultiplier);
responsivePot[i].setAnalogResolution(1023);
}
}
void loop() {
analog1.update();
analog2.update();
analaog3.update();
for (int i =0; i < N_POTS; i++) {
potState[i] = analogRead(potPin[i]);
midiState[i] = map(potState[i], 0, 1023, 0, 128);
int potVar = abs(potState[i] - potPState[i]);
if (potVar > potThreshold) {
pPotTime[i] = millis();
}
potTimer[i] = millis() - pPotTime[i];
if (potTimer[i] < POT_TIMEOUT) {
if(midiState[i] != midiPState[i]) {
Serial.print(" Pot:");
Serial.print(i);
Serial.print(" | ");
Serial.print(potState[i]);
Serial.print(" ");
Serial.print(" - MIDIState:");
Serial.print(midiState[i]);
midiPState[i] = midiState[i];
}
potPState[i] = potPState[i];
}
Serial.print(analogOne.getValue());
Serial.print(analogTwo.getValue());
}
}
Did you copy the code line by line from a tutorial? If so, you may have missed the line declaring responsivePot. Arduino IDE can't use variables that don't exist in the active sketch.