EEPROM of use Teensy ++ 2.0.

This code has a button, it works:

  1. If I press the button lights a "led" and "fan".
  2. Again I press the button, the fan turns off and the LED blinks every second.
  3. If djo down the button for 3 seconds, LED and fan off.
byte Pulsador  =PIN_B0; // Pines usados
byte Led       =PIN_D0; 
byte Ventilador=PIN_D1;  

#define ON HIGH        
#define OF LOW

boolean Estado_Pulsador;
boolean Estado_Anterior = false; 

boolean Led_Encendido=false;
boolean Ven_Encendido=false;

byte Secuencia = 0;            // Para manejar la secuencia de salidas

unsigned long Parpadeo=1000;  // Tiempo de parpadeo de led
unsigned long T_Anterior=0;   // Auxiliar para controlar tiempo de parpadeo

unsigned long T_Apagar=3000;  // Tiempo a pulsar para apagar
unsigned long T_Pulsado=0;    // Auxiliar para controlar tiempo de boton pulsado

void setup()
{
  pinMode(Pulsador, INPUT);       
  pinMode(Led, OUTPUT);         
  pinMode(Ventilador, OUTPUT);
  digitalWrite(Led, OF);
  digitalWrite(Ventilador, OF);
}

void loop()
{
  Estado_Pulsador = !digitalRead(Pulsador); // Lee el estado del botón. 
  delay(20);                                // Antirebotes.
  
  if (Estado_Pulsador && !Estado_Anterior) // Pulsador pasa de low a high
  {
    T_Pulsado=millis()+T_Apagar;           // Para controlar el timpo que pasa pulsado 
    Estado_Anterior=true;                  // No enta en el if hasta q pulsador pase de high a low
    Secuencia++;                           // Pasamos a siguiente secuencia
  } 
  
  if (!Estado_Pulsador && Estado_Anterior) // Pulsador pasa de high a low
  {
    Estado_Anterior=false;                 // No enta en el if hasta q pulsador pase de low a high
    T_Pulsado=0;                           // Al soltar pulsador ya no controlamos el tiempo 
  } 
  
  if (T_Pulsado>0 && Estado_Pulsador && millis()>T_Pulsado)  
  {                                        // Hay tiempo cargado para controlar el fin y pulsador en high y ha transcurrido el tiempo del pulsador activo
    T_Pulsado=0;                           // Ya no controlamos timepo de pulsado
    Secuencia=0;                           // Secuencia 0, todo apagado
  }  
  
  if (Secuencia==0)                        // Todo apagado
  {
    Led_Encendido=false;
    Ven_Encendido=false;
    T_Anterior=0;                          // Para que pueda funcionar el parpadeo de nuevo
  }
  else if (Secuencia==1)                   // Pulsamos por 1ª vez, todo encendido
    {
      Led_Encendido=true;
      Ven_Encendido=true;
    }
    else if (Secuencia==2)                 // Pulsamos por 2ª vez, Apaga ventilador y led parpadea
      {
        Ven_Encendido=false;        
        if (millis()>T_Anterior)           // Tiempo parpadeo finalizado
        {
          T_Anterior=millis() + Parpadeo;// Tiempo a esperar para siguiente parpadeo
          Led_Encendido=!Led_Encendido;  // de encendido a apagado y viceversa
        }           
      }
      else {Secuencia=1; }    

  if (Led_Encendido) {digitalWrite(Led, ON);} else {digitalWrite(Led, OF);}
  if (Ven_Encendido) {digitalWrite(Ventilador, ON);} else {digitalWrite(Ventilador, OF);}   
}

What I want is stored in EEPROM and any status Led ventidador when Teensy + + 2.0 loses power. When you turn Teensy + + 2.0 automatically retrieves the saved state of Led and fan.

You have to modify the code but do not.

Any help?

Greeting.

PD: Sorry if this topic does not go here.

What I want is stored in EEPROM and any status Led ventidador when Teensy + + 2.0 loses power.

When the Teensy looses power, it stops. It can't, while unpowered, store data in EEPROM. You need to monitor power, and detect when the main power is lost AND you need to provide backup power that kicks in immediately, so that the Teensy has time to store the data.

That isn't a programming issue, as such.

This system will do more adente, it's about electronics.

In my case, every time I press a button, I want the output of the Teensy is saved to the EEPROM. So much goes Teensy, do not lose data.

In my case, every time I press a button, I want the output of the Teensy is saved to the EEPROM.

So, what's the problem? Go right ahead and do that.