add light sensor and use enum for device IDs

This commit is contained in:
Nicolae Hodos 2017-06-03 16:43:58 +02:00
parent 310997529b
commit ab93e5e28a
6 changed files with 44 additions and 10 deletions

View File

@ -2,3 +2,11 @@
#include <ContactSensor.h>
#include <TempSensor.h>
enum SensorId : int {
WINDOW1 = 1,
WINDOW2 = 2,
WATER_SENSOR = 3,
TEMP_SENSOR = 4,
LIGHT_SENSOR = 5
};

View 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());
}

View File

@ -8,15 +8,13 @@
#define SENDER 1
#define TEMP_PIN A1
#define SENSOR_ID 4
#if DEBUG
#define RxD 3
#define TxD 4
SoftwareSerial AttinySerial(RxD, TxD);
#endif
TempSensor sensor = TempSensor(SENSOR_ID, SENDER);
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
int counter = 0;

View File

@ -6,9 +6,7 @@
#define SENDER 2
#define CONTROLLER 4
#define SENSOR_ID 3
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
ContactSensor sensor = ContactSensor(WATER_SENSOR, SENDER);
int counter = 0;

View File

@ -5,9 +5,8 @@
#define SWITCH 0
#define SENDER 2
#define CONTROLLER 4
#define SENSOR_ID 1
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
int counter = 0;
bool currentState;

View File

@ -4,9 +4,8 @@
// Pins
#define SWITCH 0
#define SENDER 2
#define SENSOR_ID 2
ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER);
ContactSensor sensor = ContactSensor(WINDOW2, SENDER);
int counter = 0;
bool currentState;