How to use Progmem?

How can I use the PROGMEM keyword on a String Array? Can someone please edit the following String to be used with PROGMEM. And please also explain how can I access it later.

String theArray[][5]  = 
	 { { " IndianRed" , " 205" , " 92" , " 92 " },
{ " LightCoral" , " 240" , " 128" , " 128 " },
{ " Salmon" , " 250" , " 128" , " 114 " },
{ " DarkSalmon" , " 233" , " 150" , " 122 " },
{ " LightSalmon" , " 255" , " 160" , " 122 " },
{ " Crimson" , " 220" , " 20" , " 60 " },
{ " Red" , " 255" , " 0" , " 0 " },
{ " FireBrick" , " 178" , " 34" , " 34 " },
{ " DarkRed" , " 139" , " 0" , " 0 " },
{ " Pink" , " 255" , " 192" , " 203 " },
{ " HotPink" , " 255" , " 105" , " 180 " },
{ " DeepPink" , " 255" , " 20" , " 147 " },
{ " MediumVioletRed" , " 199" , " 21" , " 133 " },
{ " PaleVioletRed" , " 219" , " 112" , " 147 " },
{ " Coral" , " 255" , " 127" , " 80 " },
{ " Tomato" , " 255" , " 99" , " 71 " },
{ " OrangeRed" , " 255" , " 69" , " 0 " },
{ " DarkOrange" , " 255" , " 140" , " 0 " },
{ " Orange" , " 255" , " 165" , " 0 " },
{ " Gold" , " 255" , " 215" , " 0 " },
{ " Yellow" , " 255" , " 255" , " 0 " },
{ " LightGoldenrodYellow" , " 250" , " 250" , " 210 " },
{ " Moccasin" , " 255" , " 228" , " 181 " },
{ " PeachPuff" , " 255" , " 218" , " 185 " },
{ " PaleGoldenrod" , " 238" , " 232" , " 170 " },
{ " Khaki" , " 240" , " 230" , " 140 " },
{ " DarkKhaki" , " 189" , " 183" , " 107 " },
{ " Lavender" , " 230" , " 230" , " 250 " },
{ " Thistle" , " 216" , " 191" , " 216 " },
{ " Violet" , " 238" , " 130" , " 238 " },
{ " Orchid" , " 218" , " 112" , " 214 " },
{ " Magenta" , " 255" , " 0" , " 255 " },
{ " MediumOrchid" , " 186" , " 85" , " 211 " },
{ " MediumPurple" , " 147" , " 112" , " 219 " },
{ " RebeccaPurple" , " 102" , " 51" , " 153 " },
{ " BlueViolet" , " 138" , " 43" , " 226 " },
{ " DarkViolet" , " 148" , " 0" , " 211 " },
{ " DarkOrchid" , " 153" , " 50" , " 204 " },
{ " DarkMagenta" , " 139" , " 0" , " 139 " },
{ " Purple" , " 128" , " 0" , " 128 " },
{ " Indigo" , " 75" , " 0" , " 130 " },
{ " SlateBlue" , " 106" , " 90" , " 205 " },
{ " DarkSlateBlue" , " 72" , " 61" , " 139 " },
{ " MediumSlateBlue" , " 123" , " 104" , " 238 " },
{ " GreenYellow" , " 173" , " 255" , " 47 " },
{ " LawnGreen" , " 124" , " 252" , " 0 " },
{ " Lime" , " 0" , " 255" , " 0 " },
{ " LimeGreen" , " 50" , " 205" , " 50 " },
{ " LightGreen" , " 144" , " 238" , " 144 " },
{ " SpringGreen" , " 0" , " 255" , " 127 " },
{ " SeaGreen" , " 46" , " 139" , " 87 " },
{ " ForestGreen" , " 34" , " 139" , " 34 " },
{ " Green" , " 0" , " 128" , " 0 " },
{ " DarkGreen" , " 0" , " 100" , " 0 " },
{ " YellowGreen" , " 154" , " 205" , " 50 " },
{ " OliveDrab" , " 107" , " 142" , " 35 " },
{ " Olive" , " 128" , " 128" , " 0 " },
{ " MediumAquamarine" , " 102" , " 205" , " 170 " },
{ " DarkSeaGreen" , " 143" , " 188" , " 139 " },
{ " Aqua" , " 0" , " 255" , " 255 " },
{ " Cyan" , " 0" , " 255" , " 255 " },
{ " LightCyan" , " 224" , " 255" , " 255 " },
{ " PaleTurquoise" , " 175" , " 238" , " 238 " },
{ " Turquoise" , " 64" , " 224" , " 208 " },
{ " DarkTurquoise" , " 0" , " 206" , " 209 " },
{ " CadetBlue" , " 95" , " 158" , " 160 " },
{ " LightBlue" , " 173" , " 216" , " 230 " },
{ " DodgerBlue" , " 30" , " 144" , " 255 " },
{ " RoyalBlue" , " 65" , " 105" , " 225 " },
{ " Blue" , " 0" , " 0" , " 255 " },
{ " DarkBlue" , " 0" , " 0" , " 139 " },
{ " MidnightBlue" , " 25" , " 25" , " 112 " },
{ " Brown" , " 165" , " 42" , " 42 " },
{ " Maroon" , " 128" , " 0" , " 0 " },
{ " White" , " 255" , " 255" , " 255 " },
{ " AntiqueWhite" , " 250" , " 235" , " 215 " },
{ " LightGray" , " 211" , " 211" , " 211 " },
{ " Silver" , " 192" , " 192" , " 192 " },
{ " DarkGray" , " 169" , " 169" , " 169 " },
{ " Gray" , " 128" , " 128" , " 128 " },
{ " LightSlateGray" , " 119" , " 136" , " 153 " },
{ " SlateGray" , " 112" , " 128" , " 144 " },
{ " DarkSlateGray" , " 47" , " 79" , " 79 " },
{ " Black" , " 0" , " 0" , " 0 "}};

