DOS BOTONES DE ENCENDIDO Y APAGADO DE DOS LED'S DISTINTOS

 byte anterior1 = 0;

byte anterior2 = 0;
byte nuevo1;
byte nuevo2;
byte LED1 = LOW;
byte LED2 = LOW;

void setup() {
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(4,INPUT);
  pinMode(3,INPUT);

}

void loop() {
 
nuevo1=digitalRead(4);
nuevo2=digitalRead(3);
 
  if (anterior1 == 0) {
    if (nuevo1==1){
    cambiar_estado_led1();
   
  }}
  anterior1=nuevo1;
  delay(10);
 if (anterior2 == 0) {
    if (nuevo2==1){
    cambiar_estado_led2();
   
  }}
  anterior2=nuevo2;
  delay(10);
}
void cambiar_estado_led1(){
  if(LED1==LOW){
    digitalWrite(13,HIGH);
    LED1=HIGH;
  }
  else{
    digitalWrite(13,LOW);
    LED1=LOW;
  }
}
void cambiar_estado_led2(){
   if(LED2==LOW){
    digitalWrite(12,HIGH);
    LED2=HIGH;
  }
  else{
    digitalWrite(12,LOW);
    LED2=LOW;
  }
}

No hay comentarios:

Publicar un comentario