Download this file
#include "indicator.h"
#include "co2_meter.h"
Indicator::Indicator(IndicatorBlinker * indicator_blinker) {
blinker = indicator_blinker;
pinMode(RED_LED_PIN, OUTPUT);
digitalWrite(RED_LED_PIN, LOW);
pinMode(GREEN_LED_PIN, OUTPUT);
digitalWrite(GREEN_LED_PIN, LOW);
}
void Indicator::off() {
blinker->stop();
}
void Indicator::update(uint16_t value) {
// Use 50% duty cycle to save power.
if (value < GREEN_THRESHOLD) { // Full green
blinker->stop();
digitalWrite(RED_LED_PIN, LOW);
analogWrite(GREEN_LED_PIN, 128);
}
else if (value < YELLOW_THRESHOLD) { // Blink between green and yellow
blinker->start();
}
else if (value < RED_THRESHOLD) { // Full yellow
blinker->stop();
analogWrite(RED_LED_PIN, 58); // Red LED is 10% brighter than green
analogWrite(GREEN_LED_PIN, 64);
}
else { // Full red
blinker->stop();
analogWrite(RED_LED_PIN, 116); // Red LED is 10% brighter than green
digitalWrite(GREEN_LED_PIN, LOW);
}
}
// vim:ft=arduino