Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define IR_PIN 1
- #define LED_PIN 2
- int state = 0;
- void setup()
- {
- pinMode(IR_PIN, INPUT);
- pinMode(LED_PIN, OUTPUT);
- digitalWrite(LED_PIN, LOW);
- //Serial.begin(9600);
- }
- void loop()
- {
- int startPulse, startTime, i;
- startPulse = pulseIn(IR_PIN, LOW);
- //Serial.print("startPulse = ");
- //Serial.println(startPulse);
- if(startPulse < 4500 || startPulse > 5500) //Starting pulse is 5ms
- return;
- startTime = millis();
- for(i = 1; i <= 4; i++)
- {
- int pulse = pulseIn(IR_PIN, LOW);
- //Serial.print("Pulse #");
- //Serial.print(i);
- //Serial.print(" = ");
- //Serial.println(pulse);
- if(pulse < 800 || pulse > 1200) //Each subsequent pulse is 1ms
- return;
- }
- //Serial.print("millis() - startTime = ");
- //Serial.println(millis() - startTime);
- if(millis() - startTime < 100)
- {
- state = !state;
- if(state)
- digitalWrite(LED_PIN, HIGH);
- else digitalWrite(LED_PIN, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement