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
Revision 0:839e4a71257c, committed 2020-04-13
- Comitter:
- Marcelocostanzo
- Date:
- Mon Apr 13 11:10:28 2020 +0000
- Commit message:
- Stepper + joystick
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 839e4a71257c main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Apr 13 11:10:28 2020 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+DigitalOut X_COIL_A1(D2);
+DigitalOut X_COIL_A2(D3);
+DigitalOut X_COIL_B1(D4);
+DigitalOut X_COIL_B2(D5);
+
+DigitalOut Y_COIL_A1(D6);
+DigitalOut Y_COIL_A2(D7);
+DigitalOut Y_COIL_B1(D8);
+DigitalOut Y_COIL_B2(D9);
+
+AnalogIn X_AXIS_ADC(A0);
+AnalogIn Y_AXIS_ADC(A1);
+
+Serial PC(USBTX, USBRX);
+
+int main()
+{
+ float X_AXIS, Y_AXIS;
+ float X_PERIOD, Y_PERIOD;
+ int X_LAST_STEP = 1;
+ int Y_LAST_STEP = 1;
+
+ while(1)
+ {
+ X_AXIS = X_AXIS_ADC * 4096; //0 a 4096 degraus
+ Y_AXIS = Y_AXIS_ADC * 4096; //0 a 4096 degraus
+
+ X_AXIS = X_AXIS - 2048; //ira descolar a leitura,pois o joystick em repouso entrega meia tensão
+ Y_AXIS = Y_AXIS - 2048; //ira descolar a leitura,pois o joystick em repouso entrega meia tensão
+
+ X_PERIOD = 1 / X_AXIS; //1 a 0,000488 segundos (488uS)
+ Y_PERIOD = 1 / Y_AXIS; //1 a 0,000488 segundos (488uS)
+
+ if(X_LAST_STEP > 4) X_LAST_STEP = 1; //reinicia o indexador de passos
+ if(Y_LAST_STEP > 4) Y_LAST_STEP = 1; //reinicia o indexador de passos
+
+
+ /*--------Rotina para rotacionar os motores----------------------------------------------------------------*/
+ if(X_AXIS > 10)
+ {
+ switch (X_LAST_STEP)
+ {
+ case 1: X_COIL_A1 = 1; X_COIL_A2 = 0; X_COIL_B1 = 0; X_COIL_B2 = 0; X_LAST_STEP++; wait(X_PERIOD); break;
+ case 2: X_COIL_A1 = 0; X_COIL_A2 = 1; X_COIL_B1 = 0; X_COIL_B2 = 0; X_LAST_STEP++; wait(X_PERIOD); break;
+ case 3: X_COIL_A1 = 0; X_COIL_A2 = 0; X_COIL_B1 = 1; X_COIL_B2 = 0; X_LAST_STEP++; wait(X_PERIOD); break;
+ case 4: X_COIL_A1 = 0; X_COIL_A2 = 0; X_COIL_B1 = 0; X_COIL_B2 = 1; X_LAST_STEP++; wait(X_PERIOD); break;
+ }
+ }
+
+ if(X_AXIS < -10)
+ {
+ switch (X_LAST_STEP)
+ {
+ case 4: X_COIL_A1 = 1; X_COIL_A2 = 0; X_COIL_B1 = 0; X_COIL_B2 = 0; X_LAST_STEP++; wait(X_PERIOD); break;
+ case 3: X_COIL_A1 = 0; X_COIL_A2 = 1; X_COIL_B1 = 0; X_COIL_B2 = 0; X_LAST_STEP++; wait(X_PERIOD); break;
+ case 2: X_COIL_A1 = 0; X_COIL_A2 = 0; X_COIL_B1 = 1; X_COIL_B2 = 0; X_LAST_STEP++; wait(X_PERIOD); break;
+ case 1: X_COIL_A1 = 0; X_COIL_A2 = 0; X_COIL_B1 = 0; X_COIL_B2 = 1; X_LAST_STEP++; wait(X_PERIOD); break;
+ }
+ }
+
+ if(Y_AXIS > 10)
+ {
+ switch (Y_LAST_STEP)
+ {
+ case 1: Y_COIL_A1 = 1; Y_COIL_A2 = 0; Y_COIL_B1 = 0; Y_COIL_B2 = 0; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ case 2: Y_COIL_A1 = 0; Y_COIL_A2 = 1; Y_COIL_B1 = 0; Y_COIL_B2 = 0; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ case 3: Y_COIL_A1 = 0; Y_COIL_A2 = 0; Y_COIL_B1 = 1; Y_COIL_B2 = 0; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ case 4: Y_COIL_A1 = 0; Y_COIL_A2 = 0; Y_COIL_B1 = 0; Y_COIL_B2 = 1; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ }
+ }
+
+ if(Y_AXIS < -10)
+ {
+ switch (Y_LAST_STEP)
+ {
+ case 4: Y_COIL_A1 = 1; Y_COIL_A2 = 0; Y_COIL_B1 = 0; Y_COIL_B2 = 0; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ case 3: Y_COIL_A1 = 0; Y_COIL_A2 = 1; Y_COIL_B1 = 0; Y_COIL_B2 = 0; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ case 2: Y_COIL_A1 = 0; Y_COIL_A2 = 0; Y_COIL_B1 = 1; Y_COIL_B2 = 0; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ case 1: Y_COIL_A1 = 0; Y_COIL_A2 = 0; Y_COIL_B1 = 0; Y_COIL_B2 = 1; Y_LAST_STEP++; wait(Y_PERIOD); break;
+ }
+ }
+
+ }
+}
diff -r 000000000000 -r 839e4a71257c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 13 11:10:28 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file