add light sensor and use enum for device IDs
This commit is contained in:
parent
310997529b
commit
ab93e5e28a
@ -2,3 +2,11 @@
|
|||||||
|
|
||||||
#include <ContactSensor.h>
|
#include <ContactSensor.h>
|
||||||
#include <TempSensor.h>
|
#include <TempSensor.h>
|
||||||
|
|
||||||
|
enum SensorId : int {
|
||||||
|
WINDOW1 = 1,
|
||||||
|
WINDOW2 = 2,
|
||||||
|
WATER_SENSOR = 3,
|
||||||
|
TEMP_SENSOR = 4,
|
||||||
|
LIGHT_SENSOR = 5
|
||||||
|
};
|
||||||
|
|||||||
32
light_sensor/light_sensor.ino
Normal file
32
light_sensor/light_sensor.ino
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "Arduino.h"
|
||||||
|
#include <TinyPower.h>
|
||||||
|
#include <Tiny.h>
|
||||||
|
|
||||||
|
// Pins
|
||||||
|
#define SWITCH 0
|
||||||
|
#define SENDER 2
|
||||||
|
|
||||||
|
ContactSensor sensor = ContactSensor(LIGHT_SENSOR, SENDER);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(SWITCH, INPUT_PULLUP);
|
||||||
|
|
||||||
|
sensor.setup();
|
||||||
|
|
||||||
|
sensor.sendStateAndVoltage(readState());
|
||||||
|
|
||||||
|
TinyPower::setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
TinyPower::sleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean readState() {
|
||||||
|
return digitalRead(SWITCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(PCINT0_vect) {
|
||||||
|
sensor.sendStateAndVoltage(!readState());
|
||||||
|
}
|
||||||
@ -8,15 +8,13 @@
|
|||||||
#define SENDER 1
|
#define SENDER 1
|
||||||
#define TEMP_PIN A1
|
#define TEMP_PIN A1
|
||||||
|
|
||||||
#define SENSOR_ID 4
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define RxD 3
|
#define RxD 3
|
||||||
#define TxD 4
|
#define TxD 4
|
||||||
SoftwareSerial AttinySerial(RxD, TxD);
|
SoftwareSerial AttinySerial(RxD, TxD);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TempSensor sensor = TempSensor(SENSOR_ID, SENDER);
|
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
|
|||||||
@ -6,9 +6,7 @@
|
|||||||
#define SENDER 2
|
#define SENDER 2
|
||||||
#define CONTROLLER 4
|
#define CONTROLLER 4
|
||||||
|
|
||||||
#define SENSOR_ID 3
|
ContactSensor sensor = ContactSensor(WATER_SENSOR, SENDER);
|
||||||
|
|
||||||
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
|
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,8 @@
|
|||||||
#define SWITCH 0
|
#define SWITCH 0
|
||||||
#define SENDER 2
|
#define SENDER 2
|
||||||
#define CONTROLLER 4
|
#define CONTROLLER 4
|
||||||
#define SENSOR_ID 1
|
|
||||||
|
|
||||||
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
|
ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
bool currentState;
|
bool currentState;
|
||||||
|
|||||||
@ -4,9 +4,8 @@
|
|||||||
// Pins
|
// Pins
|
||||||
#define SWITCH 0
|
#define SWITCH 0
|
||||||
#define SENDER 2
|
#define SENDER 2
|
||||||
#define SENSOR_ID 2
|
|
||||||
|
|
||||||
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
|
ContactSensor sensor = ContactSensor(WINDOW2, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
bool currentState;
|
bool currentState;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user