Potentiometer - AnalogRead

Hi.

I want to put out some values on the Serial Monitor as I turn the potentiometer around.

But when i do not turn it around, he should not print anything.

I tried it like this:

#define POT A0
#define LED 10
int AnalogerWert;
int DigitalerWert;
float DutyCycle;
int voltage;


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  
  AnalogerWert = analogRead(POT);
  DigitalerWert = AnalogerWert/4;
  DutyCycle = (((float)DigitalerWert*100.0)/255.0);
  voltage = AnalogerWert * ((float)(5000.0 / 1023.0));
  
  if (AnalogerWert > 0)
  {
  
  Serial.println("Analog: " + (String)AnalogerWert + " - Digital: " + DigitalerWert + " - Duty Cycle: " +    DutyCycle + "%" + " - Voltage: " + voltage + "mV");
  analogWrite(LED, DigitalerWert);
  //now i need something, that will break the print and do nothing until the point of turning around the potentiometer.
  }
  else
  {
    delay(?); //well he should delay till I do something. he should give me no results back. but how? 
    
  }
  
}

Do some of you know how to solve my problem?
Is there like a time checking function. Like wait 5ms and check if somethings changed and then print all out, if not then check again and so on...?

Save the previous value. If the new value is the same as the previous value don't print anything.

It may be wise to allow a little slack so that a tiny bit of jitter is not treated as a new value - perhaps the value has to change by +/- 5 to be considered a new value.

...R

Why are all those variables that are used only in loop() global? It is a good idea to keep the scope of variables as small as possible.

Some servo/pot test code you can use to see the output on the serial monitor. You don’t need a servo to just see the output on the serial monitor.

//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor

#include <Servo.h> 
Servo myservoS1;
Servo myservoS2;

int potpinS1 = 0;  //analog input pin A0
int potpinS2 = 1;

int newvalS1, oldvalS1;
int newvalS2, oldvalS2;

void setup() 
{
  Serial.begin(9600);  
  myservoS1.attach(2);  
  myservoS2.attach(3);
  Serial.println("testing dual pot servo");  
}

void loop() 
{ 
  newvalS1 = analogRead(potpinS1);           
  newvalS1 = map(newvalS1, 0, 1023, 0, 179); 
  if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){  
    myservoS1.write(newvalS1);
    Serial.print("1- ");
    Serial.println(newvalS1);
    oldvalS1=newvalS1;
  }

  newvalS2 = analogRead(potpinS2);
  newvalS2 = map(newvalS2, 0, 1023, 0, 179);
  if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){  
    myservoS2.write(newvalS2);
    Serial.print("2- ");    
    Serial.println(newvalS2);
    oldvalS2=newvalS2;
  }
  delay(50); //slow down looping to better read serial monitor 
}

I tried it like that, and my Potentiometer began to smoke! Haha

:o

Time to get more.

http://www.ebay.com/itm/10x-B10K-Ohm-Linear-Taper-Rotary-Potentiometer-Panel-Pot-15mm-Shaft-Nuts-Washers-/291010300828?hash=item43c190cb9c:g:BEUAAMXQWzNSeSs6