How do I clear the OLED screen using the Tiny4kOLED library?

I'm trying to make my Magic 8 Ball project smaller using an ATtiny85 but I can't seem to clear the screen after the trigger. It just adds the text to it. I tried a few different keywords using the library but here's what I have, right now.

Also how can I get one text show up below another? In the first rendition, "PRESS" was one word on top that dropped down when I put enough spaces and, "ME" was below it.



#include <TinyWireM.h>
#include <USI_TWI_Master.h>
#include <Tiny4kOLED.h>

long randNumber;
int button = 1;
int var = 0;

void setup() {
pinMode(button, INPUT);
 
   oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);

  oled.clear();
  
  oled.on();
  
  oled.switchRenderFrame();
}

void loop() {
var = digitalRead(button);
   oled.setFontX2(FONT8X16P);
                      oled.setCursor(0,21);
                      oled.println(F("PRESS ME!"));

                          if (var == 1){
                        
                          oled.clear();
                        
                          oled.setFont(FONT8X16P);
                     oled.setCursor(0,60);
                      oled.println(F("I'm in a meeting..."));
                   
                    delay(2000);
return 0;
                      }

                      

}

I am not familiar with the library but here is an example function to update the display taken from its documentation

void updateDisplay() {
  // Clear the half of memory not currently being displayed.
  oled.clear();

  // Position the text cursor
  // In order to keep the library size small, text can only be positioned
  // with the top of the font aligned with one of the four 8 bit high RAM pages.
  // The Y value therefore can only have the value 0, 1, 2, or 3.
  // usage: oled.setCursor(X IN PIXELS, Y IN ROWS OF 8 PIXELS STARTING WITH 0);
  oled.setCursor(0, 1);

  // Write text to oled RAM (which is not currently being displayed).
  oled.print(F("ms: "));

  // Write the number of milliseconds since power on.
  oled.print(millis());

  // Swap which half of RAM is being written to, and which half is being displayed.
  // This is equivalent to calling both switchRenderFrame and switchDisplayFrame.
  oled.switchFrame();
}

Note the use of the switchFrame() function and the comments in the preceding line

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.