Thanks in advance!

Strings can not be stored in PROGMEM.

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

There are 140 of those: https://www.w3schools.com/colors/colors_names.asp.
I think you can use the numbers as bytes and convert it later with the extra spaces.
The shortest name is "Red".
The longest name could be "LightGoldenrodYellow" ?

If you have a Arduino Mega 2560 with enough Flash memory, then you can make an array of a fixed length for the text. It will waste some Flash memory, but the sketch is simple.
If you don't want to waste Flash memory, then it could be a continues string of data with markers between the items. Then you have to search through the data to find the name.

Would it be possible to use "#F0F8FF" for the color ? I think that would make it a lot easier. Any conversion can be done in the sketch.

Which Arduino board do you use ?

Didn't this get answered here Creating Multiple Variables Shortcut - #5 by PieterP

Why are you starting a new thread about the same topic?

1 Like

Here is one way to put your characters into an array in PROGMEM. Because every element of a character array has to be the same size, this will use almost 10k of PROGMEM but if you don't need it for anything else, that won't be a problem.

const char theArray[84][5][23] PROGMEM =
{
  { " IndianRed" , " 205" , " 92" , " 92 " },
  { " LightCoral" , " 240" , " 128" , " 128 " },
  { " Salmon" , " 250" , " 128" , " 114 " },
  { " DarkSalmon" , " 233" , " 150" , " 122 " },
  { " LightSalmon" , " 255" , " 160" , " 122 " },
  { " Crimson" , " 220" , " 20" , " 60 " },
  { " Red" , " 255" , " 0" , " 0 " },
  { " FireBrick" , " 178" , " 34" , " 34 " },
  { " DarkRed" , " 139" , " 0" , " 0 " },
  { " Pink" , " 255" , " 192" , " 203 " },
  { " HotPink" , " 255" , " 105" , " 180 " },
  { " DeepPink" , " 255" , " 20" , " 147 " },
  { " MediumVioletRed" , " 199" , " 21" , " 133 " },
  { " PaleVioletRed" , " 219" , " 112" , " 147 " },
  { " Coral" , " 255" , " 127" , " 80 " },
  { " Tomato" , " 255" , " 99" , " 71 " },
  { " OrangeRed" , " 255" , " 69" , " 0 " },
  { " DarkOrange" , " 255" , " 140" , " 0 " },
  { " Orange" , " 255" , " 165" , " 0 " },
  { " Gold" , " 255" , " 215" , " 0 " },
  { " Yellow" , " 255" , " 255" , " 0 " },
  { " LightGoldenrodYellow" , " 250" , " 250" , " 210 " },
  { " Moccasin" , " 255" , " 228" , " 181 " },
  { " PeachPuff" , " 255" , " 218" , " 185 " },
  { " PaleGoldenrod" , " 238" , " 232" , " 170 " },
  { " Khaki" , " 240" , " 230" , " 140 " },
  { " DarkKhaki" , " 189" , " 183" , " 107 " },
  { " Lavender" , " 230" , " 230" , " 250 " },
  { " Thistle" , " 216" , " 191" , " 216 " },
  { " Violet" , " 238" , " 130" , " 238 " },
  { " Orchid" , " 218" , " 112" , " 214 " },
  { " Magenta" , " 255" , " 0" , " 255 " },
  { " MediumOrchid" , " 186" , " 85" , " 211 " },
  { " MediumPurple" , " 147" , " 112" , " 219 " },
  { " RebeccaPurple" , " 102" , " 51" , " 153 " },
  { " BlueViolet" , " 138" , " 43" , " 226 " },
  { " DarkViolet" , " 148" , " 0" , " 211 " },
  { " DarkOrchid" , " 153" , " 50" , " 204 " },
  { " DarkMagenta" , " 139" , " 0" , " 139 " },
  { " Purple" , " 128" , " 0" , " 128 " },
  { " Indigo" , " 75" , " 0" , " 130 " },
  { " SlateBlue" , " 106" , " 90" , " 205 " },
  { " DarkSlateBlue" , " 72" , " 61" , " 139 " },
  { " MediumSlateBlue" , " 123" , " 104" , " 238 " },
  { " GreenYellow" , " 173" , " 255" , " 47 " },
  { " LawnGreen" , " 124" , " 252" , " 0 " },
  { " Lime" , " 0" , " 255" , " 0 " },
  { " LimeGreen" , " 50" , " 205" , " 50 " },
  { " LightGreen" , " 144" , " 238" , " 144 " },
  { " SpringGreen" , " 0" , " 255" , " 127 " },
  { " SeaGreen" , " 46" , " 139" , " 87 " },
  { " ForestGreen" , " 34" , " 139" , " 34 " },
  { " Green" , " 0" , " 128" , " 0 " },
  { " DarkGreen" , " 0" , " 100" , " 0 " },
  { " YellowGreen" , " 154" , " 205" , " 50 " },
  { " OliveDrab" , " 107" , " 142" , " 35 " },
  { " Olive" , " 128" , " 128" , " 0 " },
  { " MediumAquamarine" , " 102" , " 205" , " 170 " },
  { " DarkSeaGreen" , " 143" , " 188" , " 139 " },
  { " Aqua" , " 0" , " 255" , " 255 " },
  { " Cyan" , " 0" , " 255" , " 255 " },
  { " LightCyan" , " 224" , " 255" , " 255 " },
  { " PaleTurquoise" , " 175" , " 238" , " 238 " },
  { " Turquoise" , " 64" , " 224" , " 208 " },
  { " DarkTurquoise" , " 0" , " 206" , " 209 " },
  { " CadetBlue" , " 95" , " 158" , " 160 " },
  { " LightBlue" , " 173" , " 216" , " 230 " },
  { " DodgerBlue" , " 30" , " 144" , " 255 " },
  { " RoyalBlue" , " 65" , " 105" , " 225 " },
  { " Blue" , " 0" , " 0" , " 255 " },
  { " DarkBlue" , " 0" , " 0" , " 139 " },
  { " MidnightBlue" , " 25" , " 25" , " 112 " },
  { " Brown" , " 165" , " 42" , " 42 " },
  { " Maroon" , " 128" , " 0" , " 0 " },
  { " White" , " 255" , " 255" , " 255 " },
  { " AntiqueWhite" , " 250" , " 235" , " 215 " },
  { " LightGray" , " 211" , " 211" , " 211 " },
  { " Silver" , " 192" , " 192" , " 192 " },
  { " DarkGray" , " 169" , " 169" , " 169 " },
  { " Gray" , " 128" , " 128" , " 128 " },
  { " LightSlateGray" , " 119" , " 136" , " 153 " },
  { " SlateGray" , " 112" , " 128" , " 144 " },
  { " DarkSlateGray" , " 47" , " 79" , " 79 " },
  { " Black" , " 0" , " 0" , " 0 "}
};

