Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <SD.h>
  2. #include "RTClib.h"
  3. #include <Wire.h>
  4. #include <string.h>
  5.  
  6. RTC_DS1307 RTC;
  7. char filename[] = "00000000.TXT";
  8. char dir[] = "asd/";
  9. File myFile;
  10.  
  11. char data[100];
  12. char* myName = filename;
  13. char* Name = "asd/";
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. void setup()
  21. {
  22. Serial.begin(9600);
  23. Wire.begin(); //Important for RTClib.h
  24. RTC.begin();
  25.  
  26. if (! RTC.isrunning()) {
  27.  
  28. Serial.println("RTC is NOT running!");
  29. return;
  30. }
  31.  
  32. Serial.print("Initializing SD card...");
  33.  
  34. pinMode(4, OUTPUT);
  35.  
  36. if (!SD.begin(4)) {
  37. Serial.println("initialization failed!");
  38. return;
  39. }
  40. Serial.println("initialization done.");
  41. }
  42.  
  43. void loop()
  44. {
  45.  
  46. getFileName();
  47. createFileName();
  48. delay(3000);
  49. }
  50.  
  51. void getFileName(){
  52.  
  53. DateTime now = RTC.now();
  54.  
  55. filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
  56. filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
  57. filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
  58. filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
  59. filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
  60. filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
  61. filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
  62. filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()
  63.  
  64. }
  65.  
  66. void createFileName(){
  67. String var1 = filename;
  68.  
  69.  
  70. sprintf(data,"asd/%s", myName);
  71. Serial.println(data);
  72. myFile = SD.open(data, FILE_WRITE);
  73. myFile.close();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement