Skip to content

Instantly share code, notes, and snippets.

@nazt
Created April 1, 2020 04:21
Show Gist options
  • Save nazt/e45ed3bc0ab8ff5319cb9f2c0345e852 to your computer and use it in GitHub Desktop.
Save nazt/e45ed3bc0ab8ff5319cb9f2c0345e852 to your computer and use it in GitHub Desktop.
sensorTask.ino
void sensorTask(void *parameter)
{
int delay;
vTaskDelay(10 * 1000 / portTICK_PERIOD_MS);
while (1)
{
sdcard = SD.open(filenamestring, FILE_WRITE);
digitalWrite(LED_BUILTIN, HIGH);
if (sdcard && rtcOk) {
sdcard.print(datestring);
sdcard.print(",");
sdcard.print(timestring);
sdcard.print(",");
sdcard.print(temperatureC);
sdcard.println();
sdcard.flush();
sdcard.close();
Serial.println("Write done...");
delay = 10;
} else {
delay = 1;
Serial.println("Write failed.");
}
vTaskDelay(20 / portTICK_PERIOD_MS);
digitalWrite(LED_BUILTIN, LOW);
vTaskDelay(delay * 1000 / portTICK_PERIOD_MS);
}
vTaskDelete( NULL );
}
void setup()
{
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
Serial.print("Initializing SD card...");
RtcSetup();
/* initialize SD library with SPI pins */
if (!SD.begin(13, 15, 2, 14)) { //T1:13,15,2,14 T2: 23,5,19,18 M5:4,23,19,18 uint8_t csPin, int8_t mosi, int8_t miso, int8_t sck
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
xTaskCreate(sensorTask, "sensorTask", 1024, NULL, 1, NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment