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: HIDScope MODSERIAL QEI biquadFilter mbed
main.cpp
- Committer:
- Luuk
- Date:
- 2017-10-07
- Revision:
- 0:1b8a08e9a66c
- Child:
- 1:14b685c3abbd
File content as of revision 0:1b8a08e9a66c:
#include "mbed.h" //#include "QEI.h" #include "MODSERIAL.h" //#include "HIDScope.h" Serial pc (USBTX,USBRX); //PwmOut Motor1Vel(D6); //motor 1 velocity control //DigitalOut Motor1Dir(D7); //motor 1 direction //PwmOut Motor2Vel(D5); //motor 2 velocity control //DigitalOut Motor2Dir(D4); //motor 2 direction DigitalOut led1(D8); DigitalOut led2(D9); AnalogIn emgx(A0); AnalogIn emgy(A1); //DigitalOut ledb(LED1); Ticker switch_tick; float limitx =3, limity = 3, positionx = 1, positiony = 1; int i = 0; //counter to go back to initial position if there is no activity void movex() { led1 = 1; } void movey() { led2 = 1; } void movexy() { led2 = 1; led1 = 1; } void initialPosition() { led2 = 0; led1 = 0; } int choosecase(float emgx, float emgy) { int a = 0; if (emgx > 0 && emgy == 0) { a = 1; i = 0; } else if (emgx == 0 && emgy > 0) { a = 2; i = 0; } else if (emgx > 0 && emgy > 0) { a = 3; i = 0; } else if (positionx >= limitx || positiony >= limity) { a = 4; i = 0; } else if (i > 199) { a = 4; i = 0; } else { i++; } pc.printf("emgx: %f emgy: %f \r\n",emgx,emgy); return a; } void selectcase() { int switchcons = choosecase(emgx,emgy); switch(switchcons) { case 1: movex(); break; case 2: movey(); break; case 3: movexy(); break; case 4: initialPosition(); break; default: break; } pc.printf("Chosen case: %d \r\n",switchcons); } main() { pc.baud(115200); switch_tick.attach(&selectcase,0.01); while (true) { } }