aboutsummaryrefslogtreecommitdiff
path: root/app.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-01-08 19:30:59 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-01-08 19:30:59 +0100
commit9c3ff3ca4ac5eb076fd6add2e5f14c294e915567 (patch)
tree73d625c3e835e7700e7d42a09dd5f6e57cc9c70d /app.cpp
parent08f269afd4926edca9cdfd00c3d15d419e6c87a4 (diff)
downloadtrygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.tar.gz
trygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.tar.bz2
trygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.tar.xz
trygvisio_soil_moisture-9c3ff3ca4ac5eb076fd6add2e5f14c294e915567.zip
o Implementing reading of values from the real thing.
Diffstat (limited to 'app.cpp')
-rw-r--r--app.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/app.cpp b/app.cpp
index 19d7285..606864d 100644
--- a/app.cpp
+++ b/app.cpp
@@ -11,15 +11,17 @@
// See http://redbearlab.com/blendmicro/ for pins.
struct sm_sensor {
- uint8_t pin;
+ uint8_t a_pin;
+ uint8_t d1_pin;
+ uint8_t d2_pin;
uint8_t value;
uint16_t warning_value;
uint16_t update_interval;
uint8_t name_length;
uint8_t name[SENSOR_NAME_LEN];
} sensors[SENSOR_COUNT] = {
- // Pin, Value, Warning Value, Update Interval, Length of Name, Name
- { 9, 0, 10, 0, 9, 'sensor #1'},
+ // A Pin, D1 Pin, D2 Pin, Value, Warning Value, Update Interval, Length of Name, Name
+ { 8, 3, 5, 0, 10, 0, 9, 'sensor #1'},
};
static unsigned long next_update[SENSOR_COUNT];
@@ -31,15 +33,42 @@ void sm_on_connect() {
}
}
-void sm_on_loop() {
+void sm_setup() {
+ for (int i = 0; i < SENSOR_COUNT; i++) {
+ struct sm_sensor s = sensors[i];
+
+ pinMode(s.a_pin, INPUT);
+ pinMode(s.d1_pin, OUTPUT);
+ pinMode(s.d2_pin, OUTPUT);
+ }
+}
+
+void sm_loop() {
static unsigned long last = 0, now;
static uint8_t x = 10;
now = millis();
+
+ if (now - last > 3000) {
+ last = now;
+ for (int i = 0; i < SENSOR_COUNT; i++) {
+ struct sm_sensor& s = sensors[i];
+
+ digitalWrite(s.d1_pin, HIGH);
+ digitalWrite(s.d2_pin, LOW);
+
+ s.value = analogRead(s.a_pin);
+ Serial.print("#");
+ Serial.print(i, DEC);
+ Serial.print(" = ");
+ Serial.print(s.value, DEC);
+ Serial.println();
+ }
+ }
// TODO: implement proper notification
- if (false || now - last > 3000) {
+ if (false && now - last > 3000) {
last = now;
struct sm_res res;