aboutsummaryrefslogtreecommitdiff
path: root/main.ino
blob: 9fcabbe1e6bc4935598e6e41a68d051c2e5bf728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <Arduino.h>
#include <Wire.h>
 
#include "data.h"
#include "battery.h"
#include "display.h"
#include "datalog.h"
#include "co2.h"
#include "pm.h"
 
Battery battery;
PM pm;
CO2 co2;
 
SensorData data;
 
Display display;
DataLog datalog;
 
void setup() {
  Serial.begin(115200);
  while (!Serial) {
    delay(100);
  }
 
  // the board's definition says SCL=23, but I have SCL=22 
  Wire.begin(21,22);
 
  display.start();
  display.show(&data);
 
  // I think this has to come after the display.start(), they may both 
  // use the same SPI thing 
  datalog.start();
 
  battery.start();
  co2.start();
  pm.start();
  Serial.println("Waiting for first measurement... (5 sec)");
 
  delay(5000);
}
 
void loop() {
  bool changed;
 
  if (battery.dataReady()) { changed=true; battery.read(&data); }
  if (pm.dataReady()) { changed = true; pm.read(&data); }
  if (co2.dataReady()) { changed = true; co2.read(&data); }
 
  if (changed) {
    display.show(&data);
    datalog.show(&data);
  }
 
  delay(5000);
}