Skip to content

Instantly share code, notes, and snippets.

@hhayley
Created October 13, 2016 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhayley/6926e17745dba4e7e7f0a0b16a18de2a to your computer and use it in GitHub Desktop.
Save hhayley/6926e17745dba4e7e7f0a0b16a18de2a to your computer and use it in GitHub Desktop.
#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