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.
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX, USBRX); 00004 00005 InterruptIn botao_SW1(D2); 00006 InterruptIn botao_SW2(D7); 00007 00008 Timer debounceSW1Fall; 00009 Timer debounceSW2Fall; 00010 Timer debounceSW1Rise; 00011 Timer debounceSW2Rise; 00012 Timer avanco; 00013 00014 AnalogIn Shunt(A5); 00015 float Corrente; 00016 00017 DigitalOut saida_IN1(D10); 00018 DigitalOut saida_IN2(D8); 00019 DigitalOut saida_EN(D9); 00020 00021 bool SW1 = 1; 00022 bool SW2 = 1; 00023 bool IN1 = 0; 00024 bool IN2 = 0; 00025 00026 void DSW1Fall(){ 00027 00028 if (debounceSW1Fall.read_ms() > 200) { 00029 SW1 = 0; 00030 debounceSW1Fall.reset(); 00031 pc.printf("DSW1Fall \n\r"); 00032 00033 avanco.start(); 00034 } 00035 } 00036 00037 void DSW2Fall(){ 00038 00039 if (debounceSW2Fall.read_ms() > 200) { 00040 SW2 = 0; 00041 debounceSW2Fall.reset(); 00042 pc.printf("DSW2Fall \n\r"); 00043 } 00044 } 00045 00046 void DSW1Rise(){ 00047 if (debounceSW1Rise.read_ms() > 200) { 00048 if(avanco.read_ms() >= 500) { 00049 avanco.stop(); 00050 avanco.reset(); 00051 } 00052 else if(avanco.read_ms() < 500){ 00053 SW1 = 1; 00054 } 00055 debounceSW1Rise.reset(); 00056 pc.printf("DSW1Rise \n\r"); 00057 } 00058 } 00059 00060 void DSW2Rise(){ 00061 if (debounceSW2Rise.read_ms() > 200) { 00062 SW2 = 1; 00063 debounceSW2Rise.reset(); 00064 pc.printf("DSW2Rise \n\r"); 00065 } 00066 } 00067 00068 int main() { 00069 debounceSW1Fall.start(); 00070 debounceSW2Fall.start(); 00071 debounceSW1Rise.start(); 00072 debounceSW2Rise.start(); 00073 00074 botao_SW1.rise(&DSW1Rise); 00075 botao_SW1.fall(&DSW1Fall); 00076 botao_SW2.rise(&DSW2Rise); 00077 botao_SW2.fall(&DSW2Fall); 00078 00079 while(1){ 00080 00081 Corrente = 3.3f*Shunt; 00082 00083 if (Corrente > 0.7f){ 00084 if (IN1 && !IN2){ 00085 saida_IN1 = IN2; 00086 saida_IN2 = IN1; 00087 wait_ms(250); 00088 } 00089 else if (IN2 && !IN1){ 00090 saida_IN1 = IN2; 00091 saida_IN2 = IN1; 00092 wait_ms(250); 00093 } 00094 saida_IN1 = 0; 00095 saida_IN2 = 0; 00096 SW1 = 1; 00097 SW2 = 1; 00098 wait_ms(1000); 00099 } 00100 00101 if (SW1 == 0){ 00102 IN1 = 1; IN2 = 0; 00103 saida_EN = 1; 00104 saida_IN1 = IN1; 00105 saida_IN2 = IN2; 00106 wait(0.01); 00107 } 00108 00109 else if (SW2 == 0){ 00110 IN1 = 0; IN2 = 1; 00111 saida_EN = 1; 00112 saida_IN1 = IN1; 00113 saida_IN2 = IN2; 00114 wait(0.01); 00115 } 00116 else { 00117 IN1 = 0; IN2 = 0; 00118 saida_EN = 0; 00119 saida_IN1 = IN1; 00120 saida_IN2 = IN2; 00121 wait(0.01); 00122 } 00123 wait(0.01); 00124 pc.printf("Timer: %.2f s \n\r", avanco.read()); 00125 } 00126 }
Generated on Sat Jul 30 2022 22:57:14 by
