Opgeschoonde code voor verslag
Dependencies: Encoder HIDScope MODSERIAL mbed
Fork of TotalCodegr13V2 by
Diff: main.cpp
- Revision:
- 1:7d5e6bc2b314
- Parent:
- 0:65ab9f79a4cc
- Child:
- 2:866a8a9f2b93
diff -r 65ab9f79a4cc -r 7d5e6bc2b314 main.cpp --- a/main.cpp Mon Oct 19 09:31:16 2015 +0000 +++ b/main.cpp Mon Oct 19 13:44:23 2015 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "encoder.h" #include "HIDScope.h" +#include "QEI.h" +#include "MODSERIAL.h" DigitalOut motor1_direction(D4); PwmOut motor1_speed(D5); @@ -52,11 +54,11 @@ { if (button_1 == pressed) { move_motor1_cw (); + } else if (button_2 == pressed) { + move_motor1_ccw (); + } else { + motor1_speed = 0; } - else if (button_2 == pressed) { - move_motor1_ccw (); - } - else movetohome(); } void read_encoder1 () // aflezen van encoder via hidscope?? @@ -69,10 +71,29 @@ int main() { - - sethome(); while (true) { - read_encoder1(); - move_motor1(); - } + pc.baud(9600); //pc baud rate van de computer + + switch (state) { //zorgt voor het in goede volgorde uitvoeren van de cases + + case gotohomeposition: //positie op 0 zetten voor arm 1 + { + read_encoder1(); + sethome(); + state = move_motor; + break; + } + + case move_motor: //motor kan cw en ccw bewegen a.d.h.v. buttons + { + move_motor1 (); + state = homeposition; + break; + } + + case backtohomeposition: //motor gaat terug naar homeposition + { + movetohome(); + break; + } } \ No newline at end of file