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.
Dependencies: Encoder MODSERIAL mbed
main.cpp@0:438a9d780499, 2015-09-23 (annotated)
- Committer:
- Technical_Muffin
- Date:
- Wed Sep 23 07:13:29 2015 +0000
- Revision:
- 0:438a9d780499
- Child:
- 1:0f99afbd578a
First commit of motor control exercise
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Technical_Muffin | 0:438a9d780499 | 1 | #include "mbed.h" |
Technical_Muffin | 0:438a9d780499 | 2 | #include "encoder.h" |
Technical_Muffin | 0:438a9d780499 | 3 | #include "MODSERIAL.h" |
Technical_Muffin | 0:438a9d780499 | 4 | |
Technical_Muffin | 0:438a9d780499 | 5 | DigitalOut led(LED_RED); |
Technical_Muffin | 0:438a9d780499 | 6 | DigitalOut motor1(D4); |
Technical_Muffin | 0:438a9d780499 | 7 | Digitalout speed1(D5); |
Technical_Muffin | 0:438a9d780499 | 8 | DigitalIn button(PTC6); |
Technical_Muffin | 0:438a9d780499 | 9 | |
Technical_Muffin | 0:438a9d780499 | 10 | Encoder motor1(D13,D12,true); |
Technical_Muffin | 0:438a9d780499 | 11 | MODSERIAL pc(USBTX,USBRX); |
Technical_Muffin | 0:438a9d780499 | 12 | |
Technical_Muffin | 0:438a9d780499 | 13 | int main() |
Technical_Muffin | 0:438a9d780499 | 14 | { |
Technical_Muffin | 0:438a9d780499 | 15 | pc.baud(115200); |
Technical_Muffin | 0:438a9d780499 | 16 | |
Technical_Muffin | 0:438a9d780499 | 17 | //speed CW = -1 |
Technical_Muffin | 0:438a9d780499 | 18 | //speed CCW = +1 |
Technical_Muffin | 0:438a9d780499 | 19 | while(PTC6==0){/as long as button is pressed turn on motor |
Technical_Muffin | 0:438a9d780499 | 20 | motor1(-1);//turn motor CW |
Technical_Muffin | 0:438a9d780499 | 21 | |
Technical_Muffin | 0:438a9d780499 | 22 | |
Technical_Muffin | 0:438a9d780499 | 23 | while(1) { |
Technical_Muffin | 0:438a9d780499 | 24 | wait(0.2); |
Technical_Muffin | 0:438a9d780499 | 25 | pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed()); |
Technical_Muffin | 0:438a9d780499 | 26 | // X unit counts equals one magnet shaft rotation, with X being 36 |
Technical_Muffin | 0:438a9d780499 | 27 | } |
Technical_Muffin | 0:438a9d780499 | 28 | } |