Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* old tryme.txt code
- C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor9\helperCode.h
- */
- int t=0;
- void tme(void) {
- Serial.println("Im in the helperCode.h INC file ");
- }
- void doLED2() {
- t++; if(t==2) t=0;
- // Serial.print("t3=");
- // Serial.println(t);
- //Serial.print(LED_BUILTIN);
- if (t==1) digitalWrite(LED_BUILTIN, HIGH);
- if (t==0) digitalWrite(LED_BUILTIN, LOW);
- }
- void listDir(const char * dirname) {
- Serial.printf("Listing directory: %s\n", dirname);
- Dir root = LittleFS.openDir(dirname);
- while (root.next()) {
- File file = root.openFile("r");
- Serial.print(" FILE: ");
- Serial.print(root.fileName());
- Serial.print(" SIZE: ");
- Serial.print(file.size());
- time_t cr = file.getCreationTime();
- time_t lw = file.getLastWrite();
- file.close();
- struct tm * tmstruct = localtime(&cr);
- Serial.printf(" CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
- tmstruct = localtime(&lw);
- Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
- }
- }
- void readFile(const char * path) {
- Serial.printf("Reading file: %s\n", path);
- File file = LittleFS.open(path, "r");
- if (!file) {
- Serial.println("Failed to open file for reading");
- return;
- }
- Serial.print("Read from file: ");
- while (file.available()) {
- Serial.write(file.read());
- }
- file.close();
- }
- void writeFile(const char * path, const char * message) {
- Serial.printf("Writing file: %s\n", path);
- File file = LittleFS.open(path, "w");
- if (!file) {
- Serial.println("Failed to open file for writing");
- return;
- }
- if (file.print(message)) {
- Serial.println("File written");
- } else {
- Serial.println("Write failed");
- }
- delay(2000); // Make sure the CREATE and LASTWRITE times are different
- file.close();
- }
- void appendFile(const char * path, const char * message) {
- Serial.printf("Appending to file: %s\n", path);
- File file = LittleFS.open(path, "a");
- if (!file) {
- Serial.println("Failed to open file for appending");
- return;
- }
- if (file.print(message)) {
- Serial.println("Message appended");
- } else {
- Serial.println("Append failed");
- }
- file.close();
- }
- void renameFile(const char * path1, const char * path2) {
- Serial.printf("Renaming file %s to %s\n", path1, path2);
- if (LittleFS.rename(path1, path2)) {
- Serial.println("File renamed");
- } else {
- Serial.println("Rename failed");
- }
- }
- void deleteFile(const char * path) {
- Serial.printf("Deleting file: %s\n", path);
- if (LittleFS.remove(path)) {
- Serial.println("File deleted");
- } else {
- Serial.println("Delete failed");
- }
- }
- //uint32_t uxt=1455451200; //Arbitrary early date.
- uint32_t uxt=1455451200 + millis(); //Millis added,just to make a difference
- time_t myTimeCallback() {
- // return 1455451200; // UNIX timestamp
- return uxt ; // UNIX timestamp
- }
Advertisement
Add Comment
Please, Sign In to add comment