Sleep for LampCtrl
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
#define MY_DEFAULT_ERR_LED_PIN (4) // Error led pin
|
||||
#define MY_DEFAULT_RX_LED_PIN (5) // Receive led pin
|
||||
#define MY_DEFAULT_TX_LED_PIN (6) // the PCB, on board LED
|
||||
#define BUTT1 8
|
||||
#define BUTT2 7
|
||||
#define BUTT1 2
|
||||
#define BUTT2 3
|
||||
|
||||
#include <MySensors.h>
|
||||
#include <Bounce2.h>
|
||||
@@ -22,14 +22,18 @@ bool stat1, stat2, Ack;
|
||||
void presentation();
|
||||
void sendData(MyMessage msg, bool status);
|
||||
void sendData(MyMessage msg, uint32_t status);
|
||||
void sendData(MyMessage msg, float status);
|
||||
|
||||
MyMessage msgLamp1(0, V_STATUS);
|
||||
MyMessage msgLamp2(1, V_STATUS);
|
||||
MyMessage msgMillis(2, V_VAR1);
|
||||
MyMessage msgVoltage(2, V_VAR2);
|
||||
|
||||
Bounce butt1 = Bounce(), butt2 = Bounce();
|
||||
int BATTERY_SENSE_PIN = A0;
|
||||
|
||||
void setup() {
|
||||
analogReference(INTERNAL);
|
||||
butt1.attach(BUTT1, INPUT_PULLUP);
|
||||
butt2.attach(BUTT2, INPUT_PULLUP);
|
||||
butt1.interval(25);
|
||||
@@ -38,6 +42,9 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
static uint32_t cRun = millis() - 60000;
|
||||
|
||||
int sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
float v = sensorValue * 0.004659498;
|
||||
butt1.update();
|
||||
butt2.update();
|
||||
if(butt1.fell()){
|
||||
@@ -50,10 +57,9 @@ void loop() {
|
||||
sendData(msgLamp2, !stat2);
|
||||
Serial.print(F("Change Sock2: ")); Serial.println(stat2);
|
||||
}
|
||||
if((cRun + 60000) <= millis()){
|
||||
cRun = millis();
|
||||
sendData(msgMillis, cRun);
|
||||
}
|
||||
sendData(msgVoltage, v);
|
||||
sleep(digitalPinToInterrupt(BUTT1), FALLING, digitalPinToInterrupt(BUTT2), FALLING, 300000);
|
||||
}
|
||||
|
||||
void presentation()
|
||||
@@ -61,7 +67,7 @@ void presentation()
|
||||
sendSketchInfo("LampCtrl", "1.0");
|
||||
present(0, S_BINARY, "Lamp1");
|
||||
present(1, S_BINARY, "Lamp2");
|
||||
present(2, S_CUSTOM, "ESMillis");
|
||||
present(2, S_CUSTOM, "MillisVoltage");
|
||||
}
|
||||
|
||||
void sendData(MyMessage msg, bool status)
|
||||
@@ -96,3 +102,20 @@ void sendData(MyMessage msg, uint32_t val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendData(MyMessage msg, float val)
|
||||
{
|
||||
bool send_data = false;
|
||||
uint8_t count = 0;
|
||||
Ack = false;
|
||||
while(send_data == false){
|
||||
count++;
|
||||
send_data = send(msg.set(val, 2), true);
|
||||
if(!send_data)
|
||||
wait(1000, C_SET, msg.type);
|
||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||
count = 0; // Обнуляем счётчик
|
||||
send_data = 1; // Выходим из цикла
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user