Hi,
@UKHeliBob meant the Serial.print lines. If you would like to use them later, then comment them for the test like this:
//Serial.print("sensor = ");
//Serial.print(sensorValue);
//Serial.print("\t");
//Serial.print("output = ");
//Serial.print(outputValue);
//Serial.print("\t");
//Serial.print("Timestart = ");
//Serial.println(starttime);
This is the file open command, put this in the end of the setup block (after SD.begin).
mySensorData= SD.open("PTData.txt",FILE_WRITE);
I don't know why exit(0) is used, but you can close the file there for example.
You stop data gathering by grounding the A0 pin?
So your loop can be something like this:
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
if (sensorValue != 1023){
starttime = micros();
if (sensorValue == 0) {
mySensorData.close(); // Close the file
exit(0);
}
}
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the Serial Monitor:
mySensorData= SD.open("PTData.txt",FILE_WRITE);
if (mySensorData) {
//Serial.print("sensor = ");
//Serial.print(sensorValue);
//Serial.print("\t");
//Serial.print("output = ");
//Serial.print(outputValue);
//Serial.print("\t");
//Serial.print("Timestart = ");
//Serial.println(starttime);
mySensorData.print(sensorValue);
mySensorData.print(",");
mySensorData.print(outputValue);
mySensorData.print(",");
mySensorData.println(starttime);
}
}
What rate are you aiming at? I'm pretty sure, that SD write would be faster this way (instead of separate mySensorData.print() calls):
char dataToPrint[32];
snprintf(dataToPrint, 32, "%u,%u,%lu\r\n", sensorValue, outputValue, starttime);
mySensorData.print(dataToPrint);