Created
October 13, 2016 18:08
-
-
Save hhayley/6926e17745dba4e7e7f0a0b16a18de2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SensorLED 13 | |
#define SensorINPUT 3 //Connect the sensor to digital Pin 3 which is Interrupts 1. | |
unsigned char state = 0; | |
int cnt = 0; | |
void setup() | |
{ | |
pinMode(SensorLED, OUTPUT); | |
pinMode(SensorINPUT, INPUT); | |
attachInterrupt(1, blink, CHANGE);// Trigger the blink function when the falling edge is detected | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
if (state != 0) | |
{ | |
state = 0; | |
cnt ++; | |
Serial.println(cnt); | |
digitalWrite(SensorLED, HIGH); | |
// delay(500); | |
} | |
else | |
digitalWrite(SensorLED, LOW); | |
delay(1); | |
} | |
void blink()//Interrupts function | |
{ | |
state++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment