/* Receptor IR */ #define LED 2 #define Opto 3 int Opto_lee = 0; int estadoLed = 0; int estadoAnterior = 0; void setup() { pinMode(LED,OUTPUT); pinMode(Opto,INPUT); } void loop() { Opto_lee = digitalRead(Opto); if((Opto_lee == 1)&&(estadoAnterior == 0)){ estadoLed = 1 - estadoLed ; delay(200); //AntiRebote } estadoAnterior = Opto_lee; if(estadoLed == 1){ digitalWrite(LED,HIGH); }else{ digitalWrite(LED,LOW); } }
MATERIALES
1 ARDUINO
1 VS1838B
1 Led 5mm
1 Resistencia 220 ohm
Protoboard
Jumpers
CIRCUITO
Comentario Blogger
Comentario Facebook