Mapping colours, most efficient way?

Hi, firstly I am new to all this, I’ve jumped in head first and don’t know what I don’t know.

I’ve written a sketch that reads a digital input, does some math and prints Vlines to an LCD at a height relative to the current value one pixel column at a time. Then I decided I wanted a colour range mapped to the value and came up with this type of arrangement.

#define RED3100 0xf800, RED3110 0xf820.... etc for all possible 565 type colours

int linecolour[] = {RED3100, RED3110, etc etc
int highcolourval; // for setting colour range max
int i = 0; //starting colour

i = map(val, low, high, 0, (highcolourval);
if (i > highcolourval) = highcolourval;

myscreen.drawFastVline(x,y,x,y1,linecolour*);*
It all works like a charm but as I learn I realise there is probably a much better more efficient way?
Ps i memory typed those bits of code, it does work in real life honest!
Ready to learn, many thanks!
Matt

Can you post your entire sketch using a code block?

I'm fairly certain you can reduce your color assignment down to math you just need to determine the pattern.

Thank you, this was my thinking/ hoping.
I can post, later/tomorrow... it is huge, I’ll probably just snip the relevant bits and make a mini sketch as a demo.

Mattty5:
Thank you, this was my thinking/ hoping.
I can post, later/tomorrow... it is huge, I’ll probably just snip the relevant bits and make a mini sketch as a demo.

That would be helpful. Thanks!

Took a little longer than expected, but here it is, a 'demo'

This sketch colour shifts a circle from RED3100 0xf800 to BLUE06331 0x07ff and back forever.

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define BLACK   0x0000
#define WHITE   0xFFFF

#define BLUE06331 0x07ff
#define BLUE06330 0x07fe
#define BLUE06329 0x07fd
#define BLUE06328 0x07fc
#define BLUE06327 0x07fb
#define MINT06326 0x07fa
#define MINT06325 0x07f9
#define MINT06324 0x07f8
#define MINT06323 0x07f7
#define MINT06322 0x07f6
#define GREEN06321 0x07f5
#define GREEN06320 0x07f4
#define GREEN06319 0x07f3
#define GREEN06318 0x07f2
#define GREEN06317 0x07f1
#define GREEN06316 0x07f0
#define GREEN06315 0x07ef
#define GREEN06314 0x07ee
#define GREEN06313 0x07ed
#define GREEN06312 0x07ec
#define GREEN06311 0x07eb
#define GREEN06310 0x07ea
#define GREEN0639 0x07e9
#define GREEN0638 0x07e8
#define GREEN0637 0x07e7
#define GREEN0636 0x07e6
#define GREEN0635 0x07e5
#define GREEN0634 0x07e4
#define GREEN0633 0x07e3
#define GREEN0632 0x07e2
#define GREEN0631 0x07e1
#define GREEN0630  0x07E0
#define GREEN1630  0x0fe0
#define GREEN2630 0x17e0
#define GREEN3630 0x1fe0
#define GREEN4630 0x27e0
#define GREEN5630 0x2fe0
#define GREEN6630 0x37e0
#define GREEN7630 0x3fe0
#define GREEN8630 0x47e0
#define GREEN9630 0x4fe0
#define GREEN10630 0x57e0
#define GREEN11630 0x5fe0
#define GREEN12630 0x67e0
#define GREEN13630 0x6fe0
#define GREEN14630 0x77e0
#define GREEN15630 0x7fe0
#define GREEN16630 0x87e0
#define GREEN17630 0x8fe0
#define GREEN18630 0x97e0
#define GREEN19630 0x9fe0
#define GREEN20630 0xa7e0
#define GREEN21630 0xafe0
#define GREEN22630 0xb7e0
#define GREEN23630 0xbfe0
#define GREEN24630 0xc7e0
#define GREEN25630 0xcfe0
#define GREEN26630 0xd7e0
#define LIME27630 0xdfe0
#define LIME28630 0xe7e0
#define LIME29630 0xefe0
#define YELLOW30630 0xf7e0
#define YELLOW31630 0xffe0
#define YELLOW31620 0xffc0
#define YELLOW31610 0xffa0
#define YELLOW31600 0xff80
#define YELLOW31590 0xff60
#define YELLOW31580 0xff40
#define YELLOW31570 0xff20
#define YELLOW31560 0xff00
#define YELLOW31550 0xfee0
#define YELLOW31540 0xfec0
#define YELLOW31530 0xfea0
#define YELLOW31520 0xfe80
#define YELLOW31510 0xfe60
#define YELLOW31500 0xfe40
#define YELLOW31490 0xfe20
#define YELLOW31480 0xfe00
#define YELLOW31470 0xfde0
#define YELLOW31460 0xfdc0
#define YELLOW31450 0xfda0
#define ORANGE31440 0xfd80
#define ORANGE31430 0xfd60
#define ORANGE31420 0xfd40
#define ORANGE31410 0xfd20
#define ORANGE31400 0xfd00
#define ORANGE31390 0xfce0
#define ORANGE31380 0xfcc0
#define ORANGE31370 0xfca0
#define ORANGE31360 0xfc80
#define ORANGE31350 0xfc60
#define ORANGE31340 0xfc40
#define ORANGE31330 0xfc20
#define ORANGE31320 0xfc00
#define ORANGE31310 0xfbe0
#define ORANGE31300 0xfbc0
#define ORANGE31290 0xfba0
#define ORANGE31280 0xfb80
#define ORANGE31270 0xfb60
#define ORANGE31260 0xfb40
#define ORANGE31250 0xfb20
#define ORANGE31240 0xfb00
#define ORANGE31230 0xfae0
#define ORANGE31220 0xfac0
#define ORANGE31210 0xfaa0
#define ORANGE31200 0xfa80
#define ORANGE31190 0xfa60
#define RED31180 0xfa40
#define RED31170 0xfa20
#define RED31160 0xfa00
#define RED31150 0xf9e0
#define RED31140 0xf9c0
#define RED31130 0xf9a0
#define RED31120 0xf980
#define RED31110 0xf960
#define RED31100 0xf940
#define RED3190 0xf920
#define RED3180 0xf900
#define RED3170 0xf8e0
#define RED3160 0xf8c0
#define RED3150 0xf8a0
#define RED3140 0xf880
#define RED3130 0xf860
#define RED3120 0xf840
#define RED3110 0xf820
#define RED3100 0xf800

int Colour[] = {RED3100, RED3110, RED3120, RED3130, RED3140, RED3150, RED3160, RED3170, RED3180, RED3190, RED31100, RED31110, RED31120, RED31130, RED31140, RED31150, RED31160, RED31170, RED31180, ORANGE31190, ORANGE31200, ORANGE31210, ORANGE31220, ORANGE31230, ORANGE31240, ORANGE31250, ORANGE31260, ORANGE31270, ORANGE31280, ORANGE31290, ORANGE31300, ORANGE31310, ORANGE31320, ORANGE31330, ORANGE31340, ORANGE31350, ORANGE31360, ORANGE31370, ORANGE31380, ORANGE31390, ORANGE31400, ORANGE31410, ORANGE31420, ORANGE31430, ORANGE31440, YELLOW31450, YELLOW31460, YELLOW31470, YELLOW31480, YELLOW31490, YELLOW31500, YELLOW31510, YELLOW31520, YELLOW31530, YELLOW31540, YELLOW31550, YELLOW31560, YELLOW31570, YELLOW31580, YELLOW31590, YELLOW31600, YELLOW31610, YELLOW31620, YELLOW31630, YELLOW30630, LIME29630, LIME28630, LIME27630, GREEN26630, GREEN25630, GREEN24630, GREEN23630, GREEN22630, GREEN21630, GREEN20630, GREEN19630, GREEN18630, GREEN17630, GREEN16630, GREEN15630, GREEN14630, GREEN13630, GREEN12630, GREEN11630, GREEN10630, GREEN9630, GREEN8630, GREEN7630, GREEN6630, GREEN5630, GREEN4630, GREEN3630, GREEN2630, GREEN1630, GREEN0630, GREEN0631, GREEN0632, GREEN0633, GREEN0634, GREEN0635, GREEN0636, GREEN0637, GREEN0638, GREEN0639, GREEN06310, GREEN06311, GREEN06312, GREEN06313, GREEN06314, GREEN06315, GREEN06316, GREEN06317, GREEN06318, GREEN06319, GREEN06320, GREEN06321, MINT06322, MINT06323, MINT06324, MINT06325, MINT06326, BLUE06327, BLUE06328, BLUE06329, BLUE06330, BLUE06331};
int i = 0; //Array pointer
int Step = 0; //Instead of input

void setup() {
  tft.begin(ID);
  tft.setRotation(3);
  tft.fillScreen(BLACK);
}

void loop() {
  for (Step = 0; Step <= 125; Step++) {
    i = map(Step, 0, 125, 0, 125);
    tft.fillCircle(60, 60, 60, Colour[i]);
  }
  for (Step = 125; Step >= 0; Step--) {
    i = map(Step, 0, 125, 0, 125);
    tft.fillCircle(60, 60, 60, Colour[i]);
  }
  /////0-125=(126 colours defined)Step set the same for convinience/inplace of input, otherwise would not use map///
}

Many thanks,
Matt

You might want to look at other color encodings, as some are more compact, and more easily manipulated than RGB. HSV is often a good choice, as a single integer value can define any color, and HSV can be easily converted to RGB, and vice-versa.

Regards,
Ray L.

What you came back with, seems to completely ignore reply #1, which was an excellent suggestion.

aarg:
What you came back with, seems to completely ignore reply #1, which was an excellent suggestion.

Which is precisely what HSV would accomplish. Except the math is already done.

Regards,
Ray L.

The OP wants to display every possible 5-6-5 colour. For that, the colourimetric model doesn't matter.

Thank you for your replies,
I’m reading up on the suggestions.
What happens to the colour code 0xXXXX beyond what we see in the IDE? What does it become before it’s sent to the screen chip for example?
Given I’ve already written the 565 type code so it’s more about reducing memory and processing.

Mattty5:
What happens to the colour code 0xXXXX beyond what we see in the IDE? What does it become before it’s sent to the screen chip for example?

It becomes a string of binary digits stored in one or more memory locations in the microprocessor.

Would mathing the colours into binary within the Sketch (assuming the sequence is workable) reduce overhead?

Of course it would. That is a huge array. How did you decide on the values in the array? That would be the starting point for producing them programmatically. Or did you just copy them from somewhere?

When I first got started (with Arduino, before I knew anything about code) I found this website;

https://chrishewett.com/blog/true-rgb565-colour-picker/

I used this as a reference to build my colour definitions.

I realise now RGB 565 refers to R5bit G6bit B5bit.

More reading ahead for me.

Thank you!

Edit; in the above array I just took each increments between 2 solid colours

Edit; I choose my colour range based on requirements of that graph/chart/output with 2/3 variables ie for a bad to good colour feedback sweep might be red to green where 0 is red and 100 is green, it changes in my main program based on what’s happening.
In terms of what colour to what colour I wonder what creations could come out of some complex math!?