Help with logic in saving tables

when you check this:

 if (indexForFileNames==0) {
    saveThis=true;
  }

it would be executed only once during the time span (because then we set indexForFileNames to 1)

full code section:


int indexForFileNames=-1;
boolean saveThis = false; // tells the sketch to save  

if (timeDiff < recTime) {
  osc.freq(freqList[0]);
  indexForFileNames=0;
} else if (timeDiff >= recTime && timeDiff < recTime*2) {
  if (indexForFileNames==0) {
    saveThis=true;
  }
  osc.freq(freqList[1]);
  indexForFileNames=1;
} else if (timeDiff >= recTime*2 && timeDiff < recTime*3) {
  if (indexForFileNames==1) {
    saveThis=true;
  }
  osc.freq(freqList[2]);
  indexForFileNames=2;
} else if (timeDiff >= recTime*3 && timeDiff < recTime*4) {
  if (indexForFileNames==2) {
    saveThis=true;
  }
  osc.freq(freqList[3]);
  indexForFileNames=3;
} else if (timeDiff >= recTime*4 && timeDiff < recTime*5) {
  if (indexForFileNames==3) {
    saveThis=true;
  }
  osc.freq(freqList[4]);
  indexForFileNames=4;
} else if (timeDiff >= recTime*5 && timeDiff < recTime*6) {
  if (indexForFileNames==4) {
    saveThis=true;
  }
  osc.freq(freqList[5]);
  indexForFileNames=5;
}


// save
if (saveThis && (indexForFileNames>0)) {
  // syntax: saveTable(table, filename)
  saveTable(table, fileNames[indexForFileNames - 1]; // using -1 here !!!!
  saveThis = false;
}

//

Chrisir

1 Like