jueves, 11 de noviembre de 2010

PROGRAMA DE ARDUINO PARA ENCENDER UN LED CON BOTON

Este es un programa del arduino para poder encender cada q oprimes 5 veces un boton, un led y despues de volver a oprimir 5 veces se apaga.


/*
  DigitalReadSerial
 Reads a digital input on pin 2, prints the result to the serial monitor 
 */
 int cont=0;
 int x=2;


void setup() {
  Serial.begin(9600);
  pinMode(40, INPUT);
  pinMode(50,OUTPUT);
}


void loop() {
  int sensorValue = digitalRead(40);
  Serial.println(sensorValue, DEC);
  if (sensorValue==1){
    delay (250);
    cont=cont+1;
  }
  if (cont==5){
    if (x%2==0){
      digitalWrite(50,LOW);
    }
    else{
      digitalWrite (50,HIGH);
    }
    x=x+1;
    cont=0;    
  }  
}

No hay comentarios:

Publicar un comentario