Start of example conversion. Added sleep to MySensors API.

This commit is contained in:
Henrik Ekblad
2014-06-13 13:54:12 +02:00
parent d1ca16fe1b
commit af90d238d4
25 changed files with 2377 additions and 224 deletions
@@ -1,5 +1,4 @@
#include <MySensor.h>
#include <Sleep_n0m1.h>
#include <SPI.h>
#include <RF24.h>
@@ -8,15 +7,11 @@
#define CHILD_ID 1 // Id of the sensor child
MySensor gw;
Sleep sleep;
// Initialize motion message
MyMessage msg(CHILD_ID, V_TRIPPED);
void setup()
{
//eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, 1);
//eeprom_write_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, 255);
//delay(2000);
gw.begin();
// Send the sketch version information to the gateway and Controller
@@ -24,9 +19,7 @@ void setup()
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
// Register all sensors to gw (they will be created as child devices)
delay(500);
gw.present(CHILD_ID, S_MOTION);
delay(1000);
}
@@ -38,12 +31,8 @@ void loop()
Serial.println(tripped);
gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
delay(200); //delay to allow serial to fully print before sleep
gw.powerDown();
sleep.pwrDownMode(); //set sleep mode
sleep.sleepInterrupt(INTERRUPT,CHANGE);
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
gw.sleep(INTERRUPT,CHANGE, 120000);
}