add movemnt sensor for basement
This commit is contained in:
parent
777afc43d7
commit
8c52520ab0
32
movement_sensor/movement_sensor.ino
Normal file
32
movement_sensor/movement_sensor.ino
Normal file
@ -0,0 +1,32 @@
|
||||
#include <Tiny.h>
|
||||
#include <SoftwareSerial_Tiny.h>
|
||||
#include <TinyPower.h>
|
||||
|
||||
// Pins
|
||||
#define MOVEMENT_PIN PCINT2
|
||||
#define SENDER 4
|
||||
|
||||
ContactSensor sensor = ContactSensor(MOVEMENT_SENSOR, SENDER);
|
||||
|
||||
volatile bool shouldSend = false;
|
||||
|
||||
void setup() {
|
||||
|
||||
pinMode(MOVEMENT_PIN, INPUT_PULLUP);
|
||||
sensor.setup();
|
||||
TinyPower::setup();
|
||||
PCMSK |= (1 << MOVEMENT_PIN);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (shouldSend) {
|
||||
shouldSend = false;
|
||||
int currentState = digitalRead(MOVEMENT_PIN);
|
||||
sensor.sendState(!currentState);
|
||||
}
|
||||
TinyPower::sleep();
|
||||
}
|
||||
|
||||
ISR(PCINT0_vect) {
|
||||
shouldSend = true;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user