Hi everyone, right now I'm stuck in a function in the project of a datalogger, that basically creates directories (years) and inside each of these it creates subdirectories (months).
The problem is that when I use sprintf() it seems to not detect correctly the %s/%s because it only shows the subdirectory (month) and the directory appears blank. I've tried with %04d/%02d which has no sense, but just to give it a try and see what showed up, and it showed the directory (year) and subdir (month), but obviously not with the correct information, just random numbers.
I don't really understand why it only shows one of the parameters in this case the subdirectory, I suppose the problem might be in the operator /'.
Thanks for any help!
Code:
#include<SPI.h>
#include<SD.h>
const int chipSelect = 4; // Arduino Mega
const int DIR_ANYO = 4;
const int SUBDIR_MES = 13;
const char *mes[SUBDIR_MES] = {"", "01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12" }; //Array con los meses
const char *anyo[DIR_ANYO] = {"", "2016", "2017", "2018"};
char dir_subdir [17];
int a = 0, m = 0;
void setup() {
Serial.begin(9600);
pinMode(pinTemp, INPUT);
pinMode(chipSelect, OUTPUT);
Serial.print("Inicializando SD...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Fallo o tarjeta no presente");
// don't do anything more:
return;
}
Serial.println("Tarjeta SD OK");
}
void loop() {
if( m < SUBDIR_MES )
{
sprintf(dir_subdir, "%s/%s", anyo[a], mes[m]);
if(!SD.exists(dir_subdir))
{
if(SD.mkdir(dir_subdir))
{
Serial.println(" ");
Serial.print("Directorio/subdirectorio creado: ");
Serial.print(dir_subdir);
}
if(m == SUBDIR_MES)
{
m = 0;
a++;
Serial.println("directorio completo, creando el siguiente...");
}
else
{
Serial.println("El subdir ya existe, creando el siguiente...");
m++;
}
}
}
else {
Serial.println("Todos los directorios/subdir creados!");
}
}