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 {
|
||||
|
||||
void displayColon();
|
||||
|
||||
uint8_t brightness = BRIGHTNESS;
|
||||
int currentMin = -1;
|
||||
|
||||
Task blinkColon(500, TASK_FOREVER, displayColon, &ts, true);
|
||||
|
||||
// Create display object
|
||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||
@ -35,6 +40,7 @@ namespace Display {
|
||||
|
||||
void changeBrightness(bool increase) {
|
||||
increase ? brightness = (brightness + 2) % 15 : brightness = (brightness - 2) % 15;
|
||||
clockDisplay.setBrightness(brightness);
|
||||
}
|
||||
|
||||
void adjustBrightness() {
|
||||
@ -44,12 +50,20 @@ namespace Display {
|
||||
} else {
|
||||
brightness = 1;
|
||||
}
|
||||
clockDisplay.setBrightness(brightness);
|
||||
}
|
||||
|
||||
void displayColon(bool on) {
|
||||
clockDisplay.setBrightness(brightness);
|
||||
clockDisplay.drawColon(on);
|
||||
void displayColon() {
|
||||
static bool colonOn = false;
|
||||
|
||||
if (colonOn && currentMin != minute()) {
|
||||
currentMin = minute();
|
||||
displayTime();
|
||||
}
|
||||
clockDisplay.drawColon(colonOn);
|
||||
clockDisplay.writeDisplay();
|
||||
|
||||
colonOn = !colonOn;
|
||||
}
|
||||
|
||||
void displayValue(int value) {
|
||||
@ -60,6 +74,6 @@ namespace Display {
|
||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||
clockDisplay.setBrightness(brightness);
|
||||
displayTime();
|
||||
displayColon(false);
|
||||
displayColon();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ namespace Ir {
|
||||
void loop() {
|
||||
if (readCommand()) {
|
||||
Display::displayValue(lastCommand);
|
||||
Display::displayColon(false);
|
||||
// Display::displayColon(false);
|
||||
delay(1000);
|
||||
switch (lastCommand)
|
||||
{
|
||||
|
||||
@ -20,6 +20,7 @@ lib_deps =
|
||||
jchristensen/Timezone@^1.2.4
|
||||
ottowinter/AsyncMqttClient-esphome@^0.8.5
|
||||
crankyoldgit/IRremoteESP8266@^2.7.18
|
||||
arkhipenko/TaskScheduler@^3.4.0
|
||||
|
||||
[env:dev_mode]
|
||||
build_flags = -D IR=1
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <TaskScheduler.h>
|
||||
Scheduler ts;
|
||||
|
||||
#include "wifi.h"
|
||||
#include "ota.h"
|
||||
#include "ntp_time.h"
|
||||
@ -42,11 +46,6 @@ void loop() {
|
||||
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