SOLVED! Help needed for a noobie using an array to control graphics

Hi Guys;

I am trying to use an array to setup the segments of a graphical 7 segment display.
I think I am close but I get an error in the drawing lines.

here is a section of the code that I am using:

#define sclk 15
#define mosi 16
#define cs   10
#define dc   9
#define rst  6

#define BLACK 0x0000
#define WHITE 0xFFFF

#include <Adafruit_GFX_AS.h>
#include <Adafruit_ILI9341_AS.h>
#include <SPI.h>

Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst);


void setup(void) {
  Serial.begin(115200);
  tft.init();
  tft.setRotation(3);

    tft.setTextSize(2);
    tft.fillScreen(ILI9341_BLACK);
    tft.setTextColor(ILI9341_WHITE);

void loop() {
    if (H==0) String Element[]={"WHITE","WHITE","WHITE","WHITE","WHITE","WHITE","BLACK"}; // 0
    if (H==1) String Element[]={"BLACK","WHITE","WHITE","BLACK","BLACK","BLACK","BLACK"}; // 1
    if (H==2) String Element[]={"WHITE","WHITE","BLACK","WHITE","WHITE","BLACK","WHITE"}; // 2
    if (H==3) String Element[]={"WHITE","WHITE","WHITE","WHITE","BLACK","BLACK","WHITE"}; // 3
    if (H==4) String Element[]={"BLACK","WHITE","WHITE","BLACK","BLACK","WHITE","WHITE"}; // 4
    if (H==5) String Element[]={"WHITE","BLACK","WHITE","WHITE","BLACK","WHITE","WHITE"}; // 5
    if (H==6) String Element[]={"WHITE","WHITE","WHITE","WHITE","WHITE","WHITE","WHITE"}; // 6
    if (H==7) String Element[]={"WHITE","WHITE","WHITE","BLACK","BLACK","BLACK","BLACK"}; // 7
    if (H==8) String Element[]={"WHITE","WHITE","WHITE","WHITE","WHITE","WHITE","WHITE"}; // 8
    if (H==9) String Element[]={"WHITE","WHITE","WHITE","WHITE","BLACK","WHITE","WHITE"}; // 9


// "A"
    tft.fillTriangle(8,82,16,82,16,90,Element[0]);
    tft.fillRect(17,82,34,10,Element[0]);
    tft.fillTriangle(51,82,59,82,51,90,Element[0]);

// "B"
    tft.fillTriangle(52,91,60,91,60,83,Element[1]);
    tft.fillRect(51,92,10,34,Element[1]);
    
// "C"
    
    tft.fillRect(51,127,10,34,Element[2]);
    tft.fillTriangle(52,161,60,161,60,169,Element[2]);
// "D"
    tft.fillTriangle(16,170,8,170,16,162,Element[3]);
    tft.fillRect(17,161,34,10,Element[3]);
    tft.fillTriangle(51,170,59,170,51,162,Element[3]);
// "E"
    
    tft.fillRect(7,127,10,34,Element[4]);
    tft.fillTriangle(7,161,15,161,7,169,Element[4]);
// "F"
    tft.fillTriangle(7,91,15,91,7,83,Element[5]);
    tft.fillRect(7,92,10,34,Element[5]);
// "G"
    tft.fillRect(18,122,32,10,Element[6]);

}

my errors are in the "tft.fillxxxx" lines it appears that it does not like using a array to set the color that way.

Is there a fix for this or do I need to do something different?

Thanks
Rick

What are all those Strings with the same name (hint) doing there?

the value in H sets up the 7 segment array of Element[] that way i will minimize redundant code

Rick

Do you realise that WHITE and "WHITE" are not even remotely related?

I tried removing the quotes and changing it from "String" to "unsigned"

This is the error message I receive:

Display_Test_ILI9341:142:39: error: 'Element' was not declared in this scope

tft.fillTriangle(8,82,16,82,16,90,Element[0]);

^

exit status 1
'Segment' was not declared in this scope

Rick

if (H==0) String Element[]={"WHITE","WHITE","WHITE","WHITE","WHITE","WHITE","BLACK"}; // 0the variable declaration comes after an 'if' statement, and therefor goes out of scope the moment that conditional bit of code is complete (in this case by the end of the line where there is a ';' )
If you want to do it this way (which i do not recommend but it's up to you) then you should declare a 2 dimensional array of unsigned int (globally, const, and probably within PROGMEM), 1 dimension for the 7 segment representation (per character) and 1 for the elements of them. (WHITE, BLACK etc) so you declaration would be something like

const unsigned int digits[10][7] = { 
  {WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK},
  {BLACK,WHITE,WHITE,BLACK,BLACK,BLACK,BLACK},
etc..                                                                       } };

rather wasteful since the information can be stored within a byte per character as you are using only black and white as colors.

Thanks Deva_Rishi!

I was able to get it working with your help!

Thank you so much
Rick