demo demo / Mbed 2 deprecated BluetoothSumo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motor.cpp Source File

Motor.cpp

00001 // H-Bridge Motor Control
00002 // Copyright (c) 2009 sford
00003 // Released under the MIT License: http://mbed.org/license/mit
00004 
00005 #include "Motor.h"
00006 
00007 #include "mbed.h"
00008 
00009 Motor::Motor(PinName pwm, PinName fwd, PinName rev) : _pwm(pwm), _fwd(fwd), _rev(rev) {
00010 
00011     // Set initial condition of PWM
00012     _pwm.period(0.001);
00013     _pwm = 0;
00014 
00015     // Initial condition of output enables
00016     _fwd = 0;
00017     _rev = 0;
00018 }
00019 
00020 void Motor::speed(float speed) {
00021     _fwd = (speed > 0.0);
00022     _rev = (speed < 0.0);
00023     _pwm = abs(speed);
00024 }