Add temperature and break countdown display

This commit is contained in:
cryptogopher
2022-10-09 15:09:52 +02:00
parent 3872ece37b
commit 21512bc4f4
2 changed files with 39 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
#include "SAMDTimerInterrupt.h" #include "SAMDTimerInterrupt.h"
#include "SAMD_ISR_Timer.h" #include "SAMD_ISR_Timer.h"
#include "grove_alphanumeric_display.h"
#define HW_TIMER_INTERVAL_MS 10 #define HW_TIMER_INTERVAL_MS 10
SAMDTimer ITimer(TIMER_TC3); SAMDTimer ITimer(TIMER_TC3);
@@ -7,7 +8,9 @@ SAMD_ISR_Timer ISR_Timer;
void TimerHandler(void) { ISR_Timer.run(); } void TimerHandler(void) { ISR_Timer.run(); }
const int COUNTDOWN = 300; Seeed_Digital_Tube tube;
const int COUNTDOWN = 240;
const int PERIOD_MS = 1000; const int PERIOD_MS = 1000;
const uint BUTTON_PIN = 6; const uint BUTTON_PIN = 6;
@@ -20,15 +23,25 @@ const uint BUZZER_PIN = 0;
* >0 - COUNTDOWN * >0 - COUNTDOWN
*/ */
volatile int countdown = -1; volatile int countdown = -1;
volatile float temperature = 0.0;
void setup() { void setup() {
initButton(); initButton();
initTemperature();
// Wire initialized by temperature sensor
tube.setTubeType(TYPE_4, TYPE_4_DEFAULT_I2C_ADDR);
tube.setBrightness(15);
tube.setBlinkRate(BLINK_OFF);
tube.setPoint(true,true);
ITimer.attachInterruptInterval_MS(10, TimerHandler); ITimer.attachInterruptInterval_MS(10, TimerHandler);
ISR_Timer.setInterval(PERIOD_MS, metronomeRun); ISR_Timer.setInterval(PERIOD_MS, runMetronome);
ISR_Timer.setInterval(PERIOD_MS, readTemperature);
ISR_Timer.setInterval(PERIOD_MS, updateTube);
} }
void metronomeRun() { void runMetronome() {
if (countdown > 0) { if (countdown > 0) {
countdown -= 1; countdown -= 1;
@@ -38,4 +51,15 @@ void metronomeRun() {
} }
} }
void updateTube() {
char tube_str[5];
if (countdown <= 0)
sprintf(tube_str, "%4u", (unsigned int) (temperature * 100.0));
else
sprintf(tube_str, "%4u", countdown);
tube.displayString(tube_str);
}
void loop() {} void loop() {}

12
temperature.ino Normal file
View File

@@ -0,0 +1,12 @@
#include "Seeed_BME280.h"
BME280 sensor;
void initTemperature() {
sensor.init();
}
void readTemperature() {
// TODO: add hysteresis
temperature = sensor.getTemperature();
}