The new Raspberry Pi B Model B+ is here - Pick one up in the store and check our detailed guide!

128x32 I2C OLED "Blinks" during refresh

by JasonM132 on Tue Nov 13, 2012 8:53 am

Now I'm pretty sure this is normal, but being a complete novice with this coding system I'm not sure how to get around the screen blinking during the loop or refresh period of the code.

What I'm doing (or trying to do) is to keep a constantly updated number value displayed on the OLED that is generated from a 100mm soft-pot. I've got the code itself working with the pot but am trying to find a work-around to keep the screen from blinking during every update of the pot. Here's the code I'm working with:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16


#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

int pot = 0;
int val;

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

void loop()
{

val = map(analogRead(2), 0, 1023, 0, 20);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)

display.clearDisplay();

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("SoftPot");
display.setTextSize(3);
display.setTextColor(WHITE);
display.print(val);
display.display();
delay(100);}


I know the code is probably a mess! go easy on me it's my first time ;)
JasonM132
 
Posts: 1
Joined: Fri Nov 09, 2012 12:00 pm

Re: 128x32 I2C OLED "Blinks" during refresh

by Corwyn on Fri Nov 23, 2012 1:25 pm

Instead of clearing the whole screen on each iteration of the loop, just clear the part that is changing (by writing spaces). It also looks like you are initializing the screen in every loop. That should probably be in the setup code.
User avatar
Corwyn
 
Posts: 14
Joined: Mon Nov 05, 2012 7:38 pm