a demo to control the movement of motor, MotorDriver library and softPWM library are both in need.
Dependencies: MotorDriver SoftwarePWM mbed
Fork of Seeed_Motor_Shield_HelloWorld by
main.cpp@0:7f7b6c3cf00f, 2014-02-12 (annotated)
- Committer:
- lawliet
- Date:
- Wed Feb 12 03:10:21 2014 +0000
- Revision:
- 0:7f7b6c3cf00f
- Child:
- 1:870d6a20e9d6
Demo code for Seeed Motor Shield
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:7f7b6c3cf00f | 1 | /* |
lawliet | 0:7f7b6c3cf00f | 2 | main.cpp |
lawliet | 0:7f7b6c3cf00f | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 0:7f7b6c3cf00f | 4 | |
lawliet | 0:7f7b6c3cf00f | 5 | Author:lawliet.zou@gmail.com |
lawliet | 0:7f7b6c3cf00f | 6 | 2014-02-11 |
lawliet | 0:7f7b6c3cf00f | 7 | |
lawliet | 0:7f7b6c3cf00f | 8 | This library is free software; you can redistribute it and/or |
lawliet | 0:7f7b6c3cf00f | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 0:7f7b6c3cf00f | 10 | License as published by the Free Software Foundation; either |
lawliet | 0:7f7b6c3cf00f | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 0:7f7b6c3cf00f | 12 | |
lawliet | 0:7f7b6c3cf00f | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 0:7f7b6c3cf00f | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 0:7f7b6c3cf00f | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 0:7f7b6c3cf00f | 16 | Lesser General Public License for more details. |
lawliet | 0:7f7b6c3cf00f | 17 | |
lawliet | 0:7f7b6c3cf00f | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 0:7f7b6c3cf00f | 19 | License along with this library; if not, write to the Free Software |
lawliet | 0:7f7b6c3cf00f | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 0:7f7b6c3cf00f | 21 | */ |
lawliet | 0:7f7b6c3cf00f | 22 | |
lawliet | 0:7f7b6c3cf00f | 23 | #include "mbed.h" |
lawliet | 0:7f7b6c3cf00f | 24 | #include "MotorDriver.h" |
lawliet | 0:7f7b6c3cf00f | 25 | |
lawliet | 0:7f7b6c3cf00f | 26 | //#define SEEEDUINO_ARCH |
lawliet | 0:7f7b6c3cf00f | 27 | #define SEEEDUINO_ARCH_PRO |
lawliet | 0:7f7b6c3cf00f | 28 | /******Pins definitions*************/ |
lawliet | 0:7f7b6c3cf00f | 29 | #if defined(SEEEDUINO_ARCH) |
lawliet | 0:7f7b6c3cf00f | 30 | #define MOTORSHIELD_IN1 P1_26 |
lawliet | 0:7f7b6c3cf00f | 31 | #define MOTORSHIELD_IN2 P1_29 |
lawliet | 0:7f7b6c3cf00f | 32 | #define MOTORSHIELD_IN3 P0_8 |
lawliet | 0:7f7b6c3cf00f | 33 | #define MOTORSHIELD_IN4 P0_9 |
lawliet | 0:7f7b6c3cf00f | 34 | #define SPEEDPIN_A P1_27 |
lawliet | 0:7f7b6c3cf00f | 35 | #define SPEEDPIN_B P0_2 |
lawliet | 0:7f7b6c3cf00f | 36 | #elif defined(SEEEDUINO_ARCH_PRO) |
lawliet | 0:7f7b6c3cf00f | 37 | #define MOTORSHIELD_IN1 P0_0 |
lawliet | 0:7f7b6c3cf00f | 38 | #define MOTORSHIELD_IN2 P0_9 |
lawliet | 0:7f7b6c3cf00f | 39 | #define MOTORSHIELD_IN3 P0_8 |
lawliet | 0:7f7b6c3cf00f | 40 | #define MOTORSHIELD_IN4 P0_7 |
lawliet | 0:7f7b6c3cf00f | 41 | #define SPEEDPIN_A P0_1 |
lawliet | 0:7f7b6c3cf00f | 42 | #define SPEEDPIN_B P0_6 |
lawliet | 0:7f7b6c3cf00f | 43 | #else |
lawliet | 0:7f7b6c3cf00f | 44 | #define MOTORSHIELD_IN1 8 |
lawliet | 0:7f7b6c3cf00f | 45 | #define MOTORSHIELD_IN2 11 |
lawliet | 0:7f7b6c3cf00f | 46 | #define MOTORSHIELD_IN3 12 |
lawliet | 0:7f7b6c3cf00f | 47 | #define MOTORSHIELD_IN4 13 |
lawliet | 0:7f7b6c3cf00f | 48 | #define SPEEDPIN_A 9 |
lawliet | 0:7f7b6c3cf00f | 49 | #define SPEEDPIN_B 10 |
lawliet | 0:7f7b6c3cf00f | 50 | #endif |
lawliet | 0:7f7b6c3cf00f | 51 | |
lawliet | 0:7f7b6c3cf00f | 52 | MotorDriver motorDriver(MOTORSHIELD_IN1,MOTORSHIELD_IN2,MOTORSHIELD_IN3,MOTORSHIELD_IN4,SPEEDPIN_A,SPEEDPIN_B); |
lawliet | 0:7f7b6c3cf00f | 53 | |
lawliet | 0:7f7b6c3cf00f | 54 | int main(){ |
lawliet | 0:7f7b6c3cf00f | 55 | /*Configure the motor A to control the wheel at the left side.*/ |
lawliet | 0:7f7b6c3cf00f | 56 | /*Configure the motor B to control the wheel at the right side.*/ |
lawliet | 0:7f7b6c3cf00f | 57 | motorDriver.init(); |
lawliet | 0:7f7b6c3cf00f | 58 | motorDriver.setSpeed(90,MOTORB); |
lawliet | 0:7f7b6c3cf00f | 59 | motorDriver.setSpeed(90,MOTORA); |
lawliet | 0:7f7b6c3cf00f | 60 | while(1){ |
lawliet | 0:7f7b6c3cf00f | 61 | motorDriver.goForward(); |
lawliet | 0:7f7b6c3cf00f | 62 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 63 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 64 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 65 | motorDriver.goBackward(); |
lawliet | 0:7f7b6c3cf00f | 66 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 67 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 68 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 69 | motorDriver.goLeft(); |
lawliet | 0:7f7b6c3cf00f | 70 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 71 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 72 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 73 | motorDriver.goRight(); |
lawliet | 0:7f7b6c3cf00f | 74 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 75 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 76 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 77 | } |
lawliet | 0:7f7b6c3cf00f | 78 | } |