Lire un fichier text

Salut Skywodd :slight_smile:
Merci de ton aide ...

voici mon horrible code traficoté avec plusieurs choses trouvées sur le net.
J'ai plusieurs erreurs et j'ai vraiment du mal mais bon ça vous donnera surement une idée.

#include <SPI.h>
#include <SD.h>

File myFile;
String config;
int led1 = 9;   

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  
  // open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
  File myFile = SD.open("test.txt");
  if(myFile){
    for(int i=0;i<10;i++)
    config[i]=myFile.parseInt();
    
    analogWrite(led1, config[i]);
    delay(5000)
    
    myFile.close();
  }
  
}

mon fichier txt ressemble à ça :

255,100,255,50,100,20,10,200,50,90,85,200,0,0,0,255

Mais je peux le mettre sous une forme différente selon ce qui est plus facile.

Dans mon vrai travail le vecteur sera beaucoup beaucoup plus long.
du coup autre question : il y a t-il une taille maximal de fichier utilisable ?

Encore merci :slight_smile: