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: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 11:32deb48774f7
- Parent:
- 10:ad2da21a102c
- Child:
- 12:d13ce121a781
--- a/main.cpp Wed Oct 02 13:49:25 2019 +0000 +++ b/main.cpp Wed Oct 02 14:48:39 2019 +0000 @@ -15,8 +15,11 @@ //Sensors //Buttons - InterruptIn button2(SW2); //button on the side of the reset button - InterruptIn button3(SW3); //button on the side opposite of the reset button + InterruptIn button1(SW2); //button on the side of the reset button + InterruptIn button2(SW3); //button on the side opposite of the reset button + + //PC + Serial pc(USBTX,USBRX); //Variables enum States {MovementIdle, CalibrationIdle, Demo, Startup, CalibrationPhysical, CalibrationEMG, Move, TiltCup, FailState}; @@ -65,51 +68,92 @@ } } +void Run_StateChangerButton1() +{ + switch(CurrentState) + { + case Startup: + CurrentState = CalibrationPhysical; + break; + case CalibrationPhysical: + CurrentState = CalibrationIdle; + break; + case CalibrationIdle: + CurrentState = CalibrationEMG; + break; + case CalibrationEMG: + CurrentState = MovementIdle; + break; + case MovementIdle: + CurrentState = TiltCup; + break; + case TiltCup: + CurrentState = MovementIdle; + break; + case Move: + CurrentState = MovementIdle; + break; + } +} + void Run_Demo(void) { - pc.prinf("Starting Demo ...\r\n") + pc.printf("Starting Demo ...\r\n"); } void Run_MovementIdle(void) { - pc.prinf("Starting Idle ...\r\n") + pc.printf("Starting Idle ...\r\n"); + //button1.rise(Run_StateChangerButton1); + //button2.rise(CurrentState = Move); } void Run_CalibrationIdle(void) { - pc.prinf("Starting Calibration Idle ...\r\n") + pc.printf("Starting Calibration Idle ...\r\n"); + //button1.rise(Run_StateChangerButton1); + //button2.rise(CurrentState = Demo); } void Run_Startup(void) { - pc.prinf("Starting Startup ...\r\n") + pc.printf("Starting Startup ...\r\n"); + //button1.rise(Run_StateChangerButton1); } void Run_CalibrationPhysical(void) { - pc.prinf("Starting Calibration Physical ... \r\n") + pc.printf("Starting Calibration Physical ... \r\n"); + wait(2); + CurrentState = CalibrationIdle; + } void Run_CalibrationEMG(void) { - pc.prinf("Starting Calibration EMG ... \r\n") + pc.printf("Starting Calibration EMG ... \r\n"); + //button1.rise(Run_StateChangerButton1); } void Run_Move(void) { - + pc.printf("Starting Calibration Move ... \r\n"); + //button1.rise(Run_StateChangerButton1); } void Run_TiltCup(void) { - + pc.printf("Starting Calibration TiltCup ... \r\n"); + //button1.rise(Run_StateChangerButton1); + //buttone2.ruse(CurrentState = FailState); } void Run_FailState(void) { - + pc.printf("Starting Calibration FailState ... \r\n"); } + //State Machine void StateMachine(void) { @@ -121,40 +165,40 @@ switch(CurrentState) { case Demo: - Run_Demo; - ledcolor='t'; + ledcolor='g'; + Run_Demo(); break; case MovementIdle: - Run_MovementIdle; - ledcolor='b'; + ledcolor='g'; + Run_MovementIdle(); break; case CalibrationIdle: - Run_CalibrationIdle; - ledcolor='b'; + ledcolor='g'; + Run_CalibrationIdle(); break; case Startup: - Run_Startup; - ledcolor='b'; + ledcolor='g'; + Run_Startup(); break; case CalibrationPhysical: - Run_CalibrationPhysical; ledcolor='g'; + Run_CalibrationPhysical(); break; case CalibrationEMG: - Run_CalibrationEMG; ledcolor='g'; + Run_CalibrationEMG(); break; case Move: - Run_Move; ledcolor='p'; + Run_Move(); break; case TiltCup: - Run_TiltCup; ledcolor='t'; + Run_TiltCup(); break; case FailState: - Run_FailState; - ledcolor='r'; + ledcolor='t'; + Run_FailState(); break; } } @@ -168,11 +212,17 @@ int main() { //Initialize - + + + pc.baud(115200); Tick_Blinky.attach(FlipLED,1); CurrentState = Startup; Main_Ticker.attach(mainloop,2); + button1.mode(PullUp); + button1.rise(Run_StateChangerButton1); + button2.mode(PullUp); + while(true) {