void setup()
{
  Serial.begin(115200);
  Serial.println("hello world");

  for (int color = 0; color < 84; color++)
  {
    Serial.print(color);
    Serial.print(": ");
    Serial.print((__FlashStringHelper*)&theArray[color][0]);
    Serial.print((__FlashStringHelper*)&theArray[color][1]);
    Serial.print((__FlashStringHelper*)&theArray[color][2]);
    Serial.print((__FlashStringHelper*)&theArray[color][3]);
    Serial.println((__FlashStringHelper*)&theArray[color][4]);
  }
}

void loop() {}

I don't quite understand why the numbers are being stored as character strings. It would be much more space efficient to have an array of structures with a character array for the name and then three bytes or ints for the numbers.

I am learning. I am still 13

Here is a way to store the array in less space by using a single 'byte' to store the R, G, and B numbers:

struct Color
{
  char Name[23];
  byte R;
  byte G;
  byte B;
};

const Color theArray[84] PROGMEM =
{
  {"IndianRed", 205, 92, 92},
  {"LightCoral", 240, 128, 128},
  {"Salmon", 250, 128, 114},
  {"DarkSalmon", 233, 150, 122},
  {"LightSalmon", 255, 160, 122},
  {"Crimson", 220, 20, 60},
  {"Red", 255, 0, 0},
  {"FireBrick", 178, 34, 34},
  {"DarkRed", 139, 0, 0},
  {"Pink", 255, 192, 203},
  {"HotPink", 255, 105, 180},
  {"DeepPink", 255, 20, 147},
  {"MediumVioletRed", 199, 21, 133},
  {"PaleVioletRed", 219, 112, 147},
  {"Coral", 255, 127, 80},
  {"Tomato", 255, 99, 71},
  {"OrangeRed", 255, 69, 0},
  {"DarkOrange", 255, 140, 0},
  {"Orange", 255, 165, 0},
  {"Gold", 255, 215, 0},
  {"Yellow", 255, 255, 0},
  {"LightGoldenrodYellow", 250, 250, 210},
  {"Moccasin", 255, 228, 181},
  {"PeachPuff", 255, 218, 185},
  {"PaleGoldenrod", 238, 232, 170},
  {"Khaki", 240, 230, 140},
  {"DarkKhaki", 189, 183, 107},
  {"Lavender", 230, 230, 250},
  {"Thistle", 216, 191, 216},
  {"Violet", 238, 130, 238},
  {"Orchid", 218, 112, 214},
  {"Magenta", 255, 0, 255},
  {"MediumOrchid", 186, 85, 211},
  {"MediumPurple", 147, 112, 219},
  {"RebeccaPurple", 102, 51, 153},
  {"BlueViolet", 138, 43, 226},
  {"DarkViolet", 148, 0, 211},
  {"DarkOrchid", 153, 50, 204},
  {"DarkMagenta", 139, 0, 139},
  {"Purple", 128, 0, 128},
  {"Indigo", 75, 0, 130},
  {"SlateBlue", 106, 90, 205},
  {"DarkSlateBlue", 72, 61, 139},
  {"MediumSlateBlue", 123, 104, 238},
  {"GreenYellow", 173, 255, 47},
  {"LawnGreen", 124, 252, 0},
  {"Lime", 0, 255, 0},
  {"LimeGreen", 50, 205, 50},
  {"LightGreen", 144, 238, 144},
  {"SpringGreen", 0, 255, 127},
  {"SeaGreen", 46, 139, 87},
  {"ForestGreen", 34, 139, 34},
  {"Green", 0, 128, 0},
  {"DarkGreen", 0, 100, 0},
  {"YellowGreen", 154, 205, 50},
  {"OliveDrab", 107, 142, 35},
  {"Olive", 128, 128, 0},
  {"MediumAquamarine", 102, 205, 170},
  {"DarkSeaGreen", 143, 188, 139},
  {"Aqua", 0, 255, 255},
  {"Cyan", 0, 255, 255},
  {"LightCyan", 224, 255, 255},
  {"PaleTurquoise", 175, 238, 238},
  {"Turquoise", 64, 224, 208},
  {"DarkTurquoise", 0, 206, 209},
  {"CadetBlue", 95, 158, 160},
  {"LightBlue", 173, 216, 230},
  {"DodgerBlue", 30, 144, 255},
  {"RoyalBlue", 65, 105, 225},
  {"Blue", 0, 0, 255},
  {"DarkBlue", 0, 0, 139},
  {"MidnightBlue", 25, 25, 112},
  {"Brown", 165, 42, 42},
  {"Maroon", 128, 0, 0},
  {"White", 255, 255, 255},
  {"AntiqueWhite", 250, 235, 215},
  {"LightGray", 211, 211, 211},
  {"Silver", 192, 192, 192},
  {"DarkGray", 169, 169, 169},
  {"Gray", 128, 128, 128},
  {"LightSlateGray", 119, 136, 153},
  {"SlateGray", 112, 128, 144},
  {"DarkSlateGray", 47, 79, 79},
  {"Black", 0, 0, 0}
};

void setup()
{
  Serial.begin(115200);
  delay(200);
  Serial.println();

  for (int color = 0; color < 84; color++)
  {
    Serial.print(color);
    Serial.print(": ");
    Serial.print((__FlashStringHelper*)&theArray[color].Name);
    Serial.print(' ');
    Serial.print(pgm_read_byte(&theArray[color].R));
    Serial.print(' ');
    Serial.print(pgm_read_byte(&theArray[color].G));
    Serial.print(' ');
    Serial.println(pgm_read_byte(&theArray[color].B));
  }
}

void loop() {}

See how you have to use special functions when working with data in PROGMEM? The compiler doesn't keep track of what data is where so it's up to you to remember. The "__FlashStringHelper *" is a data type whose sole purpose is to tell the .print() and .println() functions that it is getting a character pointer that points to a string in PROGMEM. It is used by the "F()" macro but we can use it here to get our string to print directly from PROGMEM. Pretty much anything else you want to do with data in PROGMEM will require you to call a special function that knows that the data is in PROGMEM.

2 Likes

Here is another webpage explaining PROGMEM: Putting constant data into program memory

Storing text can get a bit complicated if you want to minimize the memory used and the length of the text varies. A common technique is to store the text in individual char arrays in PROGMEM, then store a pointer to the text array in your array.

struct Color
{
  const char* Name; //pointer to where text is stored
  byte R;
  byte G;
  byte B;
};

const char text_IndianRed[] PROGMEM = "IndianRed";
const char text_LightCoral[] PROGMEM = "LightCoral";
const char text_Salmon[] PROGMEM = "Salmon";
const char text_DarkSalmon[] PROGMEM = "DarkSalmon";
const char text_LightSalmon[] PROGMEM = "LightSalmon";
const char text_Crimson[] PROGMEM = "Crimson";
const char text_Red[] PROGMEM = "Red";
const char text_FireBrick[] PROGMEM = "FireBrick";
const char text_DarkRed[] PROGMEM = "DarkRed";
const char text_Pink[] PROGMEM = "Pink";
const char text_HotPink[] PROGMEM = "HotPink";
const char text_DeepPink[] PROGMEM = "DeepPink";
const char text_MediumVioletRed[] PROGMEM = "MediumVioletRed";
const char text_PaleVioletRed[] PROGMEM = "PaleVioletRed";
const char text_Coral[] PROGMEM = "Coral";
const char text_Tomato[] PROGMEM = "Tomato";
const char text_OrangeRed[] PROGMEM = "OrangeRed";
const char text_DarkOrange[] PROGMEM = "DarkOrange";
const char text_Orange[] PROGMEM = "Orange";
const char text_Gold[] PROGMEM = "Gold";
const char text_Yellow[] PROGMEM = "Yellow";
const char text_LightGoldenrodYellow[] PROGMEM = "LightGoldenrodYellow";
const char text_Moccasin[] PROGMEM = "Moccasin";
const char text_PeachPuff[] PROGMEM = "PeachPuff";
const char text_PaleGoldenrod[] PROGMEM = "PaleGoldenrod";
const char text_Khaki[] PROGMEM = "Khaki";
const char text_DarkKhaki[] PROGMEM = "DarkKhaki";
const char text_Lavender[] PROGMEM = "Lavender";
const char text_Thistle[] PROGMEM = "Thistle";
const char text_Violet[] PROGMEM = "Violet";
const char text_Orchid[] PROGMEM = "Orchid";
const char text_Magenta[] PROGMEM = "Magenta";
const char text_MediumOrchid[] PROGMEM = "MediumOrchid";
const char text_MediumPurple[] PROGMEM = "MediumPurple";
const char text_RebeccaPurple[] PROGMEM = "RebeccaPurple";
const char text_BlueViolet[] PROGMEM = "BlueViolet";
const char text_DarkViolet[] PROGMEM = "DarkViolet";
const char text_DarkOrchid[] PROGMEM = "DarkOrchid";
const char text_DarkMagenta[] PROGMEM = "DarkMagenta";
const char text_Purple[] PROGMEM = "Purple";
const char text_Indigo[] PROGMEM = "Indigo";
const char text_SlateBlue[] PROGMEM = "SlateBlue";
const char text_DarkSlateBlue[] PROGMEM = "DarkSlateBlue";
const char text_MediumSlateBlue[] PROGMEM = "MediumSlateBlue";
const char text_GreenYellow[] PROGMEM = "GreenYellow";
const char text_LawnGreen[] PROGMEM = "LawnGreen";
const char text_Lime[] PROGMEM = "Lime";
const char text_LimeGreen[] PROGMEM = "LimeGreen";
const char text_LightGreen[] PROGMEM = "LightGreen";
const char text_SpringGreen[] PROGMEM = "SpringGreen";
const char text_SeaGreen[] PROGMEM = "SeaGreen";
const char text_ForestGreen[] PROGMEM = "ForestGreen";
const char text_Green[] PROGMEM = "Green";
const char text_DarkGreen[] PROGMEM = "DarkGreen";
const char text_YellowGreen[] PROGMEM = "YellowGreen";
const char text_OliveDrab[] PROGMEM = "OliveDrab";
const char text_Olive[] PROGMEM = "Olive";
const char text_MediumAquamarine[] PROGMEM = "MediumAquamarine";
const char text_DarkSeaGreen[] PROGMEM = "DarkSeaGreen";
const char text_Aqua[] PROGMEM = "Aqua";
const char text_Cyan[] PROGMEM = "Cyan";
const char text_LightCyan[] PROGMEM = "LightCyan";
const char text_PaleTurquoise[] PROGMEM = "PaleTurquoise";
const char text_Turquoise[] PROGMEM = "Turquoise";
const char text_DarkTurquoise[] PROGMEM = "DarkTurquoise";
const char text_CadetBlue[] PROGMEM = "CadetBlue";
const char text_LightBlue[] PROGMEM = "LightBlue";
const char text_DodgerBlue[] PROGMEM = "DodgerBlue";
const char text_RoyalBlue[] PROGMEM = "RoyalBlue";
const char text_Blue[] PROGMEM = "Blue";
const char text_DarkBlue[] PROGMEM = "DarkBlue";
const char text_MidnightBlue[] PROGMEM = "MidnightBlue";
const char text_Brown[] PROGMEM = "Brown";
const char text_Maroon[] PROGMEM = "Maroon";
const char text_White[] PROGMEM = "White";
const char text_AntiqueWhite[] PROGMEM = "AntiqueWhite";
const char text_LightGray[] PROGMEM = "LightGray";
const char text_Silver[] PROGMEM = "Silver";
const char text_DarkGray[] PROGMEM = "DarkGray";
const char text_Gray[] PROGMEM = "Gray";
const char text_LightSlateGray[] PROGMEM = "LightSlateGray";
const char text_SlateGray[] PROGMEM = "SlateGray";
const char text_DarkSlateGray[] PROGMEM = "DarkSlateGray";
const char text_Black[] PROGMEM = "Black";


const Color theArray[84] PROGMEM =
{
  {text_IndianRed, 205, 92, 92},
  {text_LightCoral, 240, 128, 128},
  {text_Salmon, 250, 128, 114},
  {text_DarkSalmon, 233, 150, 122},
  {text_LightSalmon, 255, 160, 122},
  {text_Crimson, 220, 20, 60},
  {text_Red, 255, 0, 0},
  {text_FireBrick, 178, 34, 34},
  {text_DarkRed, 139, 0, 0},
  {text_Pink, 255, 192, 203},
  {text_HotPink, 255, 105, 180},
  {text_DeepPink, 255, 20, 147},
  {text_MediumVioletRed, 199, 21, 133},
  {text_PaleVioletRed, 219, 112, 147},
  {text_Coral, 255, 127, 80},
  {text_Tomato, 255, 99, 71},
  {text_OrangeRed, 255, 69, 0},
  {text_DarkOrange, 255, 140, 0},
  {text_Orange, 255, 165, 0},
  {text_Gold, 255, 215, 0},
  {text_Yellow, 255, 255, 0},
  {text_LightGoldenrodYellow, 250, 250, 210},
  {text_Moccasin, 255, 228, 181},
  {text_PeachPuff, 255, 218, 185},
  {text_PaleGoldenrod, 238, 232, 170},
  {text_Khaki, 240, 230, 140},
  {text_DarkKhaki, 189, 183, 107},
  {text_Lavender, 230, 230, 250},
  {text_Thistle, 216, 191, 216},
  {text_Violet, 238, 130, 238},
  {text_Orchid, 218, 112, 214},
  {text_Magenta, 255, 0, 255},
  {text_MediumOrchid, 186, 85, 211},
  {text_MediumPurple, 147, 112, 219},
  {text_RebeccaPurple, 102, 51, 153},
  {text_BlueViolet, 138, 43, 226},
  {text_DarkViolet, 148, 0, 211},
  {text_DarkOrchid, 153, 50, 204},
  {text_DarkMagenta, 139, 0, 139},
  {text_Purple, 128, 0, 128},
  {text_Indigo, 75, 0, 130},
  {text_SlateBlue, 106, 90, 205},
  {text_DarkSlateBlue, 72, 61, 139},
  {text_MediumSlateBlue, 123, 104, 238},
  {text_GreenYellow, 173, 255, 47},
  {text_LawnGreen, 124, 252, 0},
  {text_Lime, 0, 255, 0},
  {text_LimeGreen, 50, 205, 50},
  {text_LightGreen, 144, 238, 144},
  {text_SpringGreen, 0, 255, 127},
  {text_SeaGreen, 46, 139, 87},
  {text_ForestGreen, 34, 139, 34},
  {text_Green, 0, 128, 0},
  {text_DarkGreen, 0, 100, 0},
  {text_YellowGreen, 154, 205, 50},
  {text_OliveDrab, 107, 142, 35},
  {text_Olive, 128, 128, 0},
  {text_MediumAquamarine, 102, 205, 170},
  {text_DarkSeaGreen, 143, 188, 139},
  {text_Aqua, 0, 255, 255},
  {text_Cyan, 0, 255, 255},
  {text_LightCyan, 224, 255, 255},
  {text_PaleTurquoise, 175, 238, 238},
  {text_Turquoise, 64, 224, 208},
  {text_DarkTurquoise, 0, 206, 209},
  {text_CadetBlue, 95, 158, 160},
  {text_LightBlue, 173, 216, 230},
  {text_DodgerBlue, 30, 144, 255},
  {text_RoyalBlue, 65, 105, 225},
  {text_Blue, 0, 0, 255},
  {text_DarkBlue, 0, 0, 139},
  {text_MidnightBlue, 25, 25, 112},
  {text_Brown, 165, 42, 42},
  {text_Maroon, 128, 0, 0},
  {text_White, 255, 255, 255},
  {text_AntiqueWhite, 250, 235, 215},
  {text_LightGray, 211, 211, 211},
  {text_Silver, 192, 192, 192},
  {text_DarkGray, 169, 169, 169},
  {text_Gray, 128, 128, 128},
  {text_LightSlateGray, 119, 136, 153},
  {text_SlateGray, 112, 128, 144},
  {text_DarkSlateGray, 47, 79, 79},
  {text_Black, 0, 0, 0}
};

void setup()
{
  Serial.begin(115200);
  delay(200);
  Serial.println();

  for (int color = 0; color < 84; color++)
  {
    Serial.print(color);
    Serial.print(": ");
    Serial.print((__FlashStringHelper*)pgm_read_ptr(&theArray[color].Name));
    Serial.print(' ');
    Serial.print(pgm_read_byte(&theArray[color].R));
    Serial.print(' ');
    Serial.print(pgm_read_byte(&theArray[color].G));
    Serial.print(' ');
    Serial.println(pgm_read_byte(&theArray[color].B));
  }
}

void loop() {}

Is Color also a datatype? Sorry, but i am new to coding. Thanks

Yes, struct is like class in that respect.

@nousernameavailable Note the use of 'pgm_read_ptr()' to get the pointer to the string out of the struct in PROGMEM and the use of '(__FlashStringHelper *)' to tell .print() that the pointer points into PROGMEM.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.