Advertisement
SallatielFernandes

microSD-millis

Jul 1st, 2022
1,106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.99 KB | None
  1. #include <SPI.h>
  2. #include <SD.h>
  3.  
  4. const int chipSelect = 10;
  5.  
  6. void setup() {
  7.   Serial.begin(9600);
  8.  
  9.   Serial.print("Initializing SD card...");
  10.  
  11.   // see if the card is present and can be initialized:
  12.   if (!SD.begin(chipSelect)) {
  13.     Serial.println("Card failed, or not present");
  14.     while (1);
  15.   }
  16.   Serial.println("card initialized.");
  17. }
  18.  
  19. void loop() {
  20.  
  21.   // open the file. note that only one file can be open at a time,
  22.   // so you have to close this one before opening another.
  23.   File dataFile = SD.open("datalog3.txt", FILE_WRITE);
  24.  
  25.   // if the file is available, write to it:
  26.   if (dataFile) {
  27.     dataFile.print("Este arduino foi ligado a ");
  28.     dataFile.print(millis()/1000);
  29.     dataFile.println(" segundos");
  30.     dataFile.close();
  31.    
  32.     // print serial port:
  33.     Serial.print("Este arduino foi ligado a ");
  34.     Serial.print(millis()/1000);
  35.     Serial.println(" segundos");
  36.  
  37.   }else {
  38.     Serial.println("error opening datalog.txt");
  39.   }
  40.   delay(1000);
  41. }
Advertisement
RAW Paste Data Copied
Advertisement