Hi All, I am new to arduino coding and have been struggling with this "learner" project of mine. I have put together this code below and was wondering if anyone could shed light with my struggle with "display.clearDisplay();". All I am doing is whenever I press a button state "LOW" my OLED display will display "OFF" and whenever I press "HIGH" it will display "ON". "ON" and "OFF" are dynamic but in my code there is a string "TITLE HEADER" which is static. Problem is, I have been struggling where to put "display.clearDisplay();" with out one affecting the other specially the title header. I solved the ON and OFF from blinking but then my static title blinks. been pulling my hair out and greatly appreciate some help. cheers
#include <Adafruit_SH1106.h>
#include <Wire.h>
#include <SPI.h>
//#include <Adafruit_GFX.h>
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
int LEDPin=11;
int buttonPin=6;
int buttonRead;
int dt=100;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LEDPin, OUTPUT);
pinMode(buttonPin,INPUT);
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
}
void loop() {
// put your main code here, to run repeatedly:
buttonRead=digitalRead(buttonPin);
Serial.println(buttonRead);
delay(dt);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("TITLE HEADER");
display.display();
if (buttonRead==1){
digitalWrite(LEDPin,LOW);
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(50, 30);
display.println("OFF");
display.display();
}
if (buttonRead==0){
digitalWrite(LEDPin,HIGH);
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(50, 30);
display.println("ON");
display.display();
}
//display.clearDisplay();
}