I´m using Spark Fun Micro Pro board 5V: https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro

and to that i´ve hooked a true color OLED from digole: http://www.digole.com/index.php?productID=859

I manage to get my VAL from my potentiometer on screen. But when I exceeds val "10", and then go back to lets say "9", the zero from "10" is still there. It looks like: "90" instead of "9". The problem is of course that the second (and third) number don't go away.. Im sure there is a simple way of doing this but I can't get my head around it.. I´ve tried using clearScreen but that function makes the OLED blink in a unpleasant way every time it clears... Hope you get my question, english isn't my native language, as u maybe can tell =) Thanks

void loop() 
  val = analogRead(potpin);        // reads the value of the     potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);  // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val)  sets the servo position according to the scaled     value 
  mydisp.setPrintPos(9, 6);

  delay(200);  // waits for the servo to get there 
 // mydisp.clearScreen();


Instead of printing "10" or "9" etc, print "10 " or "9 ". Add an extra space at the end of what you print which overwrites the character that was there before.

mydisp.print("  ");

I used 2 spaces there, in case you go from 3 digits straight to 1.

Another method is to "format" the number using sprintf:

char temp[4];
sprintf(temp, "%3d", val);
|improve this answer|||||
  • Ok, but the problem is that I print (val). So what should I write to add a " "(space) after the (val)? – MrHaze May 12 '15 at 17:45
  • Just print spaces to the display. See my edit. – Majenko May 12 '15 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.