Digole setScreenOff / On

Hi Spark Community,

hopefully this is a simple question. I have a digole OLED display attached to my Core. I need to turn it off and on again at a specific point in my loop. For now, this is pretty simple and not the question, because I can simple use digole.setScreenOn() or even digole.setScreenOff().

Now we come to the point. I want to do something like this:

if (!digole.setScreenOn()) { digole.setScreenOn(); }

Right now I am damn pretty sure this will not work. I do not want to add a counter variable and I have tried to understand the library self. But, mhm ok I don´t understand it enough to know what to do. I only want to run this piece of code if the display is set off. Here is the function that I have found in the library “DigoleSerialDisplay.cpp”:

void DigoleSerialDisp::setScreenOn(void) {
    Print::print("SOO");
    write((uint8_t) 1);
}

void DigoleSerialDisp::setScreenOff(void) {
    Print::print("SOO");
    write((uint8_t) 0);
}

I know that void in a function means that this function return nothing and takes nothing. But what is that Print::print(“SOO”); thing do?

I know that I have here some basic questions and my noobness is huge in coding this is the point I have to ask you out there.

@clyde, set up a boolean flag variable in your code that you set to “true” when you turn on the screen and “false” when you turn it off. Then test that var to decide whether you turn on or off:

boolean screenOn = true;  //start up condition

if (!screenOn) {  //screen is off, turn it on
    digole.setScreenOn(); screenOn = true;
}
else {  //screen is on, turn it off
    digole.setScreenOff(); screnOn = false;
}

:smile:

2 Likes

@peekay123
Ok, sounds good, thank you. But what is when I use exactly that in my library file?

Something like that:

bool digoleDisplayStatus = false;       //start condition
 
 void DigoleSerialDisp::setScreenOn(void) {
    Print::print("SOO");
    write((uint8_t) 1);
    digoleDisplayStatus = true;      //set flag
}

void DigoleSerialDisp::setScreenOff(void) {
    Print::print("SOO");
    write((uint8_t) 0);
    digoleDisplayStatus = false;      //set flag
}

This should set the boolean to true or false every time I use digole.setScreenOn/Off(), am i right? So I can use:

if (!digoleDisplayStatus) {  //screen is off, turn it on
    digole.setScreenOn();
} ...

Will try this one now :blush:

File: digoleSerialDisplay.cpp:

digoleDisplayStatus = false; 
void DigoleSerialDisp::setScreenOn(void) {
    Print::print("SOO");
    write((uint8_t) 1);
    digoleDisplayStatus = true;
}

void DigoleSerialDisp::setScreenOff(void) {
    Print::print("SOO");
    write((uint8_t) 0);
    digoleDisplayStatus = false;
}

File main.ino:

extern bool digoleDisplayStatus;

if (!digoleDisplayStatus) { digole.setScreenOn(); };

@clyde, which digole library are you using? It would make more sense to extend the digole library with a function that returns the screen status instead. :smile:

@peekay123

/* *********************************************************************************** */
/* Digole Serial Display Library - Version 006					                       */
/* Copyright 2014 Timothy Brown / Paul Kourany / Digole*/

I have tested my code and it works just fine, but I understand that this is not the fine art of coding.

@clyde, timothy is no longer involved with this community and Digole has done several updates to their library since that one was published. I will clone tim’s repo, update it to include digole’s changes and add several features (like the on/off status) to the class. I will post the link to the updated repo once I’m done. :smile:

@peekay123
Thank you, thank you, but you I don´t want to waste your time on that. :slight_smile: there are more important things out there. So please do this only when you have time left - at this moment my crude workaround will do.

cheers clyde

@clyde, no problem. Doing ports and managing libraries is one of my small pleasures! :smile:

2 Likes