-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzone.cpp
60 lines (50 loc) · 1.22 KB
/
zone.cpp
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
58
59
60
#include <Arduino.h>
#include <cactus_io_BME280_I2C.h>
#include "pins.h"
#include "zone.h"
// Constructors
Zone::Zone(uint8_t address, int pin) {
setupSensor(address);
setupPin(pin);
}
// Private
/**
* Initiates BME280 sensor using I2C address
* Sets proper temp offset based on sensor address
* Sets online state if successful
**/
void Zone::setupSensor(uint8_t address) {
sensor = BME280_I2C(address);
if (address == 0x76)
{
sensor.setTempCal(-.8);
} else
{
sensor.setTempCal(-1);
}
if (sensor.begin()) {online = true;}
}
/**
* Initiates output PWM pin
* Sets pwmPin to appropriate pin number
**/
void Zone::setupPin(int pin) {
pwmPin = pin;
pinMode(pin, OUTPUT);
}
// Public
/**
* Set fan speed for a particular zone
**/
void Zone::setFanSpeed(int speed) {
fanSpeed = speed;
speed = map(speed, 0, 100, 0, 1024);
analogWrite(pwmPin, speed);
if (speed <= 0) { // Turn off fans if either speed 0
digitalWrite(FANPOWER, LOW);
digitalWrite(LEDPIN, LOW); // Turn on LED
} else { // Turns fans on elsewise
digitalWrite(FANPOWER, HIGH);
digitalWrite(LEDPIN, HIGH); // Turn off LED
}
}