Created
December 13, 2023 13:40
-
-
Save blongworth/98c45e90d7b503acf9bba33fc5674d3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <TimeLib.h> | |
#include <SD.h> | |
char FileName[100]; | |
void newFilename(char* FileName1); | |
void newFile(char* FileName1); | |
File myFile; | |
void setup() { | |
Serial.begin(9600); | |
while(!Serial); | |
Serial.print("Initializing SD card..."); | |
if (!SD.begin(BUILTIN_SDCARD)) { | |
Serial.println("initialization failed!"); | |
while (1); | |
} | |
Serial.println("initialization done."); | |
} | |
void loop() { | |
newFilename(FileName); | |
Serial.print("New FileName: "); | |
Serial.println(FileName); | |
newFile(FileName); | |
delay(1000); | |
} | |
void newFilename(char* FileName1) { | |
sprintf(FileName1, "%02d_%02d_%02d_%02d_%02d_%02d.txt", year(), month(), day(), hour(), minute(), second()); | |
Serial.print("New FileName1: "); | |
Serial.println(FileName1); | |
} | |
void newFile(char *FileName1) | |
{ | |
myFile = SD.open(FileName1, FILE_WRITE); | |
if (myFile) { | |
myFile.println("testing 1, 2, 3."); | |
myFile.close(); | |
Serial.println("done."); | |
} else { | |
Serial.println("error opening test.txt"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment