How to store lcd RGB color

Hi guys
I have an RGB one button color selector.It simply read an analog button count and return value from 1-6 ( colors).
Now every time you reset your Arduino , color comes back to default.
How to store/retrieve count number so after reset the color would as before reset.

void loop()
{
 if(count==1)setColor(255,255, 0);// yellow
 
 if(count==2)setColor(0, 255, 255);//aqua
 
 if(count==3)setColor(80, 0, 80);//pirple
 
 if(count==4)setColor(255, 0, 0);//red
 
 if(count==5)setColor(0, 255, 0);//grean
 
 if(count==6)setColor(0, 0, 255);//blue
 ButtonState = digitalRead(Button);

 if(ButtonState && ButtonState != lastState)  // button latch, no debounce needed!!!!!
 {
   if(count < 6) // This will check to see if the count is within a range of 1 - 6, and anything over that, it will reset count back to 1. 
     count += 1; // same as count = count + 1;
   else
     count = 1;
   
   Serial.println(count);
 } 
 lastState = ButtonState;

Look at using EEPROM?

ok. i`m on it. Can you please tell me how to tack code instead of copy/paste?

In the Post Reply window there are buttons to change the text. You select the text you want to change like for copy and then click the button. Hold the mouse over each button and a tool tip tells what it is.

The B button makes Bold text. On the right side is a button that looks like a paper page with an ellipse, the name is Code. Next to the right is 'Insert a Quote'.

Paste your code then select it and click the Code button.

Done. thank you

mOskit:
Hi guys
I have an RGB one button color selector.It simply read an analog button count and return value from 1-6 ( colors).
Now every time you reset your Arduino , color comes back to default.
How to store/retrieve count number so after reset the color would as before reset.

void loop()

{
 if(count==1)setColor(255,255, 0);// yellow
 
 if(count==2)setColor(0, 255, 255);//aqua
 
 if(count==3)setColor(80, 0, 80);//pirple
 
 if(count==4)setColor(255, 0, 0);//red
 
 if(count==5)setColor(0, 255, 0);//grean
 
 if(count==6)setColor(0, 0, 255);//blue
 ButtonState = digitalRead(Button);

if(ButtonState && ButtonState != lastState)  // button latch, no debounce needed!!!
 {
   if(count < 6) // This will check to see if the count is within a range of 1 - 6, and anything over that, it will reset count back to 1.
     count += 1; // same as count = count + 1;
   else
     count = 1;
   
   Serial.println(count);
 }
 lastState = ButtonState;

if(ButtonState && ButtonState != lastState) // button latch, no debounce needed!!!

1st – would be more clear as

if (ButtonState && (ButtonState != lastState)) // button latch, no debounce needed!!!

2nd – if the latch is not a hardware debounce in the physical button, this is not a debounce.

Here is a sketch that shows bounce. Because it prints, it may miss some but it shows.

// bounce --- ground the jumper as a dirty button and see bounce
// some buttons are just as dirty, especially with a hard press
// serial monitor will show the pin state
// every second with no change an empty line is printed

// it is possible to get 1 change per contact and break but no guarantee
// if this demo was not printing at all, you would see more bounces

byte jumperPin = 7; // using an UNO and a jumper I ground on the USB.
byte lastState;

unsigned long tStart, tWait = 1000UL; // wait is 1 second

void setup( void )
{
  Serial.begin( 115200 );
  Serial.println( "\nserial connected..." );
  pinMode( jumperPin, INPUT_PULLUP );
}

void loop( void )
{
  if ( lastState != digitalRead( jumperPin ))
  {
    lastState ^= 1;
    tStart = millis();
    Serial.println( lastState );
 }
  
// print a new line every tWait millis without change
  if ( millis() - tStart >= tWait ) 
  {
    Serial.println();
    tStart = millis();
  }
}

When I debounce, I look for the pin to have the same state for some number of milliseconds. For some buttons as few as 2 or 5 millis is enough to declare stability, for some, 20 ms.

No bounce buttons can be made with leds and detectors or piezo discs or conductive surfaces like foil.

IR led points up with detector close pointing crossways. IR light reflects off the close finger, switch ON. Never seen one bounce.

The others are trickier.

Hi
I have managed to store my data to eeprom, and every reset i know the data is there.
But i`m struggle with EEPROm.read and using it as defult color.
Any suggestions?

#include "ST7565.h"
#include <EEPROM.h>



int redPin = 12;
int greenPin = 11;
int bluePin = 10;
const byte Button = A0;
byte ButtonState;
byte lastState = LOW;
byte count = 0;

int hold = 0;
int holdTime = 1500;
int lastReading = LOW;
long onTime = 0;


ST7565 glcd(9, 8, 7, 6, 5);

#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 

// a bitmap of a 16x16 fruit icon
static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00, 
0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };

void setup() {
 Serial.begin(9600);
 
 EEPROM.read(10);
 Serial.println(EEPROM.read(10));
 EEPROM.read(10) == count;
   
 
 
 
 
 pinMode(Button, INPUT);
 pinMode(redPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
 pinMode(bluePin, OUTPUT);  
 
 // initialize and set the contrast to 0x18
 glcd.begin(0x18);

 glcd.display(); // show splashscreen
 delay(2000);
 glcd.clear();
}

void loop() {
 
 
 ButtonState = digitalRead(Button);

 if(ButtonState && (ButtonState != lastState))  // button latch, no debounce needed!!!!!
 {
   if(count < 6) // This will check to see if the count is within a range of 0 - 9, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
     count += 1; // same as count = count + 1;
   else
     count = 1;
   Serial.println(count);
 } 
 lastState = ButtonState;

 if(count==1)setColor(255, 0, 0);  // red
 
 if(count==2)setColor(0, 255, 0);  // green
 
 if(count==3)setColor(0, 0, 255);  // blue
 
 if(count==4)setColor(255, 255, 0);  // yellow
   
 if(count==5)setColor(80, 0, 80);  // purple
 
 if(count==6)setColor(0, 255, 255);  // aqua
 
 //storing color to eeprom
 if(ButtonState == HIGH ) {
     EEPROM.write(10,count);
    }
}

void setColor(int red, int green, int blue)
{
 
   red = 255 - red;
   green = 255 - green;
   blue = 255 - blue;
 
 analogWrite(redPin, red);
 analogWrite(greenPin, green);
 analogWrite(bluePin, blue);  
}

Got it. count = EEPROM.read(10);

But,say i have red color preset in eeprom. each time you reset the color is white(default i guess), and after a second the correct color appears.

Any suggestions?

Run setColor() after the pin modes are set in setup(). The PWM doesn't start until analogWrite() is run.

i did setColor(0,0,0);
Does work but now the RGB starts around 1500ms after lcd.
Can i do anything to synchronize it somehow?
thanks

 EEPROM.read(10);
 Serial.println(EEPROM.read(10));
 EEPROM.read(10) == count;

Read a value. Throw it away. Read the same value, and print it. Read the same value a third time, and compare the value to count. Throw away the result of the comparison.

All seems rather pointless to me.