Problem with digispark OLED library when using the oled.print() function

hey guys, I’ve been trying to make a small project of a digital gauge using Digispark ATtiny and 128*64 i2c oled display.Everything was fine except:

  1. when I tried to use the oled.print() function to printout the value of the analogRead() from P3 on the oled display, the value should change from 0~1024 as I rotate the potentiometer. Turn out, the value displayed will have a random number at the fouth digites, so when it should display 801, intead of 801 it will display 8014, which is pretty annoying. I tried various method like to use oled.disply(), but the value displayed on oled blinks, which does not looks comfortable. So, any suggestions?
  2. also, I found P5 cannot be used as a analog input pin, value will only change from ~500 to 1024 instead of 0~1024 as voltage to the pin varies from 0 to 5 volts.
    Thanks!
#include <DigisparkOLED.h>
#include <Wire.h>
// ============================================================================

int sensorValue = 0;
//#include "img0_128x64c1.h"
#include "digistump_128x64c1.h"


void setup() {
  // put your setup code here, to run once:
  pinMode(3, INPUT);
  oled.begin();

}

void loop() {
  sensorValue = analogRead(3);
  // put your main code here, to run repeatedly:
  /*oled.fill(0xFF); //fill screen with color
    delay(1000);
    oled.clear(); //all black
    delay(1000);*/
  //usage: oled.setCursor(X IN PIXELS, Y IN ROWS OF 8 PIXELS STARTING WITH 0);
  oled.setCursor(0, 0); //top left
  oled.setFont(FONT8X16);
  oled.print(sensorValue);
  delay(500);
  //oled.clear();
  /*oled.print(F("DIGISTUMP")); //wrap strings in F() to save RAM!
    oled.setFont(FONT6X8);
    oled.print(F(" OLED!"));
    oled.setCursor(0, 2); //two rows down because the 8x16 font takes two rows of 8
    oled.println(F("test")); //println will move the cursor 8 or 16 pixels down (based on the front) and back to X=0
    oled.print(F("test test test test test")); //lines auto wrap

    delay(3000);
    //usage oled.bitmap(START X IN PIXELS, START Y IN ROWS OF 8 PIXELS, END X IN PIXELS, END Y IN ROWS OF 8 PIXELS, IMAGE ARRAY);
    //oled.bitmap(0, 0, 128, 8, img0_128x64c1);
    //delay(3000);
    oled.bitmap(0, 0, 128, 8, digistumplogo);
    delay(3000);*/
}

Hi.

Your shown code doesn't do what you described, so that's not too helpful.
But usually these kind of problems occur because you're printing a new value without erasing the old value on screen.
The code you did show has a clear in every iteration, so it shouldn't do the described behaviour, but would have a blinking effect.

The code you are using now (and which hasn't been shown yet) would likely not only show the fourth digit all the time once it was introduced, but also a third or second one, if the next value doesn't have such value.
So if the old content is 1023, and the next value is 5, the new displayed value would be 5023.
As you see the printed values are left aligned.

First thing to do, is to see if your last readout is a new value, or the same value already printed on screen.
If it is already there, there's no reason to erase it and/or to print it again.
That will reduce some blinking effect.

Next thing to do, is to check how many digits your new value has.
If it has only one digit, and the old one didn't have that, you will need to print spaces before you'll print the value, or erase the screen.

You might need to consider the font used, if it doesn't use the same number of pixels for each character printed (a "w" is wider than an "i"), then your solution might need a bit more ingenuity.