Receive и sleep ?
Добавлено: Вс сен 29, 2019 11:13 pm
Вот хочу разобраться - Можно ли использовать sleep с пробуждением
по interrupt от датчика движения
или по входящему сообщению от gateway
по interrupt от датчика движения
или по входящему сообщению от gateway
Код: Выделить всё
// Enable and select radio type attached
#define MY_RADIO_RF24
#define CHILD_ID_PIR 1 // PIR data
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
#define INTERRUPT_PIR DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#include <MySensors.h>
MyMessage msgPIR(CHILD_ID_PIR, V_TRIPPED);
void before()
{
}
void setup()
{
}
void presentation()
{
present(CHILD_ID_PIR, S_MOTION);
}
void loop() {
// Sleep until interrupts comes in. Send update every 30 sec.
sleep(INTERRUPT_PIR, CHANGE, SLEEP_TIME);
}
void receive(const MyMessage &message)
{
if (message.type == V_STATUS) {
// Write some debug info
Serial.println(F("Message received"));
}
}