0

Trying to save my LED-State to EEPROM.

After every 5 seconds my EEPROM saves the value of white in this example (didn't put in RGB yet)

When the EEPROM gets commited and the value changes the LED is dark for a few milliseconds

what can I do?

int xInt = wVal.toInt();
white_val = xInt;
controlLed(whitePin, xInt);

Triggers LED:

void controlLed(int pin, int integer) {
  analogWrite(pin, integer); 
  return;
}

Loop Saving Data every five seconds:

void loop() {
  static unsigned long startTemp = 0;
  unsigned long msTime = millis();

  if (msTime - startTemp >= 5000) {
    startTemp = msTime;
    writeEeprom(white_address, white_val);
  }
}

Writes Data to EEPROM:

void writeEeprom(int address, int value) {
  EEPROM.put(address, value);
  Serial.println("WRITTEN  TO EEPROM:");
  Serial.println(address);
  Serial.print("\n");
  Serial.println(value);
  Serial.print("\n");
  EEPROM.commit();

  EEPROM.get(address,value);
  Serial.println("READ  FROM EEPROM:");
  Serial.println(address);
  Serial.print("\n");
  Serial.println(value);
  Serial.print("\n");
  return;
}

migrated from stackoverflow.com Nov 15 '18 at 13:55

This question came from our site for professional and enthusiast programmers.

  • What's the GPIO number of the pin you're using to control the LED? – John Romkey Nov 13 '18 at 22:44
  • ` const int whitePin = 14; ` It's a esp8266 ESP-07 – Antax Nov 14 '18 at 7:02
  • the first snippet is from setup()? which version of esp8226 Arduino core you use? – Juraj Nov 14 '18 at 8:00
  • No the first snippet gets triggered when the value changes ` if(text.startsWith("w")){ String wVal=(text.substring(text.indexOf("w")+1,text.length())); int wInt = wVal.toInt(); white_val = wInt; controlLed(whitePin, wInt); webSocket.sendTXT(num, "white changed", lenght); } ` Latest Stable: arduino.esp8266.com/stable/package_esp8266com_index.json And Arduino 1.8.7 esp8266 has version 2.4.2 – Antax Nov 14 '18 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy