![](/media/cache/group/ep_LV4vK4D.webp.50x50_q85.jpg)
6.3 Motor mittels Tasten vor-, rückwärts, Stop laufen lassen und Poti benützen um die Geschwindigkeit einzustellen.
Dependencies: mbed
Fork of 06-08-Uebung by
Motor/Motor.h@0:5d64a3e741ec, 2015-03-04 (annotated)
- Committer:
- marcel1691
- Date:
- Wed Mar 04 16:30:53 2015 +0000
- Revision:
- 0:5d64a3e741ec
6.8 Motor mittels Tasten vor-, r?ckw?rts, Stop laufen lassen und Poti ben?tzen um die Geschwindigkeit einzustellen.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcel1691 | 0:5d64a3e741ec | 1 | /* mbed simple H-bridge motor controller |
marcel1691 | 0:5d64a3e741ec | 2 | * Copyright (c) 2007-2010, sford, http://mbed.org |
marcel1691 | 0:5d64a3e741ec | 3 | * |
marcel1691 | 0:5d64a3e741ec | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
marcel1691 | 0:5d64a3e741ec | 5 | * of this software and associated documentation files (the "Software"), to deal |
marcel1691 | 0:5d64a3e741ec | 6 | * in the Software without restriction, including without limitation the rights |
marcel1691 | 0:5d64a3e741ec | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
marcel1691 | 0:5d64a3e741ec | 8 | * copies of the Software, and to permit persons to whom the Software is |
marcel1691 | 0:5d64a3e741ec | 9 | * furnished to do so, subject to the following conditions: |
marcel1691 | 0:5d64a3e741ec | 10 | * |
marcel1691 | 0:5d64a3e741ec | 11 | * The above copyright notice and this permission notice shall be included in |
marcel1691 | 0:5d64a3e741ec | 12 | * all copies or substantial portions of the Software. |
marcel1691 | 0:5d64a3e741ec | 13 | * |
marcel1691 | 0:5d64a3e741ec | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
marcel1691 | 0:5d64a3e741ec | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
marcel1691 | 0:5d64a3e741ec | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
marcel1691 | 0:5d64a3e741ec | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
marcel1691 | 0:5d64a3e741ec | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
marcel1691 | 0:5d64a3e741ec | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
marcel1691 | 0:5d64a3e741ec | 20 | * THE SOFTWARE. |
marcel1691 | 0:5d64a3e741ec | 21 | */ |
marcel1691 | 0:5d64a3e741ec | 22 | |
marcel1691 | 0:5d64a3e741ec | 23 | #ifndef MBED_MOTOR_H |
marcel1691 | 0:5d64a3e741ec | 24 | #define MBED_MOTOR_H |
marcel1691 | 0:5d64a3e741ec | 25 | |
marcel1691 | 0:5d64a3e741ec | 26 | #include "mbed.h" |
marcel1691 | 0:5d64a3e741ec | 27 | |
marcel1691 | 0:5d64a3e741ec | 28 | /** Interface to control a standard DC motor |
marcel1691 | 0:5d64a3e741ec | 29 | * |
marcel1691 | 0:5d64a3e741ec | 30 | * with an H-bridge using a PwmOut and 2 DigitalOuts |
marcel1691 | 0:5d64a3e741ec | 31 | */ |
marcel1691 | 0:5d64a3e741ec | 32 | class Motor { |
marcel1691 | 0:5d64a3e741ec | 33 | public: |
marcel1691 | 0:5d64a3e741ec | 34 | |
marcel1691 | 0:5d64a3e741ec | 35 | /** Create a motor control interface |
marcel1691 | 0:5d64a3e741ec | 36 | * |
marcel1691 | 0:5d64a3e741ec | 37 | * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed |
marcel1691 | 0:5d64a3e741ec | 38 | * @param fwd A DigitalOut, set high when the motor should go forward |
marcel1691 | 0:5d64a3e741ec | 39 | * @param rev A DigitalOut, set high when the motor should go backwards |
marcel1691 | 0:5d64a3e741ec | 40 | */ |
marcel1691 | 0:5d64a3e741ec | 41 | Motor(PinName pwm, PinName fwd, PinName rev); |
marcel1691 | 0:5d64a3e741ec | 42 | |
marcel1691 | 0:5d64a3e741ec | 43 | /** Set the speed of the motor |
marcel1691 | 0:5d64a3e741ec | 44 | * |
marcel1691 | 0:5d64a3e741ec | 45 | * @param speed The speed of the motor as a normalised value between -1.0 and 1.0 |
marcel1691 | 0:5d64a3e741ec | 46 | */ |
marcel1691 | 0:5d64a3e741ec | 47 | void speed(float speed); |
marcel1691 | 0:5d64a3e741ec | 48 | |
marcel1691 | 0:5d64a3e741ec | 49 | protected: |
marcel1691 | 0:5d64a3e741ec | 50 | PwmOut _pwm; |
marcel1691 | 0:5d64a3e741ec | 51 | DigitalOut _fwd; |
marcel1691 | 0:5d64a3e741ec | 52 | DigitalOut _rev; |
marcel1691 | 0:5d64a3e741ec | 53 | |
marcel1691 | 0:5d64a3e741ec | 54 | }; |
marcel1691 | 0:5d64a3e741ec | 55 | |
marcel1691 | 0:5d64a3e741ec | 56 | #endif |