for noam

Dependencies:   mbed Map

Committer:
drorbalbul
Date:
Fri Dec 20 15:17:18 2019 +0000
Revision:
0:33b00fa05201
noam

Who changed what in which revision?

UserRevisionLine numberNew contents of line
drorbalbul 0:33b00fa05201 1 /* mbed simple H-bridge motor controller
drorbalbul 0:33b00fa05201 2 * Copyright (c) 2007-2010, sford, http://mbed.org
drorbalbul 0:33b00fa05201 3 *
drorbalbul 0:33b00fa05201 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
drorbalbul 0:33b00fa05201 5 * of this software and associated documentation files (the "Software"), to deal
drorbalbul 0:33b00fa05201 6 * in the Software without restriction, including without limitation the rights
drorbalbul 0:33b00fa05201 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
drorbalbul 0:33b00fa05201 8 * copies of the Software, and to permit persons to whom the Software is
drorbalbul 0:33b00fa05201 9 * furnished to do so, subject to the following conditions:
drorbalbul 0:33b00fa05201 10 *
drorbalbul 0:33b00fa05201 11 * The above copyright notice and this permission notice shall be included in
drorbalbul 0:33b00fa05201 12 * all copies or substantial portions of the Software.
drorbalbul 0:33b00fa05201 13 *
drorbalbul 0:33b00fa05201 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
drorbalbul 0:33b00fa05201 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
drorbalbul 0:33b00fa05201 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
drorbalbul 0:33b00fa05201 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
drorbalbul 0:33b00fa05201 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
drorbalbul 0:33b00fa05201 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
drorbalbul 0:33b00fa05201 20 * THE SOFTWARE.
drorbalbul 0:33b00fa05201 21 */
drorbalbul 0:33b00fa05201 22
drorbalbul 0:33b00fa05201 23 #include "Motor.h"
drorbalbul 0:33b00fa05201 24
drorbalbul 0:33b00fa05201 25 #include "mbed.h"
drorbalbul 0:33b00fa05201 26
drorbalbul 0:33b00fa05201 27 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
drorbalbul 0:33b00fa05201 28 _pwm(pwm), _fwd(fwd), _rev(rev) {
drorbalbul 0:33b00fa05201 29
drorbalbul 0:33b00fa05201 30 // Set initial condition of PWM
drorbalbul 0:33b00fa05201 31 _pwm.period(0.001);
drorbalbul 0:33b00fa05201 32 _pwm = 0;
drorbalbul 0:33b00fa05201 33
drorbalbul 0:33b00fa05201 34 // Initial condition of output enables
drorbalbul 0:33b00fa05201 35 _fwd = 0;
drorbalbul 0:33b00fa05201 36 _rev = 0;
drorbalbul 0:33b00fa05201 37 }
drorbalbul 0:33b00fa05201 38
drorbalbul 0:33b00fa05201 39 void Motor::speed(float speed) {
drorbalbul 0:33b00fa05201 40 _fwd = (speed > 0.0);
drorbalbul 0:33b00fa05201 41 _rev = (speed < 0.0);
drorbalbul 0:33b00fa05201 42 _pwm = abs(speed);
drorbalbul 0:33b00fa05201 43 }
drorbalbul 0:33b00fa05201 44
drorbalbul 0:33b00fa05201 45
drorbalbul 0:33b00fa05201 46