Compilation error: 'responsivePot' was not declared in this scope

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());
 } 
}

Welcome to the forum

The compiler is not lying. The responsivePot array is not declared in the sketch posted

Where did you get the code ?

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.

Spelling counts.

1 Like

Thank you for the fast response! Yes, I am working with a tutorial on YouTube: https://www.youtube.com/watch?v=hcm5H6f8MI8&t=599s

Example code can be found here: YouTube

I hate to ask stupid questions, but how would I declare it here? Again, very new to this.

Copy that example code... paste it here (and your IDE). If the source code is bad, do not trust the video.

Also, try an example from the ResponsiveAnalogRead library:

The site you linked to that has the code is demanding that I enter my email address before letting me in. I will not be doing that

: enters email address :

4 hours later

(999999999) Inbox - email@gmail.com

I had to strip the MIDI stuff. Please peruse this (read in a thorough or careful way) to see how an array of responsive pots is declared and used:

UA Hacked your code.

#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 analog[3] = {
  {A1, true, snapMultiplier},
  {A2, true, snapMultiplier},
  {A3, true, snapMultiplier},
};

void setup() {

  Serial.begin(9600); // Initialize serial communication for debugging

  for (int i = 0; i < N_POTS; i++) {
    analog[i].setAnalogResolution(1023);
  }
}  

void loop() {

  for (int i = 0; i < N_POTS; i++) {
    analog[i].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(analog[0].getValue());
//    Serial.print(analog[1].getValue());
//    Serial.print(analog[2].getValue());
 } 
}

a7

Thank you! This really helped me move forward with my project! I appreciate your help!

Reading @alto777's code, it seems the only real use of the responsive pot thing is commented out

//    Serial.print(analog[0].getValue());
//    Serial.print(analog[1].getValue());
//    Serial.print(analog[2].getValue());

so while it does show how to declare and update the objects, it makes no direct use of whatever functionality they are meant to provide.

Also, analog was a bad name for the array, do better. :expressionless:

a7

Thanks for the input. I'm learning and am trying to make the project as simple as I can, be kind.

Haha, I was criticizing myself… I said it showed how the object is used, it does not. I named the array analog, which is just a bad name.

I assume you copy/paste/edited the example code somehow, where that author called the object analog, and you made 1, 2 and 3 of it.

So I was also criticizing that person.

But kind is on my short list of things to be, cheerful another. Some days I do better than others. Thanks for the reminder.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.