r/arduino•
LadmanMp4

If statement help

Software Help

I'm trying to write an a sort of invert command for this esp 8 bit gfx library and wrote

int Tcolor;
  int invert = 0;
  if (invert == 0) {int Tcolor = 0xffff;}
  if (invert == 1) {int Tcolor = 0x0000;}
  

but it doesn't change the color when I change the invert variable, why is that?

below is the full code

#include <ESP_8_BIT_GFX.h>
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/DejaVu_Serif_10.h>


// A list of 8-bit color values that work well in a cycle.
uint8_t colorCycle[] = {
  0xFF, // White
  0xFE, // Lowering blue
  0xFD,
  0xFC, // No blue
  0xFD, // Raising blue
  0xFE,
  0xFF, // White
  0xF3, // Lowering green
  0xE7,
  0xE3, // No green
  0xE7, // Raising green
  0xF3,
  0xFF, // White
  0x9F, // Lowering red
  0x5F,
  0x1F, // No red
  0x5F, // Raising red
  0x9F,
  0xFF
};


// Create an instance of the graphics library
ESP_8_BIT_GFX videoOut(true /* = NTSC */, 8 /* = RGB332 color */);


void setup() {
  // Initial setup of graphics library
  videoOut.begin();
}


void loop() {
  // Wait for the next frame to minimize chance of visible tearing
  videoOut.waitForFrame();


  // Clear screen
  videoOut.fillScreen(0);
  int offset = 18;
  int base = 40;
  int Tcolor;
  int invert = 0;
  if (invert == 0) {int Tcolor = 0xffff;}
  if (invert == 1) {int Tcolor = 0x0000;}
  


  // Draw text in the middle of the screen
  videoOut.setRotation(1);
  videoOut.setTextSize(1);
  videoOut.setFont(&DejaVu_Serif_10);
  videoOut.setCursor(18, base);
  videoOut.setTextColor(Tcolor);
  videoOut.setTextWrap(false);
  videoOut.print("Censorship is the child of fear ");
  videoOut.setCursor(18, base+offset);
  videoOut.print("and the father of ignorance. Our ");
  videoOut.setCursor(18, base+(offset * 2));
  videoOut.print("children cannot afford to have the ");
  videoOut.setCursor(18, base+(offset * 3));
  videoOut.print("truth of the world withheld from ");
  videoOut.setCursor(18, base+(offset * 4));
  videoOut.print("them. They need us to be brave ");
  videoOut.setCursor(18, base+(offset * 5));
  videoOut.print("enough to give them great books so ");
  videoOut.setCursor(18, base+(offset * 6));
  videoOut.print("they can learn how to grow up into ");
  videoOut.setCursor(18, base+(offset * 7));
  videoOut.print("the men and women we want them ");
  videoOut.setCursor(18, base+(offset * 8));
  videoOut.print("to be.");
}

Posted Sep 5, 2026, 3:57 PM UTC

835
Loading comments…