6.8 Motor mittels Tasten vor-, rückwärts, Stop laufen lassen und Poti benützen um die Geschwindigkeit einzustellen.

Dependencies:   mbed

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?

UserRevisionLine numberNew 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 #include "Motor.h"
marcel1691 0:5d64a3e741ec 24
marcel1691 0:5d64a3e741ec 25 #include "mbed.h"
marcel1691 0:5d64a3e741ec 26
marcel1691 0:5d64a3e741ec 27 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
marcel1691 0:5d64a3e741ec 28 _pwm(pwm), _fwd(fwd), _rev(rev) {
marcel1691 0:5d64a3e741ec 29
marcel1691 0:5d64a3e741ec 30 // Set initial condition of PWM
marcel1691 0:5d64a3e741ec 31 _pwm.period(0.001);
marcel1691 0:5d64a3e741ec 32 _pwm = 0;
marcel1691 0:5d64a3e741ec 33
marcel1691 0:5d64a3e741ec 34 // Initial condition of output enables
marcel1691 0:5d64a3e741ec 35 _fwd = 0;
marcel1691 0:5d64a3e741ec 36 _rev = 0;
marcel1691 0:5d64a3e741ec 37 }
marcel1691 0:5d64a3e741ec 38
marcel1691 0:5d64a3e741ec 39 void Motor::speed(float speed) {
marcel1691 0:5d64a3e741ec 40 _fwd = (speed > 0.0);
marcel1691 0:5d64a3e741ec 41 _rev = (speed < 0.0);
marcel1691 0:5d64a3e741ec 42 _pwm = abs(speed);
marcel1691 0:5d64a3e741ec 43 }
marcel1691 0:5d64a3e741ec 44
marcel1691 0:5d64a3e741ec 45
marcel1691 0:5d64a3e741ec 46