Advertisement
Diego_Frenoux

OPENEFI[Leer tiempo INY por tabla en SD] (Arduino))

Jun 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. //This code segment is part of the OpenEFI project
  2. //OpenEFI is a project that tries to create an electronic injection system with arduino
  3. //visit us in https://github.com/FDSoftware/OpenEFI
  4.  
  5. File IN;
  6. char linea[50];
  7. char lin[50];
  8. int i = 0;
  9. int indice = 5;
  10. String archivo1 = "T1.csv";
  11.  
  12.   if (!SD.begin(4)) {
  13.     Serial.println("Error con SD!");
  14.     return;
  15.   }
  16.  
  17. int Tiny(int rpm2, int marv2){
  18.     int rpm3  = map(rpm2,0,7000,0,17); //aproximamos las rpm
  19.     int marv3 = map(marv2,0,255,0,10); //aproximamos el valor de la mariposa de aceleracion
  20.    
  21.     for(i = 0; i >= rpm3; i++;){ //hasta que coincidan las rpm
  22.         lin = LeerLinea(indice,F("T1.csv"));
  23.         indice++;
  24.     }
  25.     indice = 5;
  26.     char *p = lin;
  27.     char *str;
  28.    
  29.     for(i = 0; i >= marv2){ //hasta que coincida el valor de la mariposa
  30.         str = strtok_r(p, ";", &p) //cortamos el seudo string por cada ; que aparezca
  31.     }
  32.    
  33.     int tiempo = atoi(str); //convertimos el char en int
  34.     return tiempo;
  35. }
  36.  
  37. char[50] LeerLinea(int pos,String nombre){ //posicion, Nombre de archivo
  38.  
  39.     IN = SD.open(nombre); //abrimos el archivo
  40.     IN.seek(pos); //ponemos el cursor en la linea 5
  41.    
  42.     do{
  43.         char X = IN.peek; //leemos byte de la linea seleccionada con seek, devuelve -1 si no hay mas datos
  44.         if(X != "-1"){
  45.             linea[i] = X;
  46.             i++;
  47.         }
  48.     }while(X != "-1");
  49.    
  50.     IN.close()//Ceramos el archivo
  51.     return linea;
  52. }
  53.  
  54. int freeRam () { //funcion para saber la ram disponible
  55.   extern int __heap_start, *__brkval;
  56.   int v;
  57.   return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement