-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiodome.cpp
More file actions
109 lines (89 loc) · 2.42 KB
/
Biodome.cpp
File metadata and controls
109 lines (89 loc) · 2.42 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "WProgram.h"
#include "Biodome.h"
//==========================================================================//
// Model representation of a controlled relay with boolean state
//==========================================================================//
void Device::configure(int outPin, boolean isControlInverted)
{
pin = outPin;
pinMode(pin, OUTPUT);
inverted = isControlInverted;
// set defaults
turnOff();
queuedStatus = 0;
}
// turn off device via relay
void Device::turnOff()
{
inverted ? digitalWrite(pin, HIGH) : digitalWrite(pin, LOW);
status = 0;
}
// turn on device via relay
void Device::turnOn()
{
// support weird relay board from futurlec that switches on with logic 0
inverted ? digitalWrite(pin, LOW) : digitalWrite(pin, HIGH);
status = 1;
}
void Device::nextStatus()
{
if(queuedStatus == 1)
{
turnOn();
}
else if(queuedStatus == 0)
{
turnOff();
}
}
void Sensor::configure(char * sensorName, float measurementCompensation)
{
name = sensorName;
_compensation = measurementCompensation;
}
void FacadeSensor::update(){}
void FacadeSensor::updateExternal(float input)
{
_lastValue = input;
}
//==========================================================================//
// TMP36 Temperature sensor
//==========================================================================//
#define TEMP_VREF 5.0
TemperatureSensor::TemperatureSensor(byte uPin)
{
pin = uPin;
}
//avarage a temperature and update _lastValue
void TemperatureSensor::update()
{
float sum = 0;
byte iterations = 6;
for (byte i=0; i <= iterations; i++)
{
int reading = analogRead(pin);
float voltage = reading * TEMP_VREF / 1024;
sum += (voltage - 0.5) * 100;
delay(10);
}
_lastValue = sum / iterations;
}
//==========================================================================//
// LM335 Temperature sensor
//==========================================================================//
LM335TemperatureSensor::LM335TemperatureSensor(byte uPin)
{
pin = uPin;
}
//avarage a temperature and update _lastValue
void LM335TemperatureSensor::update()
{
float val = 0;
float val2 = 0;
float deg = 0;
float celcius = 0;
val = analogRead(pin); // read value from the sensor
val2 = val * 0.00489; // take SENSOR value and multiply it by 4.89mV
deg = val2 * 100; // multiply by 100 to get degrees in K
_lastValue = deg - 273.15; // subtract absolute zero to get degrees celcius
}