mirror of
https://gitlab.com/wirelos/sprocket-plugin-gpio.git
synced 2025-12-15 21:58:21 +01:00
pir plugin
This commit is contained in:
26
src/inputs/pir/PirInputPlugin.cpp
Normal file
26
src/inputs/pir/PirInputPlugin.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "PirInputPlugin.h"
|
||||
|
||||
void PirInputPlugin::checkInput()
|
||||
{
|
||||
val = digitalRead(config.pin); // read input value
|
||||
if (val == HIGH)
|
||||
{ // check if the input is HIGH
|
||||
if (pirState == LOW)
|
||||
{
|
||||
// we have just turned on
|
||||
publish(config.topic, "1");
|
||||
// We only want to print on the output change, not state
|
||||
pirState = HIGH;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pirState == HIGH)
|
||||
{
|
||||
// we have just turned of
|
||||
publish(config.topic, "0");
|
||||
// We only want to print on the output change, not state
|
||||
pirState = LOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user