Skip to content

Instantly share code, notes, and snippets.

@giljr
Created September 9, 2018 01:34
Show Gist options
  • Save giljr/d2ef699aa3d22a4e570b9c355e688c44 to your computer and use it in GitHub Desktop.
Save giljr/d2ef699aa3d22a4e570b9c355e688c44 to your computer and use it in GitHub Desktop.
class PIR {
private:
int _ledPin;
int _pirPin;
int _pirState;
public:
void PIR_Setup(int ledPin, int pirPin, int pirState) {
_ledPin = ledPin;
_pirPin = pirPin;
_pirState = pirState;
pinMode(ledPin, OUTPUT); //PIR Setup
pinMode(pirPin, INPUT);
}
void PIR_Loop() {
int pirValue = digitalRead(_pirPin); //PIR Loop
if (pirValue == HIGH) { // check if the input is HIGH
digitalWrite(_ledPin, HIGH); // turn LED ON
if (_pirState == LOW) {
_pirState = HIGH;
}
} else {
digitalWrite(_ledPin, LOW); // turn LED OFF
//lcd.print("Motion ended! ");
_pirState = LOW;
}
}
void PIR_Display() {
if (_pirState == HIGH) {
lcd.print("Motion detected!");
//break;
};
if (_pirState == LOW) {
lcd.print("Motion ended! ");
//break;
}
}
};
PIR PIR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment