use one Tiny librariy for all sensors
This commit is contained in:
parent
023859489c
commit
863e8aec99
@ -1,4 +1,5 @@
|
|||||||
#include <TinyPower.h>
|
#include <TinyPower.h>
|
||||||
|
#include <Tiny.h>
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
#include <SoftwareSerial_Tiny.h>
|
#include <SoftwareSerial_Tiny.h>
|
||||||
|
|
||||||
|
|||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
|
|
||||||
class TinySensor {
|
class ContactSensor {
|
||||||
short id;
|
short id;
|
||||||
short senderPin;
|
short senderPin;
|
||||||
RCSwitch mySwitch = RCSwitch();
|
RCSwitch mySwitch = RCSwitch();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TinySensor(short id, short senderPin) {
|
ContactSensor(short id, short senderPin) {
|
||||||
this->id = id;
|
this->id = id;
|
||||||
this->senderPin = senderPin;
|
this->senderPin = senderPin;
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ public:
|
|||||||
mySwitch.setProtocol(2);
|
mySwitch.setProtocol(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendWindowState(bool state) {
|
void sendStateAndVoltage(bool state) {
|
||||||
unsigned long value = 0x70000000;
|
unsigned long value = 0x70000000;
|
||||||
value |= readVcc() << 6;
|
value |= readVcc() << 6;
|
||||||
value |= !state << 5;
|
value |= !state << 5;
|
||||||
4
libraries/Tiny/Tiny.h
Normal file
4
libraries/Tiny/Tiny.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ContactSensor.h>
|
||||||
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
#include <TinyPower.h>
|
#include <TinyPower.h>
|
||||||
#include <TinySensor.h>
|
#include <Tiny.h>
|
||||||
|
|
||||||
// Pins
|
// Pins
|
||||||
#define SWITCH 0
|
#define SWITCH 0
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#define SENSOR_ID 3
|
#define SENSOR_ID 3
|
||||||
|
|
||||||
TinySensor sensor = TinySensor(SENSOR_ID, SENDER);
|
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ void setup() {
|
|||||||
digitalWrite(CONTROLLER, HIGH);
|
digitalWrite(CONTROLLER, HIGH);
|
||||||
|
|
||||||
sensor.setup();
|
sensor.setup();
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
|
|
||||||
TinyPower::setup();
|
TinyPower::setup();
|
||||||
TinyPower::enableWdt(WDTO_8S);
|
TinyPower::enableWdt(WDTO_8S);
|
||||||
@ -37,17 +37,17 @@ bool readState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISR(PCINT0_vect) {
|
ISR(PCINT0_vect) {
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
delay(5000);
|
delay(5000);
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(WDT_vect) {
|
ISR(WDT_vect) {
|
||||||
counter++;
|
counter++;
|
||||||
if (counter % 220 == 0) {
|
if (counter % 220 == 0) {
|
||||||
counter = 0;
|
counter = 0;
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
delay(10000);
|
delay(10000);
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#include <TinyPower.h>
|
#include <TinyPower.h>
|
||||||
#include <TinySensor.h>
|
#include <Tiny.h>
|
||||||
|
|
||||||
// Pins
|
// Pins
|
||||||
#define SWITCH 0
|
#define SWITCH 0
|
||||||
@ -7,7 +7,7 @@
|
|||||||
#define CONTROLLER 4
|
#define CONTROLLER 4
|
||||||
#define SENSOR_ID 1
|
#define SENSOR_ID 1
|
||||||
|
|
||||||
TinySensor sensor = TinySensor(SENSOR_ID, SENDER);
|
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
bool currentState;
|
bool currentState;
|
||||||
@ -21,7 +21,7 @@ void setup() {
|
|||||||
sensor.setup();
|
sensor.setup();
|
||||||
|
|
||||||
updateState();
|
updateState();
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
|
|
||||||
TinyPower::setup();
|
TinyPower::setup();
|
||||||
TinyPower::enableWdt(WDTO_8S);
|
TinyPower::enableWdt(WDTO_8S);
|
||||||
@ -40,19 +40,19 @@ byte readState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISR(PCINT0_vect) {
|
ISR(PCINT0_vect) {
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(WDT_vect) {
|
ISR(WDT_vect) {
|
||||||
bool state = readState();
|
bool state = readState();
|
||||||
if (state != currentState) {
|
if (state != currentState) {
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
updateState();
|
updateState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
if (counter % 76 == 0) {
|
if (counter % 76 == 0) {
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
#include <TinyPower.h>
|
#include <TinyPower.h>
|
||||||
#include <TinySensor.h>
|
#include <Tiny.h>
|
||||||
|
|
||||||
// Pins
|
// Pins
|
||||||
#define SWITCH 0
|
#define SWITCH 0
|
||||||
#define SENDER 2
|
#define SENDER 2
|
||||||
#define SENSOR_ID 2
|
#define SENSOR_ID 2
|
||||||
|
|
||||||
TinySensor sensor = TinySensor(SENSOR_ID, SENDER);
|
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
bool currentState;
|
bool currentState;
|
||||||
@ -18,7 +18,7 @@ void setup() {
|
|||||||
sensor.setup();
|
sensor.setup();
|
||||||
|
|
||||||
updateState();
|
updateState();
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
|
|
||||||
TinyPower::setup();
|
TinyPower::setup();
|
||||||
TinyPower::enableWdt(WDTO_8S);
|
TinyPower::enableWdt(WDTO_8S);
|
||||||
@ -37,19 +37,19 @@ byte readState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISR(PCINT0_vect) {
|
ISR(PCINT0_vect) {
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(WDT_vect) {
|
ISR(WDT_vect) {
|
||||||
bool state = readState();
|
bool state = readState();
|
||||||
if (state != currentState) {
|
if (state != currentState) {
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
updateState();
|
updateState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
if (counter % 76 == 0) {
|
if (counter % 76 == 0) {
|
||||||
sensor.sendWindowState(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user