Matt Lesslaw / Mbed 2 deprecated MagicMixer

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pump.h Source File

pump.h

00001 class Pump {
00002     private:
00003     DigitalOut *io;
00004     DigitalOut *led;
00005     int on_v, off_v;
00006     Timeout timeout;
00007     unsigned char status;
00008     
00009     public:
00010     Pump(PinName p, DigitalOut *led, int on_value) {
00011         this->io = new DigitalOut(p);
00012         if(on_value == 1) {
00013             this->on_v = 1;
00014             this->off_v = 0;
00015         } else {
00016             this->on_v = 0;
00017             this->off_v = 1;
00018         }
00019         this->led = led;
00020         this->off();
00021     }
00022     
00023     void set_status(int s) {
00024         this->status = s;
00025         this->led->write(s);
00026     }
00027     
00028     void on(float time) {
00029         while(this->status);
00030         this->io->write(this->on_v);
00031         this->set_status(1);
00032         this->timeout.attach(this, &Pump::off, time);
00033     }
00034     
00035     void off() {
00036         this->io->write(this->off_v);
00037         this->set_status(0);
00038     }
00039     
00040     ~Pump() {
00041         this->off();
00042         delete io;
00043     }
00044  };
00045