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 00002 #include "mbed.h" 00003 #include <stdio.h> 00004 #include <errno.h> 00005 #include "SDBlockDevice.h" 00006 #include "FATFileSystem.h" 00007 #include "TextLCD.h" 00008 00009 float anselect; 00010 TextLCD lcd(D8, D9, D4, D5, D6, D7); // rs, e, d4-d7 00011 AnalogIn av_sensor(A1); 00012 AnalogIn av_select(A0); 00013 00014 SDBlockDevice blockDevice (D11, D12, D13, D10); // mosi, miso, sck, cs 00015 // File system declaration 00016 char fsistem[]="fs"; 00017 char archivo1[] = "/fs/dato1.txt"; 00018 char archivo2[] = "/fs/dato2.txt"; 00019 char archivo3[] = "/fs/dato3.txt"; 00020 char prueba[] = "/fs/prueba.txt"; 00021 00022 const int tmuestra = 1500; //tamaño de la muestra(tamaño del vector); 00023 float muestra[tmuestra]; //arreglo de la muestra en float; 00024 00025 FATFileSystem fileSystem(fsistem); 00026 int escribeSD(int n, float grab[]); 00027 00028 void inicio(); //Abre o da el formato y crea los archiívos "w+" 00029 void grabacion(); //carga datos analogicos en muestra[tmuestra]; 00030 void escriteSD(int n, float grab);//n es para seleccionar los archivos 00031 int iterpre(); //interpreta los botones del shild LCD 00032 00033 int main() 00034 { 00035 while(1){ 00036 //inicio(); 00037 int n = iterpre(); 00038 int e = 0; 00039 lcd.locate(9,1); 00040 lcd.printf("%d",n); 00041 switch(n) 00042 { 00043 00044 case 0: 00045 //lcd.locate(0,0); 00046 //lcd.printf("esperando... "); 00047 break; 00048 case 1: 00049 //lcd.locate(0,0); 00050 //lcd.printf(" tomando muestra 1 "); 00051 //grabacion(); 00052 //lcd.locate(0,0); 00053 //lcd.printf(" grabando muestra 1 "); 00054 //escribeSD(1,muestra); 00055 //lcd.cls(); 00056 break; 00057 00058 case 2: 00059 //grabacion(); 00060 //escribeSD(2,muestra); 00061 break; 00062 case 3: 00063 //grabacion(); 00064 //escribeSD(3,muestra); 00065 break; 00066 case 4: 00067 //grabacion(); 00068 //escribeSD(4,muestra); 00069 break; 00070 } 00071 } 00072 } 00073 void grabacion(){ 00074 for (int i = 0; i < tmuestra; i++) { 00075 muestra[i] = av_sensor.read(); 00076 printf("\r tomando muestra %f... \n ", muestra[i]); 00077 fflush(stdout); 00078 } 00079 return; 00080 } 00081 void inicio(){ 00082 printf("Montanto el sistema de archivos... "); 00083 fflush(stdout); 00084 int err = fileSystem.reformat(&blockDevice); //formatéa si existe un error 00085 printf("%s\n", (err ? "Fail :(" : "OK")); 00086 FILE * f = fopen(archivo1, "w+"); 00087 err = fclose(f); 00088 FILE * g = fopen(archivo2, "w+"); 00089 err = fclose(g); 00090 FILE * h = fopen(archivo3, "w+"); 00091 err = fclose(h); 00092 FILE * i = fopen(prueba, "w+"); 00093 err = fclose(i); 00094 return; 00095 } 00096 int escribeSD(int n, float grab[]){ 00097 printf("Montanto el sistema de archivos... "); 00098 fflush(stdout); 00099 char ubica[]= ""; 00100 00101 switch(n) 00102 { 00103 case 0: 00104 //ubica = prueba; 00105 break; 00106 case 1: 00107 strcat(archivo1,ubica); 00108 break; 00109 case 2: 00110 strcat(archivo2,ubica); 00111 break; 00112 case 3: 00113 strcat(archivo3,ubica); 00114 break; 00115 case 4: 00116 strcat(prueba,ubica); 00117 break; 00118 } 00119 int err = fileSystem.mount(&blockDevice); //monta el sistema de archivo 00120 FILE* f = fopen(ubica, "r+"); //abre la ubicacion 00121 for (int i = 0; i < tmuestra; i++) { 00122 printf("\rWriting numbers (%d/%d)... ", i, tmuestra); 00123 fflush(stdout); 00124 err = fprintf(f, "%f\n", grab[i]); 00125 if (err < 0) { 00126 printf("Fail :(\n"); 00127 error("error: %s (%d)\n", strerror(errno), -errno); 00128 } 00129 } 00130 printf("Seeking file... "); 00131 fflush(stdout); 00132 err = fseek(f, 0, SEEK_SET); 00133 printf("%s\n", (err < 0 ? "Fail :(" : "OK")); 00134 err = fclose(f); 00135 00136 return 0; 00137 } 00138 int iterpre() 00139 { 00140 00141 00142 anselect = av_select.read(); 00143 float r1 = anselect; 00144 00145 int resp = 0; 00146 int r = r1*100; 00147 lcd.locate(5,1); 00148 lcd.printf("___"); 00149 lcd.locate(5,1); 00150 lcd.printf("%d",r); 00151 if((r < 9)) { 00152 resp = 5; 00153 return resp; 00154 } 00155 if((47 < r)&&(r < 49)) { 00156 resp = 4; 00157 return resp; 00158 } 00159 if((20 < r)&&(r < 24)) { 00160 resp = 3; 00161 return resp; 00162 } 00163 if((73 < r)&&(r < 76)) { 00164 resp = 2; 00165 return resp; 00166 } 00167 if((r == 100)) { 00168 resp = 0; 00169 return resp; 00170 } 00171 if((99 < r)&&(r < 101)) { 00172 resp = 1; 00173 return resp; 00174 } 00175 return resp; 00176 }
Generated on Thu Jul 28 2022 08:24:29 by
1.7.2