press buttons on biorobotics shield to rotate motor in certain direction
Dependencies: Encoder HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 0:4bfe85fb30ab
- Child:
- 1:e0c4625bbbab
diff -r 000000000000 -r 4bfe85fb30ab main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Sep 20 16:15:01 2015 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" +#include "encoder.h" + + +DigitalOut motor2direction(D6); //D4 en D5 zijn motor 2 (op het motorshield) +PwmOut motor2speed(D7); +DigitalOut motor1direction(D4); //D6 en D7 voor motor 1 (op het motorshield) +PwmOut motor1speed(D5); +InterruptIn stop_knop(D8); + + +int main() +{ + Encoder motor2(D13,D12); + int position = motor2.getPosition(); + Serial pc(USBTX,USBRX); + pc.baud(9600); + motor2speed=0.0f; + motor2direction=1; + wait(0.5); + + if(stop_knop.read() == 0) { + motor2speed=0.0f; + } + while (true) { + + while (position <= 12000) { + motor2direction = 1; + motor2speed = 0.1f; + wait(0.1); + pc.printf("while1: pos: %d, speed %f \r\n",motor2.getPosition(), motor2.getSpeed()); + } + while (position >= 70000) { + motor2direction = 0; + motor2speed = 0.1f; + wait(0.1); + pc.printf("while2: pos: %d, speed %f \r\n",motor2.getPosition(), motor2.getSpeed()); + } + while (position <= 700 && position >=4) { + motor2speed = 0.1f; + wait(0.1); + } + } +} \ No newline at end of file