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
main.cpp@0:070093b01182, 2014-05-30 (annotated)
- Committer:
- screamer
- Date:
- Fri May 30 13:43:04 2014 +0000
- Revision:
- 0:070093b01182
- Child:
- 2:9d1ef3713f82
Initial revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 0:070093b01182 | 1 | #include "mbed.h" |
screamer | 0:070093b01182 | 2 | #include "MotorDriver.h" |
screamer | 0:070093b01182 | 3 | |
screamer | 0:070093b01182 | 4 | #define MOTORSHIELD_IN1 D8 |
screamer | 0:070093b01182 | 5 | #define MOTORSHIELD_IN2 D11 |
screamer | 0:070093b01182 | 6 | #define MOTORSHIELD_IN3 D12 |
screamer | 0:070093b01182 | 7 | #define MOTORSHIELD_IN4 D13 |
screamer | 0:070093b01182 | 8 | #define SPEEDPIN_A D9 |
screamer | 0:070093b01182 | 9 | #define SPEEDPIN_B D10 |
screamer | 0:070093b01182 | 10 | |
screamer | 0:070093b01182 | 11 | MotorDriver motorDriver(MOTORSHIELD_IN1,MOTORSHIELD_IN2,MOTORSHIELD_IN3,MOTORSHIELD_IN4,SPEEDPIN_A,SPEEDPIN_B); |
screamer | 0:070093b01182 | 12 | |
screamer | 0:070093b01182 | 13 | int main(){ |
screamer | 0:070093b01182 | 14 | /*Configure the motor A to control the wheel at the left side.*/ |
screamer | 0:070093b01182 | 15 | /*Configure the motor B to control the wheel at the right side.*/ |
screamer | 0:070093b01182 | 16 | motorDriver.init(); |
screamer | 0:070093b01182 | 17 | motorDriver.setSpeed(90,MOTORB); |
screamer | 0:070093b01182 | 18 | motorDriver.setSpeed(90,MOTORA); |
screamer | 0:070093b01182 | 19 | while(1){ |
screamer | 0:070093b01182 | 20 | motorDriver.goForward(); |
screamer | 0:070093b01182 | 21 | wait(2); |
screamer | 0:070093b01182 | 22 | motorDriver.goBackward(); |
screamer | 0:070093b01182 | 23 | wait(2); |
screamer | 0:070093b01182 | 24 | motorDriver.goLeft(); |
screamer | 0:070093b01182 | 25 | wait(2); |
screamer | 0:070093b01182 | 26 | motorDriver.goRight(); |
screamer | 0:070093b01182 | 27 | wait(2); |
screamer | 0:070093b01182 | 28 | } |
screamer | 0:070093b01182 | 29 | } |