EEPROM.read ledstate

Hello all!

I need a little help. On my nano, have two led (pin10, pin12).
I want to store the actual ledstate in the eeprom.
1 = led1 High, led2 Low
2 = led1 Low, led2 High

The data is stored, when turn on the arduino nano, serialprint the latest led state (1 or 2), but the led stay on Low.

There is my beginner code:

#include <EEPROM.h>

int ledpin1 = 10;
int ledpin2 = 12;
int val;
int val2;
int addr = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(ledpin1, OUTPUT);
  pinMode(ledpin2, OUTPUT);
  EEPROM.read(addr);
  Serial.println(EEPROM.read(addr));

    val2 = EEPROM.read(addr);
    if (val2 == '1')               
  {
    digitalWrite(ledpin1, HIGH);
    digitalWrite(ledpin2, LOW);
  }
      if (val2 == '2')               
  {
    digitalWrite(ledpin2, HIGH);
    digitalWrite(ledpin1, LOW);
  }
}

void loop(){
  if (Serial.available()>0)
  {
  setLed();
  }
}

void setLed(){
    val = Serial.read();
    if (val == '1')               
  {
    digitalWrite(ledpin1, HIGH);
    digitalWrite(ledpin2, LOW);
    EEPROM.write(addr, 1);
    Serial.println(EEPROM.read(addr));
  }
      if (val == '2')               
  {
    digitalWrite(ledpin2, HIGH);
    digitalWrite(ledpin1, LOW);
    EEPROM.write(addr, 2);
    Serial.println(EEPROM.read(addr));
   }
}

What went wrong?

Thanks

For a start, since you declared val and val2 as int, I think you should lose the quotes:

  if (val2 == '1') 

// as opposed to

  if (val2 == 1)

Ahh, thank you!

Its working now.

doh.jpg