Example program for the SeeedStudio Motor Shield V2.0 to control the movement of 2 motors. MotorDriver library and SoftwarePWM libraries are required.

Dependencies:   MotorDriver SoftwarePWM mbed

Committer:
screamer
Date:
Fri Feb 13 09:41:49 2015 +0000
Revision:
3:89a3d8bf7a9d
Parent:
2:9d1ef3713f82
Update mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 2:9d1ef3713f82 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
screamer 2:9d1ef3713f82 2 *
screamer 2:9d1ef3713f82 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
screamer 2:9d1ef3713f82 4 * and associated documentation files (the "Software"), to deal in the Software without
screamer 2:9d1ef3713f82 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
screamer 2:9d1ef3713f82 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
screamer 2:9d1ef3713f82 7 * Software is furnished to do so, subject to the following conditions:
screamer 2:9d1ef3713f82 8 *
screamer 2:9d1ef3713f82 9 * The above copyright notice and this permission notice shall be included in all copies or
screamer 2:9d1ef3713f82 10 * substantial portions of the Software.
screamer 2:9d1ef3713f82 11 *
screamer 2:9d1ef3713f82 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
screamer 2:9d1ef3713f82 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
screamer 2:9d1ef3713f82 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
screamer 2:9d1ef3713f82 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
screamer 2:9d1ef3713f82 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
screamer 2:9d1ef3713f82 17 */
screamer 2:9d1ef3713f82 18
screamer 0:070093b01182 19 #include "mbed.h"
screamer 0:070093b01182 20 #include "MotorDriver.h"
screamer 0:070093b01182 21
screamer 0:070093b01182 22 #define MOTORSHIELD_IN1 D8
screamer 0:070093b01182 23 #define MOTORSHIELD_IN2 D11
screamer 0:070093b01182 24 #define MOTORSHIELD_IN3 D12
screamer 0:070093b01182 25 #define MOTORSHIELD_IN4 D13
screamer 0:070093b01182 26 #define SPEEDPIN_A D9
screamer 0:070093b01182 27 #define SPEEDPIN_B D10
screamer 0:070093b01182 28
screamer 0:070093b01182 29 MotorDriver motorDriver(MOTORSHIELD_IN1,MOTORSHIELD_IN2,MOTORSHIELD_IN3,MOTORSHIELD_IN4,SPEEDPIN_A,SPEEDPIN_B);
screamer 0:070093b01182 30
screamer 0:070093b01182 31 int main(){
screamer 0:070093b01182 32 /*Configure the motor A to control the wheel at the left side.*/
screamer 0:070093b01182 33 /*Configure the motor B to control the wheel at the right side.*/
screamer 0:070093b01182 34 motorDriver.init();
screamer 0:070093b01182 35 motorDriver.setSpeed(90,MOTORB);
screamer 0:070093b01182 36 motorDriver.setSpeed(90,MOTORA);
screamer 0:070093b01182 37 while(1){
screamer 0:070093b01182 38 motorDriver.goForward();
screamer 0:070093b01182 39 wait(2);
screamer 0:070093b01182 40 motorDriver.goBackward();
screamer 0:070093b01182 41 wait(2);
screamer 0:070093b01182 42 motorDriver.goLeft();
screamer 0:070093b01182 43 wait(2);
screamer 0:070093b01182 44 motorDriver.goRight();
screamer 0:070093b01182 45 wait(2);
screamer 0:070093b01182 46 }
screamer 0:070093b01182 47 }