Salinity and temperature sensors are implemented in classes.

Dependencies:   mbed

Committer:
mariosimaremare
Date:
Tue Jun 14 09:14:24 2016 +0000
Revision:
2:ed17e258da0d
Parent:
1:f448c12d2c5b
Child:
3:7c648d1d8802
Fixing temperature calculation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariosimaremare 0:ad9362f18797 1 /*
mariosimaremare 0:ad9362f18797 2 * G3: WATERPLAY
mariosimaremare 0:ad9362f18797 3 */
mariosimaremare 0:ad9362f18797 4
mariosimaremare 0:ad9362f18797 5 #include "mbed.h"
mariosimaremare 0:ad9362f18797 6 #include "Flasher.h"
mariosimaremare 0:ad9362f18797 7 #include "SalinitySensor.h"
mariosimaremare 0:ad9362f18797 8 #include "TemperatureSensor.h"
mariosimaremare 2:ed17e258da0d 9 #include "Thermostat.h"
mariosimaremare 2:ed17e258da0d 10 #include "DRV8825.h"
mariosimaremare 2:ed17e258da0d 11 #define MAX_SPEED 8000
mariosimaremare 2:ed17e258da0d 12 #define MICROSTEPS_PER_STEP 16
mariosimaremare 2:ed17e258da0d 13 DRV8825 stpr_mtr(p21, p22, p23, p24, p25, p26);
mariosimaremare 0:ad9362f18797 14
mariosimaremare 0:ad9362f18797 15 char program_name[128] = "G3: WATERPLAY";
mariosimaremare 0:ad9362f18797 16 int keep_running = 1;
mariosimaremare 0:ad9362f18797 17 Serial serial(USBTX, USBRX);
mariosimaremare 0:ad9362f18797 18 Flasher led1(LED1);
mariosimaremare 0:ad9362f18797 19
mariosimaremare 0:ad9362f18797 20 double salinity_voltage = 3.3;
mariosimaremare 0:ad9362f18797 21 double salinity_converter = 1.6667; // 5.0/3.0
mariosimaremare 0:ad9362f18797 22 double salinity_multiplier = 16.3;
mariosimaremare 2:ed17e258da0d 23 double salinity_lower_boundary = 3.0;
mariosimaremare 2:ed17e258da0d 24 double salinity_upper_boundary = 7.0;
mariosimaremare 1:f448c12d2c5b 25
mariosimaremare 0:ad9362f18797 26 double temperature_voltage = 4.85;
mariosimaremare 0:ad9362f18797 27 double temperature_converter = 1.6667; // 5.0/3.0
mariosimaremare 0:ad9362f18797 28 double temperature_variance = 5.0;
mariosimaremare 0:ad9362f18797 29 double temperature_vin = 4.85;
mariosimaremare 0:ad9362f18797 30 double temperature_resistance = 15000.0;
mariosimaremare 2:ed17e258da0d 31 double temperature_lower_boundary = 27.0;
mariosimaremare 2:ed17e258da0d 32 double temperature_upper_boundary = 32.0;
mariosimaremare 0:ad9362f18797 33
mariosimaremare 0:ad9362f18797 34 SalinitySensor salinitySensor(
mariosimaremare 1:f448c12d2c5b 35 serial,
mariosimaremare 0:ad9362f18797 36 p16,
mariosimaremare 0:ad9362f18797 37 salinity_voltage,
mariosimaremare 0:ad9362f18797 38 salinity_converter,
mariosimaremare 2:ed17e258da0d 39 salinity_multiplier,
mariosimaremare 2:ed17e258da0d 40 salinity_lower_boundary,
mariosimaremare 2:ed17e258da0d 41 salinity_upper_boundary
mariosimaremare 0:ad9362f18797 42 );
mariosimaremare 0:ad9362f18797 43
mariosimaremare 0:ad9362f18797 44 TemperatureSensor temperatureSensor(
mariosimaremare 1:f448c12d2c5b 45 serial,
mariosimaremare 0:ad9362f18797 46 p15,
mariosimaremare 0:ad9362f18797 47 temperature_voltage,
mariosimaremare 0:ad9362f18797 48 temperature_converter,
mariosimaremare 2:ed17e258da0d 49 temperature_lower_boundary,
mariosimaremare 2:ed17e258da0d 50 temperature_upper_boundary,
mariosimaremare 0:ad9362f18797 51 temperature_variance,
mariosimaremare 0:ad9362f18797 52 temperature_vin,
mariosimaremare 0:ad9362f18797 53 temperature_resistance
mariosimaremare 0:ad9362f18797 54 );
mariosimaremare 0:ad9362f18797 55
mariosimaremare 2:ed17e258da0d 56 Thermostat thermostat(
mariosimaremare 2:ed17e258da0d 57 serial,
mariosimaremare 2:ed17e258da0d 58 p18,
mariosimaremare 2:ed17e258da0d 59 LED4
mariosimaremare 2:ed17e258da0d 60 );
mariosimaremare 2:ed17e258da0d 61
mariosimaremare 1:f448c12d2c5b 62 double salinity_value = 0.0;
mariosimaremare 1:f448c12d2c5b 63 double temperature_value = 0.0;
mariosimaremare 0:ad9362f18797 64 int main()
mariosimaremare 0:ad9362f18797 65 {
mariosimaremare 0:ad9362f18797 66 serial.printf("\n\r%s\n\r", program_name);
mariosimaremare 0:ad9362f18797 67
mariosimaremare 0:ad9362f18797 68 while(keep_running) {
mariosimaremare 2:ed17e258da0d 69 salinitySensor.reload();
mariosimaremare 2:ed17e258da0d 70 temperatureSensor.reload();
mariosimaremare 2:ed17e258da0d 71
mariosimaremare 1:f448c12d2c5b 72 // in waiting for objects to be ready, make some delay.
mariosimaremare 1:f448c12d2c5b 73 // a single flashing is 0.2 second.
mariosimaremare 0:ad9362f18797 74 led1.flash(5);
mariosimaremare 0:ad9362f18797 75
mariosimaremare 0:ad9362f18797 76 serial.printf(
mariosimaremare 2:ed17e258da0d 77 "salinity: %3.2F | %3.2F | %3.2F :: temperature: %3.2F | %3.2F | %3.2F\n\r",
mariosimaremare 2:ed17e258da0d 78 salinitySensor.getReading(),
mariosimaremare 0:ad9362f18797 79 salinitySensor.getSalinity(),
mariosimaremare 2:ed17e258da0d 80 salinitySensor.getStatus(),
mariosimaremare 2:ed17e258da0d 81 temperatureSensor.getReading(),
mariosimaremare 2:ed17e258da0d 82 temperatureSensor.getTemperature(),
mariosimaremare 2:ed17e258da0d 83 temperatureSensor.getStatus()
mariosimaremare 0:ad9362f18797 84 );
mariosimaremare 2:ed17e258da0d 85
mariosimaremare 2:ed17e258da0d 86 thermostat.react(temperatureSensor.getStatus());
mariosimaremare 2:ed17e258da0d 87 //or (int i = 500; i < MAX_SPEED; i+=5) {
mariosimaremare 2:ed17e258da0d 88 // stpr_mtr.settings(1/MICROSTEPS_PER_STEP, 1, i);
mariosimaremare 2:ed17e258da0d 89 //}
mariosimaremare 0:ad9362f18797 90 }
mariosimaremare 0:ad9362f18797 91 }