From 9c3ff3ca4ac5eb076fd6add2e5f14c294e915567 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 8 Jan 2015 19:30:59 +0100 Subject: o Implementing reading of values from the real thing. --- app.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'app.cpp') 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; -- cgit v1.2.3