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 #include "TextLCD.h" 00003 TextLCD lcd(PTC16, PTC17, PTA16, PTA17, PTE31, PTD6); // rs, e, d4-d7 00004 00005 DigitalIn sensor(PTE20); 00006 00007 Ticker visualiza; 00008 Ticker cuenta; 00009 Ticker x; 00010 int vueltas, rpm; 00011 BusOut sentido_giro(D12, D13); 00012 DigitalIn bajar(D15); 00013 DigitalIn subir(D14); 00014 DigitalIn derecha(PTC12); 00015 DigitalIn izquierda(PTC13); 00016 PwmOut velocidad(D11); 00017 00018 BusOut transistores(D0,D1); 00019 BusOut segmentos (A0,A1,A2,A3,A4,A5,PTE30); 00020 00021 BusOut transistores2(D2, D3); 00022 BusOut segmentos2 (D4,D5,D6,D7, D8,D9, D10); 00023 // tabla de segmentos 00024 const char seg[10] = {0x3f, 0x06,0x5b,0x57,0x66,0x75,0x7d,0x07,0x7f,0x77}; 00025 char unidades,decenas, miliunidades, milidecenas; 00026 void segundo(){ 00027 00028 vueltas = 0; 00029 00030 miliunidades = rpm%10; 00031 milidecenas = (rpm%100)/10; 00032 unidades = (rpm/100)%10; 00033 decenas = rpm/1000; 00034 } 00035 void cambio(){ 00036 static bool bandera; 00037 bandera = !bandera; 00038 switch (bandera){ 00039 case 0: 00040 transistores = 0x0; 00041 segmentos = seg[unidades]; 00042 transistores = 0x2; 00043 00044 transistores2 = 0x0; 00045 segmentos2 = seg[miliunidades]; 00046 transistores2 = 0x2; 00047 00048 break; 00049 case 1: 00050 transistores = 0x0; 00051 segmentos = seg[decenas]; 00052 transistores = 0x1; 00053 00054 transistores2 = 0x0; 00055 segmentos2 = seg[milidecenas]; 00056 transistores2 = 0x1; 00057 00058 break; 00059 }} 00060 unsigned int revol; 00061 00062 int main() { 00063 lcd.cls(); 00064 lcd.printf(" REVOLUCIONES "); 00065 lcd.locate(1, 5); 00066 lcd.printf("POR MINUTO :)"); 00067 sentido_giro = 0x0; 00068 velocidad = 0.15; 00069 rpm = 0; vueltas = 0; 00070 00071 transistores = 0x0; 00072 transistores2 = 0x0; 00073 visualiza.attach(&cambio,0.008333); // tiempo de visualizacion 00074 00075 while(1) { 00076 rpm = vueltas * 60; 00077 00078 if (!derecha && izquierda){ 00079 wait (0.1); 00080 if (derecha==0){ 00081 lcd.cls(); 00082 lcd.printf(" izquierda "); 00083 lcd.locate(1, 5); 00084 lcd.printf(" "); 00085 sentido_giro = 0x1; 00086 } 00087 } 00088 else if (derecha && !izquierda){ 00089 wait (0.1); 00090 if (izquierda==0){ 00091 sentido_giro = 0x2; 00092 lcd.cls(); 00093 lcd.printf(" Derecha "); 00094 lcd.locate(1, 5); 00095 lcd.printf(" "); 00096 } 00097 } 00098 if (subir ==0 ){ 00099 wait (0.5); 00100 velocidad = velocidad + 0.03; 00101 lcd.cls(); 00102 lcd.printf(" Subiendo PWM "); 00103 lcd.locate(1, 5); 00104 lcd.printf (" "); 00105 00106 unidades = 0;decenas = 0; miliunidades = 0; milidecenas = 0; 00107 if (velocidad >= 0.3) { 00108 velocidad = 0.3; 00109 lcd.cls(); 00110 lcd.printf(" RPM maximo "); 00111 lcd.locate(1, 5); 00112 lcd.printf (" "); 00113 } } 00114 if (bajar ==0 ) { 00115 wait(0.5); 00116 velocidad = velocidad - 0.03; 00117 lcd.cls(); 00118 lcd.printf (" Bajando PWM "); 00119 lcd.locate(1, 5); 00120 lcd.printf(" "); 00121 unidades = 0;decenas = 0; miliunidades = 0; milidecenas = 0; 00122 if (velocidad <= 0.0){ 00123 velocidad = 0.0; 00124 lcd.cls(); 00125 lcd.printf(" 0 RPM "); 00126 lcd.locate(1, 5); 00127 lcd.printf (" "); 00128 }} 00129 00130 00131 if (!sensor){ 00132 wait (0.01); 00133 if (sensor==1){ 00134 vueltas = vueltas + 1; 00135 if (vueltas == 1) 00136 { 00137 x.attach(&segundo,1); 00138 00139 00140 } 00141 } 00142 00143 00144 00145 } }}
Generated on Fri Oct 14 2022 01:24:58 by
1.7.2