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
Diff: main.cpp
- Revision:
- 0:6a267a6ae479
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Mar 17 01:27:08 2021 +0000
@@ -0,0 +1,238 @@
+/*Autor: Hugo Campos & Marcelo
+Acionamento de 1 motor de passo com ULN2003
+*/
+
+#include "mbed.h"
+#define velocidade1 2
+#define velocidade2 3
+
+DigitalIn bt1 (PC_4); //Botão Motor 1
+
+DigitalOut in1_m1 (D13); //Bobina 1
+DigitalOut in2_m1 (D12); //Bobina 2
+DigitalOut in3_m1 (D11); //Bobina 3
+DigitalOut in4_m1 (D10); //Bobina 4
+
+InterruptIn FDC1 (PC_2); //Fim de Curso Motor
+InterruptIn FDC2 (PC_3); //Fim de Curso Motor
+DigitalIn BINV (PB_13);//Botão Inversor de de Sentido
+DigitalIn VEL (PB_7);//Botão mudança de Velocidade
+
+InterruptIn emergence (PA_15); //Botão de Emergência
+DigitalOut buzzer (PH_1); //Buzzer de Indicação de Emergência
+
+// ------------ Declarações de Funções do Programa ------------
+void emergencia(void);
+void fimdecurso1(void);
+void fimdecurso2(void);
+
+void step1_X(void);
+void step2_X(void);
+void step3_X(void);
+void step4_X(void);
+void stop_X(void);
+
+// ----------- Variavies do Programa ---------------------
+bool FDC_1_ACIONADO = 0;
+bool FDC_2_ACIONADO = 0;
+bool DEU_MERDA = 0;
+
+// -------------- Programa Principal ---------------
+
+int main()
+{
+ emergence.rise (&emergencia); // Botão de Emergência
+ FDC1.rise (&fimdecurso1); //Botão de Fim de Curso 1
+ FDC2.rise (&fimdecurso2); //Botão de Fim de Curso 2
+ while (1)
+ {
+ if(DEU_MERDA == 0) // IF principal só é acionado se o Botão de Emergência for acionado
+ {
+ if (bt1 == 0 && BINV == 0 && VEL == 0)
+ {
+ printf ("\nMotor Acionado Sentido 1 e Velocidade1");
+ step1_X();
+ wait_ms(velocidade1);
+
+ step2_X();
+ wait_ms (velocidade1);
+
+ step3_X();
+ wait_ms(velocidade1);
+
+ step4_X();
+ wait_ms(velocidade1);
+ }
+ wait_ms (2);
+
+ if (bt1 == 0 && BINV == 1 && VEL == 0)
+ {
+ printf ("\nMotor Acionado Sentido 2 e Velocidade1");
+ step4_X();
+ wait_ms(velocidade1);
+
+ step3_X();
+ wait_ms(velocidade1);
+
+ step2_X();
+ wait_ms(velocidade1);
+
+ step1_X();
+ wait_ms(velocidade1);
+ }
+
+ if (bt1 == 0 && BINV == 0 && VEL == 1)
+ {
+ printf ("\nMotor Acionado Sentido 1 e Velocidade 2");
+ step1_X();
+ wait_ms(velocidade2);
+
+ step2_X();
+ wait_ms(velocidade2);
+
+ step3_X();
+ wait_ms(velocidade2);
+
+ step4_X();
+ wait_ms(velocidade2);
+ }
+
+ if (bt1 == 0 && BINV == 1 && VEL == 1)
+ {
+ printf ("\nMotor Acionado Sentido 2 e Velocidade 2");
+ step4_X();
+ wait_ms(velocidade2);
+
+ step3_X();
+ wait_ms(velocidade2);
+
+ step2_X();
+ wait_ms(velocidade2);
+
+ step1_X();
+ wait_ms(velocidade2);
+ }
+ }//fim deu merda
+
+ if(DEU_MERDA == 1)
+ {
+ stop_X();
+ printf("\n\rEMERGENCIA");
+ }
+ if(emergence == 0)
+ {
+ wait_ms(200);
+ if(emergence == 0)
+ {
+ DEU_MERDA = 0;
+ }
+ }
+ if(FDC_1_ACIONADO == 1)
+ {
+ stop_X();
+ printf("\n\rFim de curso 1");
+ wait_ms(1000);
+ while(FDC_1_ACIONADO == 1)
+ {
+ step1_X();
+ wait_ms(velocidade1);
+ step2_X();
+ wait_ms(velocidade1);
+ step3_X();
+ wait_ms(velocidade1);
+ step4_X();
+ wait_ms(velocidade1);
+ if(FDC1 == 0)
+ {
+ FDC_1_ACIONADO = 0;
+ }
+ }
+ }
+
+ if(FDC_2_ACIONADO == 1)
+ {
+ stop_X();
+ printf("\n\rFim de curso 2");
+ wait_ms(1000);
+ while(FDC_2_ACIONADO == 1)
+ {
+ step1_X();
+ wait_ms(velocidade1);
+ step2_X();
+ wait_ms(velocidade1);
+ step3_X();
+ wait_ms(velocidade1);
+ step4_X();
+ wait_ms(velocidade1);
+ if(FDC2 == 0)
+ {
+ FDC_2_ACIONADO = 0;
+ }
+ }
+ }
+ }//fim da while
+}//fim int main
+
+void emergencia ()
+{
+ DEU_MERDA = 1;
+}
+
+void fimdecurso1 ()
+{
+ wait_ms(30);
+ if(FDC1 == 1)
+ {
+ FDC_1_ACIONADO = 1;
+ }
+}
+
+void fimdecurso2 ()
+{
+ wait_ms(30);
+ if(FDC2 == 1)
+ {
+ FDC_2_ACIONADO = 1;
+ }
+}
+
+void step1_X()
+{
+ in1_m1 = 1;
+ in2_m1 = 0;
+ in3_m1 = 0;
+ in4_m1 = 0;
+}
+
+void step2_X()
+{
+ in1_m1 = 0;
+ in2_m1 = 1;
+ in3_m1 = 0;
+ in4_m1 = 0;
+}
+
+void step3_X()
+{
+ in1_m1 = 0;
+ in2_m1 = 0;
+ in3_m1 = 1;
+ in4_m1 = 0;
+}
+
+void step4_X()
+{
+ in1_m1 = 0;
+ in2_m1 = 0;
+ in3_m1 = 0;
+ in4_m1 = 1;
+}
+
+void stop_X()
+{
+ in1_m1 = 0;
+ in2_m1 = 0;
+ in3_m1 = 0;
+ in4_m1 = 0;
+}
+