eka sinambela
/
mbed_stepper_motors
stepper mottor for pumps
Ping.h@1:8431b042a2eb, 2016-06-19 (annotated)
- Committer:
- ekasinambela
- Date:
- Sun Jun 19 21:32:08 2016 +0000
- Revision:
- 1:8431b042a2eb
modify stepper motor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ekasinambela | 1:8431b042a2eb | 1 | /* mbed Ping Library |
ekasinambela | 1:8431b042a2eb | 2 | * Copyright (c) 2007-2010 rosienej |
ekasinambela | 1:8431b042a2eb | 3 | * |
ekasinambela | 1:8431b042a2eb | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
ekasinambela | 1:8431b042a2eb | 5 | * of this software and associated documentation files (the "Software"), to deal |
ekasinambela | 1:8431b042a2eb | 6 | * in the Software without restriction, including without limitation the rights |
ekasinambela | 1:8431b042a2eb | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
ekasinambela | 1:8431b042a2eb | 8 | * copies of the Software, and to permit persons to whom the Software is |
ekasinambela | 1:8431b042a2eb | 9 | * furnished to do so, subject to the following conditions: |
ekasinambela | 1:8431b042a2eb | 10 | * |
ekasinambela | 1:8431b042a2eb | 11 | * The above copyright notice and this permission notice shall be included in |
ekasinambela | 1:8431b042a2eb | 12 | * all copies or substantial portions of the Software. |
ekasinambela | 1:8431b042a2eb | 13 | * |
ekasinambela | 1:8431b042a2eb | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
ekasinambela | 1:8431b042a2eb | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
ekasinambela | 1:8431b042a2eb | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
ekasinambela | 1:8431b042a2eb | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
ekasinambela | 1:8431b042a2eb | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ekasinambela | 1:8431b042a2eb | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
ekasinambela | 1:8431b042a2eb | 20 | * THE SOFTWARE. |
ekasinambela | 1:8431b042a2eb | 21 | */ |
ekasinambela | 1:8431b042a2eb | 22 | |
ekasinambela | 1:8431b042a2eb | 23 | #ifndef MBED_PING_H |
ekasinambela | 1:8431b042a2eb | 24 | #define MBED_PING_H |
ekasinambela | 1:8431b042a2eb | 25 | |
ekasinambela | 1:8431b042a2eb | 26 | #include "mbed.h" |
ekasinambela | 1:8431b042a2eb | 27 | /** Ping class, based on an InterruptIn pin, and a timer |
ekasinambela | 1:8431b042a2eb | 28 | * works with the parallax Ping))) sensor (www.parallax.com) |
ekasinambela | 1:8431b042a2eb | 29 | * |
ekasinambela | 1:8431b042a2eb | 30 | * Example: |
ekasinambela | 1:8431b042a2eb | 31 | * @code |
ekasinambela | 1:8431b042a2eb | 32 | * // Continuously send pings and read the sensor |
ekasinambela | 1:8431b042a2eb | 33 | * #include "mbed.h" |
ekasinambela | 1:8431b042a2eb | 34 | * #include "Ping.h" |
ekasinambela | 1:8431b042a2eb | 35 | * |
ekasinambela | 1:8431b042a2eb | 36 | * Ping Pinger(p21); |
ekasinambela | 1:8431b042a2eb | 37 | * |
ekasinambela | 1:8431b042a2eb | 38 | * int main() { |
ekasinambela | 1:8431b042a2eb | 39 | * int range; |
ekasinambela | 1:8431b042a2eb | 40 | |
ekasinambela | 1:8431b042a2eb | 41 | * while(1) { |
ekasinambela | 1:8431b042a2eb | 42 | * |
ekasinambela | 1:8431b042a2eb | 43 | * Pinger.Send(); |
ekasinambela | 1:8431b042a2eb | 44 | * wait_ms(30); |
ekasinambela | 1:8431b042a2eb | 45 | * range = Pinger.Read_cm(); |
ekasinambela | 1:8431b042a2eb | 46 | * } |
ekasinambela | 1:8431b042a2eb | 47 | * } |
ekasinambela | 1:8431b042a2eb | 48 | * @endcode |
ekasinambela | 1:8431b042a2eb | 49 | */ |
ekasinambela | 1:8431b042a2eb | 50 | class Ping { |
ekasinambela | 1:8431b042a2eb | 51 | public: |
ekasinambela | 1:8431b042a2eb | 52 | /** Create a Ping object connected to the specified InterruptIn pin |
ekasinambela | 1:8431b042a2eb | 53 | * |
ekasinambela | 1:8431b042a2eb | 54 | * @param PING_PIN InterruptIn pin to connect to |
ekasinambela | 1:8431b042a2eb | 55 | */ |
ekasinambela | 1:8431b042a2eb | 56 | Ping(PinName PING_PIN); |
ekasinambela | 1:8431b042a2eb | 57 | |
ekasinambela | 1:8431b042a2eb | 58 | /** Sends a Ping |
ekasinambela | 1:8431b042a2eb | 59 | * |
ekasinambela | 1:8431b042a2eb | 60 | * @param none |
ekasinambela | 1:8431b042a2eb | 61 | */ |
ekasinambela | 1:8431b042a2eb | 62 | void Send(void); |
ekasinambela | 1:8431b042a2eb | 63 | |
ekasinambela | 1:8431b042a2eb | 64 | /** Set the speed of sound, default 33 cm/ms |
ekasinambela | 1:8431b042a2eb | 65 | * |
ekasinambela | 1:8431b042a2eb | 66 | * @param Speed of sound in centimeters per milliseconds |
ekasinambela | 1:8431b042a2eb | 67 | */ |
ekasinambela | 1:8431b042a2eb | 68 | void Set_Speed_of_Sound(int SoS_ms); |
ekasinambela | 1:8431b042a2eb | 69 | |
ekasinambela | 1:8431b042a2eb | 70 | /** Read the result in centimeters |
ekasinambela | 1:8431b042a2eb | 71 | * |
ekasinambela | 1:8431b042a2eb | 72 | * @param none |
ekasinambela | 1:8431b042a2eb | 73 | */ |
ekasinambela | 1:8431b042a2eb | 74 | int Read_cm(void); |
ekasinambela | 1:8431b042a2eb | 75 | |
ekasinambela | 1:8431b042a2eb | 76 | protected: |
ekasinambela | 1:8431b042a2eb | 77 | |
ekasinambela | 1:8431b042a2eb | 78 | InterruptIn _event; |
ekasinambela | 1:8431b042a2eb | 79 | DigitalInOut _cmd; |
ekasinambela | 1:8431b042a2eb | 80 | Timer _timer; |
ekasinambela | 1:8431b042a2eb | 81 | |
ekasinambela | 1:8431b042a2eb | 82 | bool _Valid; |
ekasinambela | 1:8431b042a2eb | 83 | bool _Busy; |
ekasinambela | 1:8431b042a2eb | 84 | int _Time; |
ekasinambela | 1:8431b042a2eb | 85 | int _SPEED_OF_SOUND_CM; /* in milliseconds */ |
ekasinambela | 1:8431b042a2eb | 86 | |
ekasinambela | 1:8431b042a2eb | 87 | void _Starts(void); |
ekasinambela | 1:8431b042a2eb | 88 | void _Stops(void); |
ekasinambela | 1:8431b042a2eb | 89 | |
ekasinambela | 1:8431b042a2eb | 90 | }; |
ekasinambela | 1:8431b042a2eb | 91 | |
ekasinambela | 1:8431b042a2eb | 92 | #endif |
ekasinambela | 1:8431b042a2eb | 93 |