Exercise of motor control
Dependencies: Encoder MODSERIAL mbed
main.cpp@2:6ed3b386d4fa, 2015-09-23 (annotated)
- Committer:
- Technical_Muffin
- Date:
- Wed Sep 23 07:46:49 2015 +0000
- Revision:
- 2:6ed3b386d4fa
- Parent:
- 1:0f99afbd578a
- Child:
- 3:8583035f898b
Fixed naming of function direction 1 and appointing values tp function direction1 and speed1
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 | 2:6ed3b386d4fa | 6 | DigitalOut direction1(D4); |
Technical_Muffin | 2:6ed3b386d4fa | 7 | PwmOut 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 | 1:0f99afbd578a | 17 | //motor CW = 0 |
Technical_Muffin | 1:0f99afbd578a | 18 | //motor CCW = 1 |
Technical_Muffin | 1:0f99afbd578a | 19 | while(PTC6==0){//as long as button is pressed turn on motor |
Technical_Muffin | 2:6ed3b386d4fa | 20 | direction1=1;//turn motor CW |
Technical_Muffin | 2:6ed3b386d4fa | 21 | speed1=1;//Set speed of motor to full. |
Technical_Muffin | 1:0f99afbd578a | 22 | } |
Technical_Muffin | 0:438a9d780499 | 23 | |
Technical_Muffin | 0:438a9d780499 | 24 | while(1) { |
Technical_Muffin | 0:438a9d780499 | 25 | wait(0.2); |
Technical_Muffin | 0:438a9d780499 | 26 | pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed()); |
Technical_Muffin | 1:0f99afbd578a | 27 | // X unit counts equals one magnet shaft rotation, with X being 64 |
Technical_Muffin | 0:438a9d780499 | 28 | } |
Technical_Muffin | 1:0f99afbd578a | 29 | } |