Download this file
#include "indicator.h"
#include "co2_meter.h"

Indicator::Indicator() {
  pinMode(RED_LED_PIN, OUTPUT);
  digitalWrite(RED_LED_PIN, LOW);
  pinMode(GREEN_LED_PIN, OUTPUT);
  digitalWrite(GREEN_LED_PIN, LOW);
}

void Indicator::update(uint16_t value) {
  // Use 50% duty cycle to save power.
  if (value < GREEN_THRESHOLD) {
    digitalWrite(RED_LED_PIN, LOW);
    analogWrite(GREEN_LED_PIN, 128);
  }
  else if (value > RED_THRESHOLD) {
    analogWrite(RED_LED_PIN, 116); // Red LED is 10% brighter than green
    digitalWrite(GREEN_LED_PIN, LOW);
  }
  else {
    analogWrite(RED_LED_PIN, 58); // Red LED is 10% brighter than green
    analogWrite(GREEN_LED_PIN, 64);
  }
}

// vim:ft=arduino