Advertisement
MarceloFerreira

Prog dois

Oct 22nd, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3.  
  4. #include <SPI.h>
  5. #include <SD.h>
  6.  
  7. RTC_DS1307 rtc;
  8.  
  9. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  10.  
  11. const int chipSelect = 4;
  12. int sensor1=30, sensor2=25, sensor3=90;
  13.  
  14. int ano,dia,mes,hora,minuto,segundo;
  15. char sem;
  16.  
  17. File dataFile;
  18.  
  19. void setup()
  20. {
  21. Serial.begin(9600);
  22.  
  23. //********************** Iniciando o RTC ***************************************
  24. if (! rtc.begin())
  25. {
  26. Serial.println("RTC Não Encontrado");
  27. while (1);
  28. }
  29.  
  30. if (! rtc.isrunning())
  31. {
  32. Serial.println("RTC is NOT running!");
  33. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  34. rtc.adjust(DateTime(2015, 1, 21, 3, 0, 0));
  35. }
  36.  
  37. delay(500);
  38. //********************** Inicando o SD ***************************************
  39.  
  40. Serial.print("Initializing SD card...");
  41. // make sure that the default chip select pin is set to
  42. // output, even if you don't use it:
  43. pinMode(SS, OUTPUT);
  44.  
  45. // see if the card is present and can be initialized:
  46. if (!SD.begin(chipSelect)) {
  47. Serial.println("Card failed, or not present");
  48. // don't do anything more:
  49. while (1) ;
  50. }
  51. Serial.println("card initialized.");
  52.  
  53. //********************** Cria o Arquivo no SD ***************************************
  54. // Open up the file we're going to log to!
  55. dataFile = SD.open("teste.txt", FILE_WRITE);
  56. if (! dataFile) {
  57. Serial.println("error opening datalog.txt");
  58. // Wait forever since we cant write data
  59. while (1) ;
  60. }
  61.  
  62. }
  63.  
  64. void loop()
  65. {
  66. DateTime now = rtc.now();
  67.  
  68. ano=now.year();
  69. mes=now.month();
  70. dia=now.day();
  71. hora=now.hour();
  72. minuto=now.minute();
  73. segundo=now.second();
  74.  
  75. dataFile = SD.open("teste.txt", FILE_WRITE);
  76.  
  77.  
  78. dataFile.print(String(dia));
  79. dataFile.print('/');
  80. dataFile.print(String(mes));
  81. dataFile.print('/');
  82. dataFile.print(String(ano));
  83. dataFile.print(" (");
  84. dataFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
  85. dataFile.print(") ");
  86. dataFile.print(String(hora));
  87. dataFile.print(':');
  88. dataFile.print(String(minuto));
  89. dataFile.print(':');
  90. dataFile.print(String(segundo));
  91. dataFile.print('|');
  92. dataFile.print(String(sensor1));
  93. dataFile.print('|');
  94. dataFile.print(String(sensor2));
  95. dataFile.print('|');
  96. dataFile.print(String(sensor3));
  97. dataFile.println();
  98. Serial.print(hora);
  99. Serial.print(':');
  100. Serial.print(minuto);
  101. Serial.print(':');
  102. Serial.print(segundo);
  103. Serial.print(':');
  104. Serial.println("Salvo");
  105. dataFile.close();
  106. delay(1000);
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement