Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:8a42934ad23a, 2014-02-20 (annotated)
- Committer:
- shalab
- Date:
- Thu Feb 20 04:56:44 2014 +0000
- Revision:
- 0:8a42934ad23a
- Child:
- 1:35b072614734
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| shalab | 0:8a42934ad23a | 1 | #include "mbed.h" |
| shalab | 0:8a42934ad23a | 2 | #include "VNH5019MC.h" |
| shalab | 0:8a42934ad23a | 3 | |
| shalab | 0:8a42934ad23a | 4 | DigitalOut led1(LED1); |
| shalab | 0:8a42934ad23a | 5 | Serial pc(USBTX, USBRX); |
| shalab | 0:8a42934ad23a | 6 | |
| shalab | 0:8a42934ad23a | 7 | // Motor |
| shalab | 0:8a42934ad23a | 8 | VNH5019MC motor(p19, p20, p21, p22); |
| shalab | 0:8a42934ad23a | 9 | |
| shalab | 0:8a42934ad23a | 10 | int main() { |
| shalab | 0:8a42934ad23a | 11 | pc.printf("\r\n\r\n\r\n"); |
| shalab | 0:8a42934ad23a | 12 | pc.printf("Shalab - Tutorial03_SimpleMotorControl\r\n"); |
| shalab | 0:8a42934ad23a | 13 | |
| shalab | 0:8a42934ad23a | 14 | int duty = 0; |
| shalab | 0:8a42934ad23a | 15 | bool increment = true; |
| shalab | 0:8a42934ad23a | 16 | |
| shalab | 0:8a42934ad23a | 17 | while(1) { |
| shalab | 0:8a42934ad23a | 18 | if ( duty >= 100 ) increment = false; |
| shalab | 0:8a42934ad23a | 19 | if ( duty <= -100) increment = true; |
| shalab | 0:8a42934ad23a | 20 | if (increment) duty++; |
| shalab | 0:8a42934ad23a | 21 | else duty--; |
| shalab | 0:8a42934ad23a | 22 | |
| shalab | 0:8a42934ad23a | 23 | motor.move(duty); |
| shalab | 0:8a42934ad23a | 24 | led1 = !led1; |
| shalab | 0:8a42934ad23a | 25 | wait(0.2); |
| shalab | 0:8a42934ad23a | 26 | } |
| shalab | 0:8a42934ad23a | 27 | } |