128x32 I2C OLED "Blinks" during refresh

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
JasonM132
 
Posts: 1
Joined: Fri Nov 09, 2012 1:00 pm

128x32 I2C OLED "Blinks" during refresh

Post by JasonM132 »

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 ;)

User avatar
corwyn
 
Posts: 14
Joined: Mon Nov 05, 2012 8:38 pm

Re: 128x32 I2C OLED "Blinks" during refresh

Post by corwyn »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”