Blink text on 0.91 display?

I could not find a way to blink text continuously on a 0.91 OLED I2C display using the SSD1306 library. The point is to blink the text showing the temperature if it exceeds 95 degrees. Is it possible to do it and if yes, how?

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example



void setup() {
  pinMode(5,OUTPUT);
  digitalWrite(5,HIGH);
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...






 

  testdrawstyles();    // Draw 'stylized' characters

  



  // Invert and restore display, pausing in-between
  display.invertDisplay(true);
  delay(1000);
  display.invertDisplay(false);
  delay(1000);


}

void loop() {
}










void testdrawstyles(void) {

  float sensorValue = analogRead(15);
  float voltage1 = sensorValue * (35.0 / 1023.0);
  Serial.println((float) voltage1);

  float sensorValue2 = analogRead(14);
  float voltage2 = sensorValue2 * (36.0 / 1023.0);
  Serial.println((float) voltage2);

  float val0 = analogRead(A3);
  float mv = ( val0 / 1024.0) * 5000;
  float tmp1 = mv / 10;
  Serial.print((float) tmp1);
  Serial.println();

  float val5 = analogRead(A4);
  float mv5 = ( val5 / 1024.0) * 5000;
  float tmp2 = mv5 / 10;
  Serial.print((float) tmp2);
  Serial.println();


  float val6 = analogRead(A5);
  float mv6 = ( val6 / 1024.0) * 5000;
  float tmp3 = mv6 / 10;
  Serial.print((float) tmp3);
  Serial.println();

  display.clearDisplay();

  display.setTextSize(1,2);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(38, 0);             // Start at top-left corner
  display.print(F("c"));
  display.setCursor(0, 0);
  display.setTextSize(2);
  display.println(tmp1, 0);
  display.display();

  display.setTextSize(1,2);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(38, 18);             // Start at top-left corner
  display.print(F("c"));
  display.setCursor(0, 18);
  display.setTextSize(2);
  display.println(tmp2, 0);
  display.display();

  display.setTextSize(1,2);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(75, 18);             // Start at top-left corner
  display.print(F("c"));
  display.setCursor(55, 18);
  display.setTextSize(2);
  display.println(tmp3, 0);
  display.display();


  display.setTextSize(1,2);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(122, 0);             // Start at top-left corner
  display.print(F("v"));
  display.setCursor(91, 0);
  display.setTextSize(1,2);
  display.println(voltage1, 2);


  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(122, 18);             // Start at top-left corner
  display.print(F("v"));
  display.setCursor(91, 18);
  display.setTextSize(1,2);
  display.println(voltage2, 2);
  






// display.setTextSize(2);             // Draw 2X-scale text
//  display.setTextColor(SSD1306_WHITE);
  

  display.display();
  delay(2000);
}

Please help :smiling_face_with_tear:!

Display the temperature...
Wait a bit...
Clear the display...
Wait a bit...

Repeat.

That is what I thought of but I couldn't do it :neutral_face:.

You have nothing in the loop function, so what ever you do it only happens once, and once only.

This is an I2C device so you don't read it by reading the analogue input pins A4 and A5.

So this is a nonsense

Read up on I2C devices and how they work. Why not try the examples that come with the libraries you use.

Hello net_worker

The magic numbers in the sketch would like to have a functional name.

1 Like

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