setTextColor confusion

I’m really struggling using setTextColor.

It doesn’t seem to… change the text color where it is in the code but else where in the code I guess?

Pardon my terrible code but here is my level select screen:

int counter = 1;
  for(int y = 0; y < 5;y++) {
    for(int x = 0; x < 5;x++) {
      arduboy.setCursor(x*25+1,y*14+1);
      arduboy.print(counter);
      arduboy.fillRect(x*25+14,y*14+1,7,7);
      if(completed[counter-1] == false) {
        arduboy.setCursor(x*25+14,y*14+1);
        arduboy.setTextColor(BLACK);
        arduboy.write('?');
        arduboy.setTextColor(WHITE);
      }
      counter += 1;
    }
  }

If we assume that all entries in completed are false we get:
wrong%20menu

Which doesn’t look right at all to me. There should be black ?s inside my white rectangles! I only got my boy a few days ago so yknow… I hope I can be cut some slack here.

edit: so I didn’t realise that the black in ABE saved as 0 alpha… that makes my screenshot a bit less useful.

If you change the text colour, you probably also want to change the text background colour using setTextBackground()

I am having a similar noob problem. I am trying to make “Your Company Name Here” black text while “PHOENIX DOWNER” remains white because I want to put a white filled rectangle behind “Your Company Name Here”. I can only seem to change the color of the text for the whole screen. I went over all 181 pages of the library and can’t figure out what I am doing wrong.

#include <Arduboy2.h>

Arduboy2 arduboy;


void setup() {

  arduboy.begin();
  arduboy.setFrameRate(15);
}


void loop() {
  if (!(arduboy.nextFrame()))
    return;

  arduboy.clear();
  arduboy.fillCircle(8, 7, 3, WHITE);
  arduboy.fillCircle(119, 7, 3, WHITE);
  arduboy.fillCircle(8, 39, 3, WHITE);
  arduboy.fillCircle(119, 39, 3, WHITE);
  
  arduboy.drawFastVLine(8, 3, 64, BLACK);
  arduboy.drawFastVLine(119, 3, 64, BLACK);
  arduboy.drawFastVLine(0, 0, 64, WHITE);
  arduboy.drawFastVLine(127, 0, 64, WHITE);
  arduboy.drawFastHLine(0, 0, 128, WHITE);
  
  arduboy.setCursor(23, 8);
  arduboy.setTextSize(2.75);
  arduboy.print(F("PHOENIX"));
  arduboy.setCursor(30, 25);
  arduboy.print(F("DOWNER"));
  
  arduboy.drawFastHLine(0, 46, 128, WHITE);
  arduboy.setTextSize(1);
  arduboy.setCursor(5,51);
/* Where I am stuck */
  arduboy.setTextColor(BLACK);
  arduboy.setTextBackground(BLACK);
  arduboy.print(F("Your Company Name Here"));
  
  arduboy.drawFastHLine(0, 63, 128, WHITE);
  
  arduboy.display();
}

I think I have to assume I got in over my head if I am getting lost this quickly. I can’t even get the invert to work. I seem to be having troubles with even understanding the basic instructions. I might just be stepping away from this and only using the Arduboy as a game machine.

#include <Arduboy2.h>

Arduboy2 arduboy;


void setup() {

  arduboy.begin();
  arduboy.setFrameRate(15);
}


void loop() {
  if (!(arduboy.nextFrame()))
    return;

  arduboy.clear();
  arduboy.fillCircle(8, 7, 3, WHITE);
  arduboy.fillCircle(119, 7, 3, WHITE);
  arduboy.fillCircle(8, 39, 3, WHITE);
  arduboy.fillCircle(119, 39, 3, WHITE);
  
  arduboy.drawFastVLine(8, 3, 64, BLACK);
  arduboy.drawFastVLine(119, 3, 64, BLACK);
  arduboy.drawFastVLine(0, 0, 64, WHITE);
  arduboy.drawFastVLine(127, 0, 64, WHITE);
  arduboy.drawFastHLine(0, 0, 128, WHITE);
  
//specify that you want the text below to be white
  arduboy.setTextColor(WHITE);
  arduboy.setTextBackground(BLACK);
  
  arduboy.setCursor(23, 8);
  arduboy.setTextSize(2.75);
  arduboy.print(F("PHOENIX"));
  arduboy.setCursor(30, 25);
  arduboy.print(F("DOWNER"));
  
  arduboy.drawFastHLine(0, 46, 128, WHITE);
  arduboy.setTextSize(1);
  arduboy.setCursor(5,51);
/* Where I am stuck */
  arduboy.setTextColor(BLACK);
  arduboy.setTextBackground(WHITE);
  arduboy.print(F("Your Company Name Here"));
  
  arduboy.drawFastHLine(0, 63, 128, WHITE);
  
  arduboy.display();
}


When you change the text colors it doesn’t reset next frame so everything above the setTextColor becomes black too.

The solution being to set the color to white before you want to draw the white text so it doesn’t use whatever it was set to last, which was black.

Hope that helps

3 Likes

What “invert” are you talking about?

I will be back on here to tackle this issue either late Sunday or sometime Monday. The BlackBerry Priv didn’t have full OTG, so it’s not connecting to the Arduboy. I will have to program from home and that is my next significant amount of time off. I don’t recall exactly, but I highlighted it in the PDF for the library. It’s supposed to invert all the colors on the screen. I’m under the impression that if I set it up as a loop I can get the colors to invert every so many seconds (which I presume are represented as frame numbers?). Anyways, I will be back early in the week.

I am going to try that Sunday evening or sometime Monday and try different variations of it to make sure I understand. Working some long shifts until then, but I will be back on it.

So you’re talking about the actual invert() function. You can use it as long as you want to invert the entire screen.
You use
invert(true)
to invert the screen colours and
invert(false)
to return to normal colours.

Yes, you can use a count of frames to time things, such as your goal to invert the screen and return to normal after a delay.

Since the invert() function is told either to invert (true) or display normal colours (false), you will have to keep track of the state the screen is in, in order to change it to the opposite state. You should use a global boolean variable for this. I’ll call the variable inverted:
boolean inverted = false;

There is a function named everyXFrames(), which, as the name implies, will return true if the number of frames you specify has elapsed since the last time it returned true. If your frame rate is 15 frames per second, then to flip the screen colours every 2 seconds you would use a value of 30.

  if (arduboy.everyXFrames(30)) {
    inverted = !inverted; // flip the flag
    arduboy.invert(inverted); // set the screen state to match the flag
  }

You should be able to test you code using the emulator running in a browser.