Fertiliser mixing station

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lawless
Date:
Fri Oct 04 22:15:50 2013 +0000
Parent:
0:34e2166ac5cd
Commit message:
Pumps set with a auto-off timeout. Call it with a number of seconds and it switches itself off afterwards.

Changed in this revision

flow_controlled.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
peristaltics.h Show annotated file Show diff for this revision Revisions of this file
pump.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flow_controlled.h	Fri Oct 04 22:15:50 2013 +0000
@@ -0,0 +1,38 @@
+
+class Flow_Controlled {
+    private :
+        vector<Pump *>pumps;
+        DigitalOut *enable;
+        DigitalIn *flow;
+
+    public:
+    
+    Flow_Controlled(int on_value) {    
+        this->enable = new DigitalOut(p17);
+        this->pumps.push_back(new Pump(p18, &led1, on_value));
+        this->pumps.push_back(new Pump(p19, &led2, on_value));
+        this->flow = new DigitalIn(p20);
+    }
+    
+    void raw_water(unsigned int litres) {
+        this->pumps[0]->on(0.7 * litres);
+    }
+    
+    void recycled_water(unsigned int litres) {
+        this->pumps[1]->on(0.7 * litres);
+    }
+    
+    void all_off() {
+        for(int p = 0; p < pumps.size(); p++)
+            this->pumps[p]->off();
+        this->enable->write(0);        
+    }
+    
+    ~Flow_Controlled() {
+        for(int p = 0; p < pumps.size(); p++)
+            delete this->pumps[p];
+        delete this->enable;
+        delete this->flow;
+        
+    }
+};
--- a/main.cpp	Thu Oct 03 12:03:16 2013 +0000
+++ b/main.cpp	Fri Oct 04 22:15:50 2013 +0000
@@ -1,23 +1,33 @@
+#include <vector>
+
 #include "mbed.h"
+#include <FunctionPointer.h>
 
-DigitalOut myled(LED1);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+#include "pump.h"
+#include "peristaltics.h"
+#include "flow_controlled.h"
 
 
-DigitalOut Pump_Peri_1_Activate(p5);
-DigitalOut Pump_Peri_2_Activate(p6);
-DigitalOut Pump_Peri_3_Activate(p7);
-
-DigitalOut Pump_Water_Enable(p17);
-DigitalOut Pump_Water_Raw_Activate(p18);
-DigitalOut Pump_Water_Recycled_Activate(p19);
-DigitalIn Flow_Meter_Pulse(p20);
-
-
-int main() {
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
-    }
+int 
+main() {
+    Peristaltics *peri = new Peristaltics(1);
+    Flow_Controlled *flowed = new Flow_Controlled(1);
+    
+    wait(3);
+    
+    
+    peri->nutrient_a(1);
+    peri->nutrient_b(2);
+    led4 = 1;
+    wait(5);
+    led4 = 0;
+    
+    
+    delete peri, flowed;
+    
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/peristaltics.h	Fri Oct 04 22:15:50 2013 +0000
@@ -0,0 +1,47 @@
+
+class Peristaltics {
+    private :
+        vector<Pump *>pumps;
+
+    public:
+    
+    Peristaltics(int on_value) {
+        this->pumps.push_back(new Pump(p5, &led1, on_value));
+        this->pumps.push_back(new Pump(p6, &led2, on_value));
+        this->pumps.push_back(new Pump(p7, &led3, on_value));
+    }
+    
+    void nutrient_a(unsigned int ml) {
+led1 = 1;
+        this->pumps[0]->on(1.0 * ml);
+    }
+    
+    void nutrient_b(unsigned int ml) {
+led2 = 1;
+        this->pumps[1]->on(1.0 * ml);
+    }
+    
+    void pH(unsigned int ml) {
+led3 = 1;    
+        this->pumps[2]->on(1.0 * ml);
+    }
+    
+    void all_off() {
+        for(int p = 0; p < pumps.size(); p++)
+            this->pumps[p]->off();
+led1 = 0;
+led2 = 0;
+led3 = 0;            
+    }
+    
+    
+    ~Peristaltics() {
+        for(int p = 0; p < pumps.size(); p++)
+            delete this->pumps[p];
+
+led1 = 0;
+led2 = 0;
+led3 = 0;            
+            
+    }
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pump.h	Fri Oct 04 22:15:50 2013 +0000
@@ -0,0 +1,45 @@
+class Pump {
+    private:
+    DigitalOut *io;
+    DigitalOut *led;
+    int on_v, off_v;
+    Timeout timeout;
+    unsigned char status;
+    
+    public:
+    Pump(PinName p, DigitalOut *led, int on_value) {
+        this->io = new DigitalOut(p);
+        if(on_value == 1) {
+            this->on_v = 1;
+            this->off_v = 0;
+        } else {
+            this->on_v = 0;
+            this->off_v = 1;
+        }
+        this->led = led;
+        this->off();
+    }
+    
+    void set_status(int s) {
+        this->status = s;
+        this->led->write(s);
+    }
+    
+    void on(float time) {
+        while(this->status);
+        this->io->write(this->on_v);
+        this->set_status(1);
+        this->timeout.attach(this, &Pump::off, time);
+    }
+    
+    void off() {
+        this->io->write(this->off_v);
+        this->set_status(0);
+    }
+    
+    ~Pump() {
+        this->off();
+        delete io;
+    }
+ };
+ 
\ No newline at end of file