Confused: Need to use to Potentiometers

three things to be changed to the code

  • 1 - use proper indenting and add some extra spaces before the comments to make it more readable. Leave out comment that is trivial and take care that comments are correct (check for cw and ccw in your comments :slight_smile:

  • 2 - in loop() add two delay(100) before doing the analog read

  • 3 - You have split the potmeter range in two, but as a potmeter can fluctuate in its readings you will have problems in the "511" area. define a empty zone so fluctuations don't influence the system. Done the first half in code below.

void loop()
{
  delay(100);
  potValue = analogRead(potPin); 
  Serial.println(potValue);
  if (potValue < [glow]505[/glow])  // was 511
  { 
    motorSpeed = (potValue/15 + 8);  //scale potValue to be useful for motor
    clockwise(); 
  }
  if (potValue > 516)       // note that values around 511 are skipped.
  { 
    motorSpeed = ((1023-potValue)/15 + 8); 
    counterclockwise(); 
  }

  delay(100);
  pot2Value = analogRead(pot2Pin); 
  Serial.println(pot2Value);

  ... etc

}