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@1:870d6a20e9d6, 2014-02-16 (annotated)
- Committer:
- lawliet
- Date:
- Sun Feb 16 03:44:55 2014 +0000
- Revision:
- 1:870d6a20e9d6
- Parent:
- 0:7f7b6c3cf00f
version 0.1
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 | /******Pins definitions*************/ |
lawliet | 1:870d6a20e9d6 | 27 | #if defined(TARGET_LPC11U24) //SEEEDUINO_ARCH |
lawliet | 1:870d6a20e9d6 | 28 | #define MOTORSHIELD_IN1 P1_26 |
lawliet | 1:870d6a20e9d6 | 29 | #define MOTORSHIELD_IN2 P1_29 |
lawliet | 1:870d6a20e9d6 | 30 | #define MOTORSHIELD_IN3 P0_8 |
lawliet | 1:870d6a20e9d6 | 31 | #define MOTORSHIELD_IN4 P0_9 |
lawliet | 1:870d6a20e9d6 | 32 | #define SPEEDPIN_A P1_27 |
lawliet | 1:870d6a20e9d6 | 33 | #define SPEEDPIN_B P0_2 |
lawliet | 1:870d6a20e9d6 | 34 | #elif defined(TARGET_LPC1768) //SEEEDUINO_ARCH_PRO |
lawliet | 1:870d6a20e9d6 | 35 | #define MOTORSHIELD_IN1 P0_0 |
lawliet | 1:870d6a20e9d6 | 36 | #define MOTORSHIELD_IN2 P0_9 |
lawliet | 1:870d6a20e9d6 | 37 | #define MOTORSHIELD_IN3 P0_8 |
lawliet | 1:870d6a20e9d6 | 38 | #define MOTORSHIELD_IN4 P0_7 |
lawliet | 1:870d6a20e9d6 | 39 | #define SPEEDPIN_A P0_1 |
lawliet | 1:870d6a20e9d6 | 40 | #define SPEEDPIN_B P0_6 |
lawliet | 1:870d6a20e9d6 | 41 | #else //please redefine the follow pins. |
lawliet | 1:870d6a20e9d6 | 42 | #define MOTORSHIELD_IN1 |
lawliet | 1:870d6a20e9d6 | 43 | #define MOTORSHIELD_IN2 |
lawliet | 1:870d6a20e9d6 | 44 | #define MOTORSHIELD_IN3 |
lawliet | 1:870d6a20e9d6 | 45 | #define MOTORSHIELD_IN4 |
lawliet | 1:870d6a20e9d6 | 46 | #define SPEEDPIN_A |
lawliet | 1:870d6a20e9d6 | 47 | #define SPEEDPIN_B |
lawliet | 0:7f7b6c3cf00f | 48 | #endif |
lawliet | 0:7f7b6c3cf00f | 49 | |
lawliet | 0:7f7b6c3cf00f | 50 | MotorDriver motorDriver(MOTORSHIELD_IN1,MOTORSHIELD_IN2,MOTORSHIELD_IN3,MOTORSHIELD_IN4,SPEEDPIN_A,SPEEDPIN_B); |
lawliet | 0:7f7b6c3cf00f | 51 | |
lawliet | 0:7f7b6c3cf00f | 52 | int main(){ |
lawliet | 0:7f7b6c3cf00f | 53 | /*Configure the motor A to control the wheel at the left side.*/ |
lawliet | 0:7f7b6c3cf00f | 54 | /*Configure the motor B to control the wheel at the right side.*/ |
lawliet | 0:7f7b6c3cf00f | 55 | motorDriver.init(); |
lawliet | 0:7f7b6c3cf00f | 56 | motorDriver.setSpeed(90,MOTORB); |
lawliet | 0:7f7b6c3cf00f | 57 | motorDriver.setSpeed(90,MOTORA); |
lawliet | 0:7f7b6c3cf00f | 58 | while(1){ |
lawliet | 0:7f7b6c3cf00f | 59 | motorDriver.goForward(); |
lawliet | 0:7f7b6c3cf00f | 60 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 61 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 62 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 63 | motorDriver.goBackward(); |
lawliet | 0:7f7b6c3cf00f | 64 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 65 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 66 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 67 | motorDriver.goLeft(); |
lawliet | 0:7f7b6c3cf00f | 68 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 69 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 70 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 71 | motorDriver.goRight(); |
lawliet | 0:7f7b6c3cf00f | 72 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 73 | motorDriver.stop(); |
lawliet | 0:7f7b6c3cf00f | 74 | wait(5); |
lawliet | 0:7f7b6c3cf00f | 75 | } |
lawliet | 0:7f7b6c3cf00f | 76 | } |