Change KorMYS LED Inv
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
// Set blinking period
|
||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||
// Inverses the behavior of leds
|
||||
#define MY_WITH_LEDS_BLINKING_INVERSE
|
||||
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
||||
// Flash leds on rx/tx/err
|
||||
#define MY_DEFAULT_ERR_LED_PIN A3 // Error led pin
|
||||
#define MY_DEFAULT_TX_LED_PIN A4 // the PCB, on board LED
|
||||
@@ -30,6 +30,7 @@ bool lamp;
|
||||
#define RX_PIN 2
|
||||
#define TX_PIN 3
|
||||
#define LAMP_OUT 5
|
||||
#define PIN_MOVE 7
|
||||
SoftwareSerial sSerial(RX_PIN, TX_PIN);
|
||||
SDS011 sds;
|
||||
|
||||
@@ -58,7 +59,7 @@ void setup()
|
||||
//Serial.println(sds.setCustomWorkingPeriod(3).toString()); // sensor sends data every 3 minutes
|
||||
//sds.setActiveReportingMode();
|
||||
//sds.setCustomWorkingPeriod(1);
|
||||
pinMode(A1, INPUT_PULLUP);
|
||||
pinMode(PIN_MOVE, INPUT_PULLUP);
|
||||
pinMode(LAMP_OUT, OUTPUT);
|
||||
//digitalWrite(7, HIGH);
|
||||
//saveState(6, 2);
|
||||
@@ -98,9 +99,8 @@ void loop()
|
||||
{
|
||||
float p25, p10;
|
||||
uint32_t curTime;
|
||||
//move = digitalRead(A1);
|
||||
|
||||
if(digitalRead(A1) > 0){
|
||||
if(digitalRead(PIN_MOVE) > 0){
|
||||
if(curDelay == -1) sendData(msgMove, true);
|
||||
move = true;
|
||||
curDelay = timeDelay;
|
||||
@@ -127,8 +127,8 @@ void loop()
|
||||
}
|
||||
}
|
||||
else if((adc > (minLight + minLightDB)) || (move == 0)){
|
||||
//analogWrite(LAMP_OUT, 0);
|
||||
curDelay = 2;
|
||||
analogWrite(LAMP_OUT, 0);
|
||||
//curDelay = 2;
|
||||
if(lamp == true){
|
||||
Serial.println("Lamp OFF");
|
||||
Serial.print("ADC: ");Serial.print(adc);
|
||||
@@ -169,14 +169,14 @@ void loop()
|
||||
send(msgMillis.set(ms));
|
||||
}
|
||||
}
|
||||
if(lamp && curTime > millis()){
|
||||
/*if(lamp && curTime > millis()){
|
||||
uint8_t ll = int(LightInt - LightInt * (1 - curTime - millis() / float(fadeTime * 1000)));
|
||||
analogWrite(LAMP_OUT, ll);
|
||||
if(curTime - millis() < 10){
|
||||
lamp = false;
|
||||
analogWrite(LAMP_OUT, 0);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void receive(const MyMessage &message)
|
||||
|
||||
@@ -50,6 +50,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
||||
void oneClick()
|
||||
{
|
||||
switchLight(R_LED, !digitalRead(R_LED), true);
|
||||
//Serial.println("Press");
|
||||
//lStat1 = !lStat1;
|
||||
}
|
||||
|
||||
@@ -67,18 +68,18 @@ void longPress()
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Serial.begin(9600);
|
||||
// Serial.println("Booting"); // "Загрузка"
|
||||
//Serial.begin(115200);
|
||||
//Serial.println("Booting"); // "Загрузка"
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.hostname("SW-Koridor");
|
||||
ArduinoOTA.onStart([]() {
|
||||
// Serial.println("Start"); // "Начало OTA-апдейта"
|
||||
//Serial.println("Start"); // "Начало OTA-апдейта"
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
// Serial.println("\nEnd"); // "Завершение OTA-апдейта"
|
||||
//Serial.println("\nEnd"); // "Завершение OTA-апдейта"
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
// Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
//Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
// Serial.printf("Error[%u]: ", error);
|
||||
@@ -93,19 +94,23 @@ void setup() {
|
||||
// else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
// // "Ошибка при завершении OTA-апдейта"
|
||||
});
|
||||
// Serial.println("OTA Begin");
|
||||
ArduinoOTA.begin();
|
||||
// Serial.println("OTA Done");
|
||||
//Serial.end();
|
||||
|
||||
pinMode(B_LED, FUNCTION_3);
|
||||
pinMode(B_LED, OUTPUT);
|
||||
digitalWrite(B_LED, HIGH);
|
||||
pinMode(R_LED, OUTPUT);
|
||||
pinMode(BUTT, INPUT_PULLUP);
|
||||
// Serial.println("EEPROM Begin");
|
||||
EEPROM.begin(16);
|
||||
uint8_t lstat = 0;
|
||||
EEPROM.get(0, lstat);
|
||||
//oldLStat1 = lStat1;
|
||||
// Serial.print("Lamp1: ");
|
||||
// Serial.println(lStat1);
|
||||
//Serial.println(lStat1);
|
||||
digitalWrite(R_LED, lstat);
|
||||
//oldLStat2 = lStat2;
|
||||
|
||||
@@ -127,6 +132,7 @@ void setup() {
|
||||
|
||||
//attachInterrupt(digitalPinToInterrupt(BUTT), sw_func, RISING);
|
||||
|
||||
// Serial.println("WiFi Connect");
|
||||
connectToWifi();
|
||||
|
||||
cRun = millis();
|
||||
@@ -164,24 +170,24 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
|
||||
}
|
||||
|
||||
void connectToWifi() {
|
||||
//Serial.println("Connecting to Wi-Fi...");
|
||||
// Serial.println("Connecting to Wi-Fi...");
|
||||
WiFi.begin(ssid, password);
|
||||
}
|
||||
|
||||
void connectToMqtt() {
|
||||
//Serial.println("Connecting to MQTT...");
|
||||
// Serial.println("Connecting to MQTT...");
|
||||
mqttClient.connect();
|
||||
}
|
||||
|
||||
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
|
||||
//Serial.println("Connected to Wi-Fi.");
|
||||
//Serial.print("IP: ");
|
||||
//Serial.println(WiFi.localIP());
|
||||
// Serial.println("Connected to Wi-Fi.");
|
||||
// Serial.print("IP: ");
|
||||
// Serial.println(WiFi.localIP());
|
||||
connectToMqtt();
|
||||
}
|
||||
|
||||
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
//Serial.println("Disconnected from Wi-Fi.");
|
||||
// Serial.println("Disconnected from Wi-Fi.");
|
||||
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
|
||||
wifiReconnectTimer.once(2, connectToWifi);
|
||||
}
|
||||
@@ -194,7 +200,7 @@ void onMqttConnect(bool sessionPresent) {
|
||||
}
|
||||
|
||||
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
||||
//Serial.println("Disconnected from MQTT.");
|
||||
// Serial.println("Disconnected from MQTT.");
|
||||
|
||||
if (WiFi.isConnected()) {
|
||||
mqttReconnectTimer.once(2, connectToMqtt);
|
||||
|
||||
Reference in New Issue
Block a user