LightController Build
This commit is contained in:
@@ -3,21 +3,22 @@
|
|||||||
#define MY_RADIO_RF24
|
#define MY_RADIO_RF24
|
||||||
#define MY_RF24_CHANNEL (105)
|
#define MY_RF24_CHANNEL (105)
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
||||||
#define MY_REPEATER_FEATURE
|
|
||||||
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN (4) // Error led pin
|
#define MY_DEFAULT_ERR_LED_PIN (4) // Error led pin
|
||||||
#define MY_DEFAULT_RX_LED_PIN (5) // Receive 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 MY_DEFAULT_TX_LED_PIN (6) // the PCB, on board LED
|
||||||
#define BUTT1 2
|
#define BUTT1 2
|
||||||
#define BUTT2 3
|
#define BUTT2 3
|
||||||
|
#define TIME_SLEEP 5 //Minutes
|
||||||
|
|
||||||
#include <MySensors.h>
|
#include <MySensors.h>
|
||||||
#include <Bounce2.h>
|
//#include <Bounce2.h>
|
||||||
|
|
||||||
|
|
||||||
// #undef MY_NODE_ID
|
// #undef MY_NODE_ID
|
||||||
// #define MY_NODE_ID 14
|
// #define MY_NODE_ID 14
|
||||||
int8_t buttWU = MY_WAKE_UP_BY_TIMER;
|
int8_t buttWU = MY_WAKE_UP_BY_TIMER;
|
||||||
|
uint16_t workMins = 0;
|
||||||
|
|
||||||
void presentation();
|
void presentation();
|
||||||
void sendDataI(MyMessage msg, uint32_t status);
|
void sendDataI(MyMessage msg, uint32_t status);
|
||||||
@@ -28,33 +29,29 @@ MyMessage msgLamp2(1, V_STATUS);
|
|||||||
MyMessage msgMillis(2, V_VAR1);
|
MyMessage msgMillis(2, V_VAR1);
|
||||||
MyMessage msgVoltage(2, V_VAR2);
|
MyMessage msgVoltage(2, V_VAR2);
|
||||||
|
|
||||||
Bounce butt1 = Bounce(), butt2 = Bounce();
|
|
||||||
int BATTERY_SENSE_PIN = A0;
|
int BATTERY_SENSE_PIN = A0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
analogReference(INTERNAL);
|
analogReference(INTERNAL);
|
||||||
butt1.attach(BUTT1, INPUT_PULLUP);
|
pinMode(BUTT1, INPUT_PULLUP);
|
||||||
butt2.attach(BUTT2, INPUT_PULLUP);
|
pinMode(BUTT2, INPUT_PULLUP);
|
||||||
butt1.interval(25);
|
|
||||||
butt2.interval(25);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
static uint32_t cRun = millis() - 60000;
|
|
||||||
|
|
||||||
int sensorValue = analogRead(BATTERY_SENSE_PIN);
|
int sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||||
float v = sensorValue * 0.004659498;
|
float v = sensorValue * 0.0039561775471698;
|
||||||
if(buttWU == digitalPinToInterrupt(BUTT1)){
|
if(buttWU == digitalPinToInterrupt(BUTT1)){
|
||||||
sendDataI(msgLamp1, (uint8_t)1);
|
sendDataI(msgLamp1, (uint8_t)1);
|
||||||
Serial.print(F("Pressed: 1"));
|
wait(30);
|
||||||
|
Serial.println(F("Pressed: 1"));
|
||||||
}
|
}
|
||||||
if(buttWU == digitalPinToInterrupt(BUTT2)){
|
if(buttWU == digitalPinToInterrupt(BUTT2)){
|
||||||
sendDataI(msgLamp2, (uint8_t)1);
|
sendDataI(msgLamp2, (uint8_t)1);
|
||||||
Serial.print(F("Pressed: 2"));
|
wait(30);
|
||||||
|
Serial.println(F("Pressed: 2"));
|
||||||
}
|
}
|
||||||
sendDataI(msgMillis, cRun);
|
|
||||||
sendDataF(msgVoltage, v);
|
sendDataF(msgVoltage, v);
|
||||||
buttWU = sleep(digitalPinToInterrupt(BUTT1), FALLING, digitalPinToInterrupt(BUTT2), FALLING, 300000);
|
buttWU = sleep(digitalPinToInterrupt(BUTT1), FALLING, digitalPinToInterrupt(BUTT2), FALLING, TIME_SLEEP * 60000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void presentation()
|
void presentation()
|
||||||
@@ -73,7 +70,7 @@ void sendDataI(MyMessage msg, uint32_t val)
|
|||||||
count++;
|
count++;
|
||||||
send_data = send(msg.set(val), true);
|
send_data = send(msg.set(val), true);
|
||||||
if(!send_data)
|
if(!send_data)
|
||||||
wait(1000, C_SET, msg.type);
|
wait(500, C_SET, msg.type);
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||||
count = 0; // Обнуляем счётчик
|
count = 0; // Обнуляем счётчик
|
||||||
send_data = 1; // Выходим из цикла
|
send_data = 1; // Выходим из цикла
|
||||||
@@ -89,7 +86,7 @@ void sendDataF(MyMessage msg, float val)
|
|||||||
count++;
|
count++;
|
||||||
send_data = send(msg.set(val, 2), true);
|
send_data = send(msg.set(val, 2), true);
|
||||||
if(!send_data)
|
if(!send_data)
|
||||||
wait(1000, C_SET, msg.type);
|
wait(500, C_SET, msg.type);
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||||
count = 0; // Обнуляем счётчик
|
count = 0; // Обнуляем счётчик
|
||||||
send_data = 1; // Выходим из цикла
|
send_data = 1; // Выходим из цикла
|
||||||
|
|||||||
Reference in New Issue
Block a user