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
  }
1 Like

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

Ahh! Okay. This all hit me at once. I just needed enough time to read over this without being in a hurry. It seems that my Arduboy has stopped working, so I am going to have to use the emulator to get going until I figure out what to do there.

I had to read this one several times to understand it, but I think I’ve got it now.

The part in the code that says, “!inverted”, what’s that? Is the “!” what tells the Arduboy to flip the colors on the screen depending on what the boolean variable state is (true or false)? Is the “!” universally used to flip values?

Oh my goodness. I have seen this page several times. When you sent it to me, I looked at it and I was wondering how do you add your own projects. Then, I suddenly realized that whoever designed the page took the hamburger menu literally and all was revealed to me. I was truly LMAO once I realized that.

ADDED: Holy wow! That emulator works on the cell phone too. I just got to figure out what keyboard keys function for the buttons. If I can’t connect an Arduboy to my cell phone then this will be the next best thing.

I think you may potentially be trying to run before you can walk here.
You really need to have a good grasp of the concept of variables before it’ll make proper sense.

I’ll answer your question anyway though, partly in case I’m misjudging and partly in case you don’t understand now but come back and understand later…

The ! symbol is the logical ‘not’ operator.
It inverts a value of true to false and a value of false to true,
hence the statement inverted = !inverted; sets the variable inverted to the value of its inverse.
That part is what actually toggles the value of the variable between true and false.

arduboy.invert(inverted) is the part that actually tells the screen whether it should be inverted or not.
arduboy.invert(true) inverts the screen (so that white is drawn as black and vice versa),
whilst arduboy.invert(false) restores it to normal (white is white, black is black).

In a rare instance of me using slangy acronyms: RTM. :P

(Documentation is a wonderful thing.)

1 Like

You using the word toggle put the whole thing into context for me. Perfect. Thanks.

Haha. I was just commenting on another thread that I just created a GitHub account. I didn’t know what to do with it yet, but I knew I needed it. Here we go already with GitHub. Apparently, I had good timing.

ADDED: Alright, that is the first “Watched” item I got on GitHub. I don’t think the BlackBerry is going to help me run emulated software much because the keyboard doesn’t have arrow keys.

MORE ADDED: Hey, this offers an offline version to download. Super excited.

1 Like

Without any code, documentation or general text to host your best bet is to just play around with it to figure out what things do.

Getting used to how git (the underlying system) works takes a bit of time and effort.
(It helps to have a basic understanding of trees and/or (directed acyclic) graphs.)

That and reading more documentation:

Unfortunate. Maybe we can get IJKL added as an alternative?

1 Like

Maybe I should be putting in my name tag program just to get familiar with the system. I have a basic understanding of trees, acyclic graphs, and forests. I would say it’s just that, basic. I also want to get familiar with versions. None of the lessons I have read so far have indicated how to track different version. I kind of want to learn this early because I will be more prone to screw up while I am learning, so it would be nice to have an easy recovery option. I am under the impression you want to use GitHub for this sort of thing.

I could see that working. I was wondering why they didn’t use WASD, but realized that would interfere with using the A key for the A button. With IJKL, I could use Z and X for the A and B.

In which case: the history of a repo is stored as a directed acyclic graph of commits.
(And of course a tree is a special type of directed acyclic graph.)

Each commit represents a snapshot of the code along with a heading and a comment providing details of what the change represented by that snapshot is and does.

A basic approach of just commiting things builds up a single ‘chain’ of commits,
but the code can be ‘branched’ off which is where history turns into a ‘tree’ shape,
and then ‘merged’ back in, which is where it becomes a DAG.

There’s a fancy example here.

I also stumbled across this little O’Reilly guide that features a nice example:

(The accompanying text probably says something useful too,
but it looks like it’s far more in depth than you really need to care about - just look at the pretty graphs instead.)

Alternatively: https://www.geeksforgeeks.org/introduction-semantic-versioning/

Usually new versions just get published as new releases with an accompanying version tag.

In a bit of a shameless self plug, have a look at my releases list for Minesweeper:

Note that each release is tagged with a semver-style tag.
E.g. v2.0.2, v2.0.1, v2.0.0, v1.1.0, v1.0.3
(Technically semver requires that the ‘v’ not be present, but GitHub encourages the ‘v’.)

Half the point of git/GitHub is that you can jump back to any point in history and visit the code as it was at that point, as long as you have a commit for that point in time.

Commits are basically time capsules, and a repo is a graph of commits (time capsules) with documentation for the changes that occur.

That’s the general idea.

If I get the time I might have a go at trying to get it to work myself,
though JavaScript is not a language I enjoy using.
If not I’ll pester the creator to see if he has time to do it.

1 Like

I used to do XML a lot and ! was used to denote a document type or comment. I think my brain was having a crossover moment and was wondering why the exclamation point was there. Once I realized we were talking about not equal and toggles I was back in the right reality.

https://www.cellml.org/getting-started/tutorials/tutorial/xml_guide

I think that would be beneficial, especially if there is some drag-and-drop FTP sort of thing available. When I was working on the name tag I messed up some of the code and had to CTRL+Z the thing to death. If I know I am making a major addition (based on my skill level at this point, not the end user), then I will likely want to make a backup. I have also done technical writing before such as user manuals and stuff, so I should enjoy making my own README.txt files. I think it is good timing that I am running into GitHub more heavily now instead of earlier since I’m far enough along for me to want to bother with versions.

Your post was totally comprehensible to me. I took a class in computer logic and design in college, but couldn’t afford to stick around. I am going to delve into the additional resources you have provided to see if there’s any gaps in my knowledge that can be filled. I am a little OCD with the organization, so I think this was another aspect of programming that appealed to me. As such, it stuck in my mind. Haha.

I happen to be somewhat familiar with XML.
(Other examples aside, I wrote an .xspf playlist generator a while back.)

XML is a kind of markup language, which means that really it just describes and structures data, so it’s not really a programming language in the sense of telling a computer what to do (though it could certainly be used to store instructions that would tell a computer what to do) and hence you can’t generalise anything from it to programming languages.
(Except maybe the use of quoted strings.)

There is. Just try it - drag a file onto an established repo.
It’ll upload the file and start a commit. You can upload multiple files.
Changes won’t be applied until you press the ‘commit’ button as would happen with any other kind of commit.

Rather than a ‘backup’ (since everyone commit is a snapshot anyway), what you want to look into is creating a branch for developing a feature, committing to that branch and then merging that branch on the master branch using the ‘pull request’ (PR) feature.

Of course, you can create a branch from any commit at any point in the history.
(It makes more sense if you keep the idea of the history being a graph in your head.)

I’d suggest using README.md files instead so you can make use of markdown support.
(Once again, an example from Minesweeper.)

Depending on what that entailed, you might actually be more qualified than I am.

1 Like

You can press the buttons on the screen graphic of the emulated arduboy, instead of using a physical keyboard. Also, pressing on the “reset” button will reset and restart the sketch, and pressing on the “power switch” will return to the main game selection menu.


If you aren’t comfortable with MicroSoft being the GitHub overlord or don’t want to use GitHub for any other reason, GitLab is a popular alternative. (Of course, you could have accounts on both.)

1 Like