add software debounce
This commit is contained in:
parent
8a001a4697
commit
5fd1543e3f
1 changed files with 49 additions and 34 deletions
35
main.ino
35
main.ino
|
@ -51,7 +51,9 @@ public:
|
||||||
return this->data[realIndex];
|
return this->data[realIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
int getCursor() const { return this->rCount; }
|
int getCursor() const {
|
||||||
|
return this->rCount;
|
||||||
|
}
|
||||||
|
|
||||||
float getMaxDataPoint() {
|
float getMaxDataPoint() {
|
||||||
if (this->rCount == 0) return 0;
|
if (this->rCount == 0) return 0;
|
||||||
|
@ -82,7 +84,9 @@ public:
|
||||||
return sum / this->rCount;
|
return sum / this->rCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getUnit() { return this->UNIT; }
|
String getUnit() {
|
||||||
|
return this->UNIT;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Element {
|
class Element {
|
||||||
|
@ -130,7 +134,6 @@ class MaxAvgMinElement : public Element {
|
||||||
tft.print(F("Min: "));
|
tft.print(F("Min: "));
|
||||||
tft.print(this->data.getMinDataPoint(), 1);
|
tft.print(this->data.getMinDataPoint(), 1);
|
||||||
tft.print(unit);
|
tft.print(unit);
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,7 +147,9 @@ private:
|
||||||
return X + 2 + (int)(i * (this->WIDTH - 3) / (this->AMOUNT_DATAPOINTS - 1));
|
return X + 2 + (int)(i * (this->WIDTH - 3) / (this->AMOUNT_DATAPOINTS - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int getScaledY(float value) { return this->getScaledY(value, this->data.getMinDataPoint(), this->data.getMaxDataPoint()); }; // OOP is soo cool
|
int getScaledY(float value) {
|
||||||
|
return this->getScaledY(value, this->data.getMinDataPoint(), this->data.getMaxDataPoint());
|
||||||
|
}; // OOP is soo cool
|
||||||
|
|
||||||
int getScaledY(float value, float minY, float maxY) {
|
int getScaledY(float value, float minY, float maxY) {
|
||||||
if (maxY - minY == 0) return this->Y + this->HEIGHT / 2;
|
if (maxY - minY == 0) return this->Y + this->HEIGHT / 2;
|
||||||
|
@ -187,7 +192,8 @@ class Screen {
|
||||||
protected:
|
protected:
|
||||||
Element** elements;
|
Element** elements;
|
||||||
public:
|
public:
|
||||||
Screen(Element** elems) : elements(elems){};
|
Screen(Element** elems)
|
||||||
|
: elements(elems){};
|
||||||
void draw() {
|
void draw() {
|
||||||
for (int i = 0; this->elements[i] != nullptr; i++) {
|
for (int i = 0; this->elements[i] != nullptr; i++) {
|
||||||
this->elements[i]->render();
|
this->elements[i]->render();
|
||||||
|
@ -202,7 +208,8 @@ class DisplayConfig {
|
||||||
int screenCount;
|
int screenCount;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DisplayConfig(Screen** screens) : screens(screens), screenIndex(0), screenCount(0){
|
DisplayConfig(Screen** screens)
|
||||||
|
: screens(screens), screenIndex(0), screenCount(0) {
|
||||||
while (this->screens[this->screenCount] != nullptr) this->screenCount++;
|
while (this->screens[this->screenCount] != nullptr) this->screenCount++;
|
||||||
tft.initR(INITR_MINI160x80);
|
tft.initR(INITR_MINI160x80);
|
||||||
tft.setRotation(1);
|
tft.setRotation(1);
|
||||||
|
@ -218,17 +225,23 @@ class DisplayConfig {
|
||||||
return this->applyScreen(this->screenIndex);
|
return this->applyScreen(this->screenIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
Screen* getCurrentScreen() {return this->screens[this->screenIndex];}
|
Screen* getCurrentScreen() {
|
||||||
Screen* getCurrentScreenIndex() {return this->screenIndex;}
|
return this->screens[this->screenIndex];
|
||||||
|
}
|
||||||
|
Screen* getCurrentScreenIndex() {
|
||||||
|
return this->screenIndex;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
unsigned long previousMillis = -1000000000;
|
unsigned long previousMillis = -1000000000;
|
||||||
|
unsigned long lastDebounceTime = 0;
|
||||||
|
unsigned long debounceDelay = 50;
|
||||||
bool buttonPressedLastCycle = false;
|
bool buttonPressedLastCycle = false;
|
||||||
bool sht3xErrorLastCycle = false;
|
bool sht3xErrorLastCycle = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CONFIG START
|
// CONFIG START
|
||||||
DataStorage* tempData;
|
DataStorage* tempData;
|
||||||
DataStorage* humData;
|
DataStorage* humData;
|
||||||
|
@ -334,10 +347,12 @@ void loop() {
|
||||||
sht3xErrorLastCycle = true;
|
sht3xErrorLastCycle = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (digitalRead(buttonPin)) {
|
if (digitalRead(buttonPin)) {
|
||||||
if (!buttonPressedLastCycle){
|
if (!buttonPressedLastCycle && millis() - lastDebounceTime > debounceDelay) {
|
||||||
config->cycleScreen()->draw();
|
config->cycleScreen()->draw();
|
||||||
buttonPressedLastCycle = true;
|
buttonPressedLastCycle = true;
|
||||||
|
lastDebounceTime = millis();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buttonPressedLastCycle = false;
|
buttonPressedLastCycle = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue