Not declared in scope

#define POT1_PIN A1
#define POT2_PIN A2

#include <X9C103S.h>
void setup() {
  Serial.begin(9600);
  X9C103S pot1(1, 2, 3);
  X9C103S pot2(4, 5, 6);
  pot1.initializePot();
  pot2.initializePot();
}

void loop() {
  int resistance1 = map(analogRead(POT1_PIN), 0, 1023, 0, 100);
  int resistance2 = map(analogRead(POT2_PIN), 0, 1023, 0, 100);
  pot1.setResistance(resistance1);
  Serial.write("Potentiometer 1:");
  Serial.write(pot1.getResistance());
  pot2.setResistance(resistance2);
  Serial.write("Potentiometer 2:");
  Serial.write(pot2.getResistance());
}

I'm trying to make my sons power wheels variable speed. I started with a PWM motor controller and a 3 wire pedal (pot) but its lowest value is too high to stop the motors. I was planning on sticking an arduino in so I can map the real pot to output the value to the digital pot that way I can control the bottom and the top. Any help would be appreciated.

Try moving the instantiation outside the loop();

(confusing that the example in the library has it "wrong"... if this works)

** but I think you should not use pin 1 (even as a test pin)

#define POT1_PIN A1
#define POT2_PIN A2

#include <X9C103S.h>
X9C103S pot1(1, 2, 3);
X9C103S pot2(4, 5, 6);

void setup() {
  Serial.begin(9600);
  pot1.initializePot();
  pot2.initializePot();
}

void loop() {
  int resistance1 = map(analogRead(POT1_PIN), 0, 1023, 0, 100);
  int resistance2 = map(analogRead(POT2_PIN), 0, 1023, 0, 100);
  pot1.setResistance(resistance1);
  Serial.write("Potentiometer 1:");
  Serial.write(pot1.getResistance());
  pot2.setResistance(resistance2);
  Serial.write("Potentiometer 2:");
  Serial.write(pot2.getResistance());
}

I don't understand what you changed but it compiled. Thank you.

Do a "before and after" comparison of the code and it should become clear.

1 Like

The "instantiation" - the command to create the object.

X9C103S pot1(1, 2, 3);
X9C103S pot2(4, 5, 6);

It creates pot1 object (instance) and pot2 object (instance). These objects are the thing you direct to do work in your code... "pot1.getResistance(...)" and so on.

This is the library "example.ino" file... which shows the ?wrong? way, and will not compile unless the instantiation is move outside loop();

//This example shows how to use the 'getResistance()' method.

#include <X9C103S.h>
// X9C103S pot1(6, 7, 8); // this line should be outside loop(); or it creates "local" instances to loop();
//X9C103S digital potentiometer connected to the Arduino with inc pin to pin 6 ud pin to pin 7 and cs pin to pin 8. Change pin numbers as nessary.
void setup() {
  Serial.begin(9600);
  X9C103S pot1(6, 7, 8); //X9C103S digital potentiometer connected to the Arduino with inc pin to pin 6 ud pin to pin 7 and cs pin to pin 8. Change pin numbers as nessary.
  pot1.initializePot();
}

void loop() {
  pot1.setResistance(45); //Sets the pot resistance to 50. The number can be any number from 1 to 100 (both included).
  pot1.increaseResistance(25); //Increases the pot resistance by 10. The resistance is now at the value 70.
  Serial.write(pot1.getResistance()); //Gets the resistance of the pot and sends it via serial.
}

Should the author be notified? How?

I see what you changed. Thanks again. This is for my sons birthday you will have made his day. The plan worked and I have full control of the motors. I can't thank you enough.

2 Likes