Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Test
- - Source Code compiled for: Arduino Nano
- - Source Code created on: 2023-11-20 13:47:51
- - Source Code generated by: Cippa
- ********* Pleasedontcode.com **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <SPI.h>
- #include <SdFat.h>
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Write timestamp to SD card */
- /****** FUNCTION PROTOTYPES *****/
- void setup();
- void loop();
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t SD_CARD_MODULE_SPI_PIN_MOSI = 11;
- const uint8_t SD_CARD_MODULE_SPI_PIN_MISO = 12;
- const uint8_t SD_CARD_MODULE_SPI_PIN_SCLK = 13;
- const uint8_t SD_CARD_MODULE_SPI_PIN_CS = 10;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- SdFat sd;
- SdFile file;
- void setup() {
- // Start the SPI library
- SPI.begin();
- // Initialize the SD card
- if (!sd.begin(SD_CARD_MODULE_SPI_PIN_CS, SPI_HALF_SPEED)) {
- // Handle SD card initialization error
- Serial.println("SD card initialization failed!");
- while (true) {
- // Wait indefinitely
- delay(1000);
- }
- }
- // Remove existing files if any
- sd.remove("default.txt");
- sd.remove("stamp.txt");
- // Create and write to file "default.txt"
- if (!file.open("default.txt", O_WRONLY | O_CREAT)) {
- // Handle file opening error
- sd.errorHalt("Failed to open default.txt");
- }
- file.close();
- // Create file "stamp.txt" and set timestamps
- if (!file.open("stamp.txt", O_WRONLY | O_CREAT)) {
- // Handle file opening error
- sd.errorHalt("Failed to open stamp.txt");
- }
- if (!file.timestamp(T_CREATE, 2022, 9, 1, 12, 0, 0)) {
- // Handle timestamp setting error
- sd.errorHalt("Failed to set create timestamp");
- }
- if (!file.timestamp(T_WRITE, 2022, 9, 1, 12, 0, 0)) {
- // Handle timestamp setting error
- sd.errorHalt("Failed to set write timestamp");
- }
- if (!file.timestamp(T_ACCESS, 2022, 9, 1, 12, 0, 0)) {
- // Handle timestamp setting error
- sd.errorHalt("Failed to set access timestamp");
- }
- file.close();
- Serial.println("Initialization complete.");
- }
- void loop() {
- // Main code here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement