Advertisement
pleasedontcode

Test rev_01

Nov 20th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Test
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-11-20 13:47:51
  15.     - Source Code generated by: Cippa
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <SPI.h>
  21. #include <SdFat.h>
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* Write timestamp to SD card */
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup();
  28. void loop();
  29.  
  30. /***** DEFINITION OF SPI PINS *****/
  31. const uint8_t SD_CARD_MODULE_SPI_PIN_MOSI = 11;
  32. const uint8_t SD_CARD_MODULE_SPI_PIN_MISO = 12;
  33. const uint8_t SD_CARD_MODULE_SPI_PIN_SCLK = 13;
  34. const uint8_t SD_CARD_MODULE_SPI_PIN_CS = 10;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. SdFat sd;
  38. SdFile file;
  39.  
  40. void setup() {
  41.   // Start the SPI library
  42.   SPI.begin();
  43.  
  44.   // Initialize the SD card
  45.   if (!sd.begin(SD_CARD_MODULE_SPI_PIN_CS, SPI_HALF_SPEED)) {
  46.     // Handle SD card initialization error
  47.     Serial.println("SD card initialization failed!");
  48.     while (true) {
  49.       // Wait indefinitely
  50.       delay(1000);
  51.     }
  52.   }
  53.  
  54.   // Remove existing files if any
  55.   sd.remove("default.txt");
  56.   sd.remove("stamp.txt");
  57.  
  58.   // Create and write to file "default.txt"
  59.   if (!file.open("default.txt", O_WRONLY | O_CREAT)) {
  60.     // Handle file opening error
  61.     sd.errorHalt("Failed to open default.txt");
  62.   }
  63.   file.close();
  64.  
  65.   // Create file "stamp.txt" and set timestamps
  66.   if (!file.open("stamp.txt", O_WRONLY | O_CREAT)) {
  67.     // Handle file opening error
  68.     sd.errorHalt("Failed to open stamp.txt");
  69.   }
  70.   if (!file.timestamp(T_CREATE, 2022, 9, 1, 12, 0, 0)) {
  71.     // Handle timestamp setting error
  72.     sd.errorHalt("Failed to set create timestamp");
  73.   }
  74.   if (!file.timestamp(T_WRITE, 2022, 9, 1, 12, 0, 0)) {
  75.     // Handle timestamp setting error
  76.     sd.errorHalt("Failed to set write timestamp");
  77.   }
  78.   if (!file.timestamp(T_ACCESS, 2022, 9, 1, 12, 0, 0)) {
  79.     // Handle timestamp setting error
  80.     sd.errorHalt("Failed to set access timestamp");
  81.   }
  82.   file.close();
  83.  
  84.   Serial.println("Initialization complete.");
  85. }
  86.  
  87. void loop() {
  88.   // Main code here
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement