Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
pump.h@1:a1f7cc753866, 2013-10-04 (annotated)
- Committer:
- lawless
- Date:
- Fri Oct 04 22:15:50 2013 +0000
- Revision:
- 1:a1f7cc753866
Pumps set with a auto-off timeout. Call it with a number of seconds and it switches itself off afterwards.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| lawless | 1:a1f7cc753866 | 1 | class Pump { |
| lawless | 1:a1f7cc753866 | 2 | private: |
| lawless | 1:a1f7cc753866 | 3 | DigitalOut *io; |
| lawless | 1:a1f7cc753866 | 4 | DigitalOut *led; |
| lawless | 1:a1f7cc753866 | 5 | int on_v, off_v; |
| lawless | 1:a1f7cc753866 | 6 | Timeout timeout; |
| lawless | 1:a1f7cc753866 | 7 | unsigned char status; |
| lawless | 1:a1f7cc753866 | 8 | |
| lawless | 1:a1f7cc753866 | 9 | public: |
| lawless | 1:a1f7cc753866 | 10 | Pump(PinName p, DigitalOut *led, int on_value) { |
| lawless | 1:a1f7cc753866 | 11 | this->io = new DigitalOut(p); |
| lawless | 1:a1f7cc753866 | 12 | if(on_value == 1) { |
| lawless | 1:a1f7cc753866 | 13 | this->on_v = 1; |
| lawless | 1:a1f7cc753866 | 14 | this->off_v = 0; |
| lawless | 1:a1f7cc753866 | 15 | } else { |
| lawless | 1:a1f7cc753866 | 16 | this->on_v = 0; |
| lawless | 1:a1f7cc753866 | 17 | this->off_v = 1; |
| lawless | 1:a1f7cc753866 | 18 | } |
| lawless | 1:a1f7cc753866 | 19 | this->led = led; |
| lawless | 1:a1f7cc753866 | 20 | this->off(); |
| lawless | 1:a1f7cc753866 | 21 | } |
| lawless | 1:a1f7cc753866 | 22 | |
| lawless | 1:a1f7cc753866 | 23 | void set_status(int s) { |
| lawless | 1:a1f7cc753866 | 24 | this->status = s; |
| lawless | 1:a1f7cc753866 | 25 | this->led->write(s); |
| lawless | 1:a1f7cc753866 | 26 | } |
| lawless | 1:a1f7cc753866 | 27 | |
| lawless | 1:a1f7cc753866 | 28 | void on(float time) { |
| lawless | 1:a1f7cc753866 | 29 | while(this->status); |
| lawless | 1:a1f7cc753866 | 30 | this->io->write(this->on_v); |
| lawless | 1:a1f7cc753866 | 31 | this->set_status(1); |
| lawless | 1:a1f7cc753866 | 32 | this->timeout.attach(this, &Pump::off, time); |
| lawless | 1:a1f7cc753866 | 33 | } |
| lawless | 1:a1f7cc753866 | 34 | |
| lawless | 1:a1f7cc753866 | 35 | void off() { |
| lawless | 1:a1f7cc753866 | 36 | this->io->write(this->off_v); |
| lawless | 1:a1f7cc753866 | 37 | this->set_status(0); |
| lawless | 1:a1f7cc753866 | 38 | } |
| lawless | 1:a1f7cc753866 | 39 | |
| lawless | 1:a1f7cc753866 | 40 | ~Pump() { |
| lawless | 1:a1f7cc753866 | 41 | this->off(); |
| lawless | 1:a1f7cc753866 | 42 | delete io; |
| lawless | 1:a1f7cc753866 | 43 | } |
| lawless | 1:a1f7cc753866 | 44 | }; |
| lawless | 1:a1f7cc753866 | 45 |