How to save on/off state EEPROM from TTP223B CAPACITIVE TOUCH SENSOR?

this is my code. how to store TOUCH SENSOR state . i want to on/off bulb using EEPROM data with touch sensor state.

#define TouchSensor 9 // Pin for capactitive touch sensor
 
int relay = 8; 

boolean currentState = LOW;
boolean lastState = LOW;
boolean RelayState = LOW;
 
void setup() {
  Serial.begin(9600);
  pinMode(relay, OUTPUT);  
  pinMode(TouchSensor, INPUT);
}
 
void loop() {
  currentState = digitalRead(TouchSensor);
    if (currentState == HIGH && lastState == LOW){
    Serial.println("pressed");
    delay(1);
    
    if (RelayState == HIGH){
      digitalWrite(relay, LOW);
      RelayState = LOW;
    } else {
      digitalWrite(relay, HIGH);
      RelayState = HIGH;
    }
  }
  lastState = currentState;
}

Are you sure you want to use the onboard EEPROM with the touch sensor? Why? what exactly are you trying to do?

If you do want to use the EEPROM, there are many examples that come with the IDE (File -> Examples -> EEPROM) that will show you how to use it. You can treat it like an array.

Boolean are designed to be either true or false, not LOW (nor HIGH)

boolean currentState = LOW;
boolean lastState = LOW;
boolean RelayState = LOW;

i just remember touch switch on/off state. when power gone

i used this code but doesn't work.

#include <EEPROM.h>
int buttonState = 0; 

void setup() {
              pinMode(0, INPUT); // TTP223B  CAPACITIVE TOUCH SENSOR
              pinMode(1, OUTPUT); //relay
            }


void loop() {
            
 
            int address0=0;
            int state0;

            
            
            buttonState = digitalRead(0);
 
            if (buttonState == HIGH) {
                  state0 = 0;
                  EEPROM.write(address0, state0);
                 
            
                }
            
            else{
                state0 = 1;
                EEPROM.write(address0, state0);
                
            
                }

                
                if(EEPROM.read(0) == 0){digitalWrite(1, LOW); }
                else if(EEPROM.read(0) == 1){digitalWrite(1, HIGH); }
    
delay(1);
        }

"doesn't work" is the worst possible description for describing a problem. What do you expect the code to do? What is it doing that you don't want?

Also, it's best not to use pin 0 and pin 1 since those are the tx/rx pins for the serial monitor. It can be really useful to print out debugging messages and variables and all sorts of valuable information.

If you are just saving the state of a button (0/1) then you can access EEPROM memory as if it is an array of bytes:

EEPROM[address0] = state0;
state0 = EEPROM[address0];

Note that the number of times you can write to a given location in EEPROM is something like 100k writes. It sounds like a lot, but if you doing it every time through loop(), you will get there quickly.

thanks