Compare commits
11 Commits
b81b52b204
...
6a0a954814
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a0a954814 | ||
|
|
d6f9bb6634 | ||
|
|
1e206b248c | ||
|
|
8594905748 | ||
|
|
814a99f733 | ||
|
|
7fe04d76cb | ||
|
|
f8878d3c37 | ||
|
|
374a72fb07 | ||
|
|
21512bc4f4 | ||
|
|
3872ece37b | ||
|
|
315aa9996c |
23
bme280.ino
Normal file
23
bme280.ino
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "Seeed_BME280.h"
|
||||
|
||||
BME280 sensor;
|
||||
float highTemp = 0.0, lowTemp = 0.0;
|
||||
const float blindZone = 0.03;
|
||||
|
||||
void initBME280() {
|
||||
sensor.init();
|
||||
}
|
||||
|
||||
void readTemperature() {
|
||||
float newTemperature = sensor.getTemperature();
|
||||
|
||||
if (newTemperature > highTemp) {
|
||||
temperature = newTemperature;
|
||||
highTemp = newTemperature;
|
||||
lowTemp = highTemp - blindZone;
|
||||
} else if (newTemperature < lowTemp) {
|
||||
temperature = newTemperature;
|
||||
lowTemp = newTemperature;
|
||||
highTemp = lowTemp + blindZone;
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
volatile unsigned long lastButtonPress = millis();
|
||||
|
||||
// Debouncing na timerze:
|
||||
// https://github.com/khoih-prog/TimerInterrupt/blob/master/examples/SwitchDebounce/SwitchDebounce.ino
|
||||
void initButton() {
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
// Order of ISRs matter: RISING should be invoked first
|
||||
@@ -10,12 +12,15 @@ void initButton() {
|
||||
void buttonISRstate() {
|
||||
if ((millis() - lastButtonPress) > 100) {
|
||||
if (countdown < 0)
|
||||
// TODO: enable metronome timer
|
||||
countdown = 0;
|
||||
else if (countdown == 0)
|
||||
// TODO: restart metronome timer to align countdown
|
||||
countdown = COUNTDOWN;
|
||||
else {
|
||||
countdown = -1;
|
||||
digitalWrite(BUTTON_LED_PIN, LOW);
|
||||
// TODO: disable metronome timer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
buzzer.ino
Normal file
22
buzzer.ino
Normal file
@@ -0,0 +1,22 @@
|
||||
SAMDTimer BuzzerTimer(TIMER_TC5);
|
||||
|
||||
bool attached = false;
|
||||
|
||||
void initBuzzer() {
|
||||
pinMode(BUZZER_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
void buzzerISR() {
|
||||
digitalWrite(BUZZER_PIN, !digitalRead(BUZZER_PIN));
|
||||
}
|
||||
|
||||
void buzz() {
|
||||
if (attached)
|
||||
BuzzerTimer.enableTimer();
|
||||
else
|
||||
BuzzerTimer.attachInterrupt(BUZZER_FREQ *2, buzzerISR);
|
||||
}
|
||||
|
||||
void noBuzz() {
|
||||
BuzzerTimer.disableTimer();
|
||||
}
|
||||
33
metronom.ino
33
metronom.ino
@@ -1,14 +1,15 @@
|
||||
#include "SAMDTimerInterrupt.h"
|
||||
#include "SAMD_ISR_Timer.h"
|
||||
|
||||
#define HW_TIMER_INTERVAL_MS 10
|
||||
SAMDTimer ITimer(TIMER_TC3);
|
||||
SAMD_ISR_Timer ISR_Timer;
|
||||
SAMDTimer TaskTimer(TIMER_TC3);
|
||||
SAMD_ISR_Timer TasksISRs;
|
||||
|
||||
void TimerHandler(void) { ISR_Timer.run(); }
|
||||
void TasksHandler(void) { TasksISRs.run(); }
|
||||
|
||||
const int COUNTDOWN = 300;
|
||||
|
||||
const int COUNTDOWN = 600;
|
||||
const int PERIOD_MS = 1000;
|
||||
const int BUZZER_FREQ = 300;
|
||||
|
||||
const uint BUTTON_PIN = 6;
|
||||
const uint BUTTON_LED_PIN = 5;
|
||||
@@ -20,26 +21,30 @@ const uint BUZZER_PIN = 0;
|
||||
* >0 - COUNTDOWN
|
||||
*/
|
||||
volatile int countdown = -1;
|
||||
volatile float temperature = 0.0;
|
||||
|
||||
void setup() {
|
||||
initButton();
|
||||
initBME280();
|
||||
initBuzzer();
|
||||
initTube();
|
||||
|
||||
ITimer.attachInterruptInterval_MS(10, TimerHandler);
|
||||
ISR_Timer.setInterval(PERIOD_MS, metronomeBeat);
|
||||
ISR_Timer.setInterval(PERIOD_MS, metronomeCountdown);
|
||||
TaskTimer.attachInterruptInterval_MS(20, TasksHandler);
|
||||
TasksISRs.setInterval(PERIOD_MS, runMetronome);
|
||||
TasksISRs.setInterval(PERIOD_MS, readTemperature);
|
||||
// TODO: move display from ISR to loop()
|
||||
TasksISRs.setInterval(200, updateTube);
|
||||
}
|
||||
|
||||
void metronomeCountdown() {
|
||||
void runMetronome() {
|
||||
if (countdown > 0) {
|
||||
countdown -= 1;
|
||||
|
||||
digitalWrite(BUTTON_LED_PIN, countdown % 2 ? HIGH : LOW);
|
||||
} else if (countdown == 0) {
|
||||
TasksISRs.setTimeout(100, noBuzz);
|
||||
buzz();
|
||||
}
|
||||
}
|
||||
|
||||
void metronomeBeat() {
|
||||
if (countdown == 0)
|
||||
tone(BUZZER_PIN, 1000, 100);
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
|
||||
30
tube.ino
Normal file
30
tube.ino
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "grove_alphanumeric_display.h"
|
||||
|
||||
Seeed_Digital_Tube tube;
|
||||
char tubeText[5] = "";
|
||||
|
||||
void initTube() {
|
||||
// Wire initialized by BME280 sensor
|
||||
tube.setTubeType(TYPE_4, TYPE_4_DEFAULT_I2C_ADDR);
|
||||
tube.setBrightness(15);
|
||||
tube.setBlinkRate(BLINK_OFF);
|
||||
}
|
||||
|
||||
void updateTube() {
|
||||
char newText[5];
|
||||
bool highPoint = false, lowPoint = false;
|
||||
|
||||
if (countdown <= 0) {
|
||||
sprintf(newText, "%4u", (unsigned int) (temperature * 100.0));
|
||||
lowPoint = true;
|
||||
} else {
|
||||
sprintf(newText, "%4u", countdown);
|
||||
}
|
||||
|
||||
if (strcmp(tubeText, newText)) {
|
||||
strcpy(tubeText, newText);
|
||||
tube.displayString(tubeText);
|
||||
tube.setPoint(highPoint, lowPoint);
|
||||
tube.display();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user