Salinity and temperature sensors are implemented in classes.

Dependencies:   mbed

Revision:
2:ed17e258da0d
Parent:
1:f448c12d2c5b
Child:
3:7c648d1d8802
--- a/main.cpp	Tue Jun 07 10:21:07 2016 +0000
+++ b/main.cpp	Tue Jun 14 09:14:24 2016 +0000
@@ -4,36 +4,41 @@
 
 #include "mbed.h"
 #include "Flasher.h"
-#include "Waterplay.h"
 #include "SalinitySensor.h"
 #include "TemperatureSensor.h"
+#include "Thermostat.h"
+#include "DRV8825.h"
+#define MAX_SPEED 8000
+#define MICROSTEPS_PER_STEP 16
+DRV8825 stpr_mtr(p21, p22, p23, p24, p25, p26);
 
 char program_name[128] = "G3: WATERPLAY";
 int keep_running = 1;
 Serial serial(USBTX, USBRX);
 Flasher led1(LED1);
-Waterplay waterplay(serial);
 
 double salinity_voltage = 3.3;
 double salinity_converter = 1.6667; // 5.0/3.0
 double salinity_multiplier = 16.3;
-
-
-
-
+double salinity_lower_boundary = 3.0;
+double salinity_upper_boundary = 7.0;
 
 double temperature_voltage = 4.85;
 double temperature_converter = 1.6667; // 5.0/3.0
 double temperature_variance = 5.0;
 double temperature_vin = 4.85;
 double temperature_resistance = 15000.0;
+double temperature_lower_boundary = 27.0;
+double temperature_upper_boundary = 32.0;
 
 SalinitySensor salinitySensor(
     serial,
     p16,
     salinity_voltage,
     salinity_converter,
-    salinity_multiplier
+    salinity_multiplier,
+    salinity_lower_boundary,
+    salinity_upper_boundary
 );
 
 TemperatureSensor temperatureSensor(
@@ -41,11 +46,19 @@
     p15,
     temperature_voltage,
     temperature_converter,
+    temperature_lower_boundary,
+    temperature_upper_boundary,
     temperature_variance,
     temperature_vin,
     temperature_resistance
 );
 
+Thermostat thermostat(
+    serial,
+    p18,
+    LED4
+);
+
 double salinity_value = 0.0;
 double temperature_value = 0.0;
 int main()
@@ -53,20 +66,26 @@
     serial.printf("\n\r%s\n\r", program_name);
 
     while(keep_running) {
-        salinity_value = salinitySensor.read();
-        temperature_value = temperatureSensor.read();
+        salinitySensor.reload();
+        temperatureSensor.reload();
+
         // in waiting for objects to be ready, make some delay.
         // a single flashing is 0.2 second.
         led1.flash(5);
 
         serial.printf(
-            "salinity: %5.4F | %5.4F | %5.4F :: temperature: %5.4F | %5.4F | %5.4F\n\r",
-            salinity_value,
-            salinitySensor.getVoltage(),
+            "salinity: %3.2F | %3.2F | %3.2F :: temperature: %3.2F | %3.2F | %3.2F\n\r",
+            salinitySensor.getReading(),
             salinitySensor.getSalinity(),
-            temperature_value,
-            temperatureSensor.getVoltage(),
-            temperatureSensor.getTemperature()
+            salinitySensor.getStatus(),
+            temperatureSensor.getReading(),
+            temperatureSensor.getTemperature(),
+            temperatureSensor.getStatus()
         );
+
+        thermostat.react(temperatureSensor.getStatus());
+        //or (int i = 500; i < MAX_SPEED; i+=5) {
+         //   stpr_mtr.settings(1/MICROSTEPS_PER_STEP, 1, i);
+        //}
     }
 }
\ No newline at end of file