use TaskScheduler
- use task for displaying colon - update display only when minute changes
This commit is contained in:
parent
633f2eb2de
commit
f807698cdd
@ -9,7 +9,12 @@
|
|||||||
|
|
||||||
namespace Display {
|
namespace Display {
|
||||||
|
|
||||||
|
void displayColon();
|
||||||
|
|
||||||
uint8_t brightness = BRIGHTNESS;
|
uint8_t brightness = BRIGHTNESS;
|
||||||
|
int currentMin = -1;
|
||||||
|
|
||||||
|
Task blinkColon(500, TASK_FOREVER, displayColon, &ts, true);
|
||||||
|
|
||||||
// Create display object
|
// Create display object
|
||||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||||
@ -35,6 +40,7 @@ namespace Display {
|
|||||||
|
|
||||||
void changeBrightness(bool increase) {
|
void changeBrightness(bool increase) {
|
||||||
increase ? brightness = (brightness + 2) % 15 : brightness = (brightness - 2) % 15;
|
increase ? brightness = (brightness + 2) % 15 : brightness = (brightness - 2) % 15;
|
||||||
|
clockDisplay.setBrightness(brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjustBrightness() {
|
void adjustBrightness() {
|
||||||
@ -44,12 +50,20 @@ namespace Display {
|
|||||||
} else {
|
} else {
|
||||||
brightness = 1;
|
brightness = 1;
|
||||||
}
|
}
|
||||||
|
clockDisplay.setBrightness(brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayColon(bool on) {
|
void displayColon() {
|
||||||
clockDisplay.setBrightness(brightness);
|
static bool colonOn = false;
|
||||||
clockDisplay.drawColon(on);
|
|
||||||
|
if (colonOn && currentMin != minute()) {
|
||||||
|
currentMin = minute();
|
||||||
|
displayTime();
|
||||||
|
}
|
||||||
|
clockDisplay.drawColon(colonOn);
|
||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
|
|
||||||
|
colonOn = !colonOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayValue(int value) {
|
void displayValue(int value) {
|
||||||
@ -60,6 +74,6 @@ namespace Display {
|
|||||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||||
clockDisplay.setBrightness(brightness);
|
clockDisplay.setBrightness(brightness);
|
||||||
displayTime();
|
displayTime();
|
||||||
displayColon(false);
|
displayColon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ namespace Ir {
|
|||||||
void loop() {
|
void loop() {
|
||||||
if (readCommand()) {
|
if (readCommand()) {
|
||||||
Display::displayValue(lastCommand);
|
Display::displayValue(lastCommand);
|
||||||
Display::displayColon(false);
|
// Display::displayColon(false);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
switch (lastCommand)
|
switch (lastCommand)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,6 +20,7 @@ lib_deps =
|
|||||||
jchristensen/Timezone@^1.2.4
|
jchristensen/Timezone@^1.2.4
|
||||||
ottowinter/AsyncMqttClient-esphome@^0.8.5
|
ottowinter/AsyncMqttClient-esphome@^0.8.5
|
||||||
crankyoldgit/IRremoteESP8266@^2.7.18
|
crankyoldgit/IRremoteESP8266@^2.7.18
|
||||||
|
arkhipenko/TaskScheduler@^3.4.0
|
||||||
|
|
||||||
[env:dev_mode]
|
[env:dev_mode]
|
||||||
build_flags = -D IR=1
|
build_flags = -D IR=1
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <TaskScheduler.h>
|
||||||
|
Scheduler ts;
|
||||||
|
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
#include "ntp_time.h"
|
#include "ntp_time.h"
|
||||||
@ -42,11 +46,6 @@ void loop() {
|
|||||||
wifi.disconnect();
|
wifi.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Display::displayTime();
|
|
||||||
Display::displayColon(true);
|
|
||||||
delay(500);
|
|
||||||
Display::displayColon(false);
|
|
||||||
delay(500);
|
|
||||||
|
|
||||||
yield();
|
ts.execute();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user