Guest User

Untitled

a guest
Sep 30th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include "Inkplate.h" // Include Inkplate library
  2. Inkplate display(INKPLATE_3BIT); // Create an Inkplate object in 3-bit mode
  3.  
  4. // No need to declare SdFile or SdFat objects separately; we'll use the one provided by Inkplate
  5. // SdFile file; // Not needed in this context
  6.  
  7. void setup()
  8. {
  9. display.begin(); // Initialize Inkplate library
  10. display.clearDisplay(); // Clear display buffer
  11. display.setTextColor(BLACK); // Set text color to black
  12. display.setTextSize(3); // Set font size to 3
  13.  
  14. // Initialize the SD card
  15. if (!display.sdCardInit()) {
  16. display.println("SD Card initialization failed!");
  17. display.display();
  18. return;
  19. }
  20.  
  21. display.println("SD Card OK! Reading folder...");
  22. display.display();
  23.  
  24. // Example variables (replace these with your actual variables)
  25. const char* nr = "123"; // Replace with: const char* nr = docP["nr"];
  26. const char* v = "voice1"; // Replace with: const char* v = voice["voice"];
  27.  
  28. // Construct the path using the variables
  29. char path[256];
  30. snprintf(path, sizeof(path), "/%s/%s", nr, v);
  31.  
  32. // Check if the directory exists
  33. if (sd.exists(path)) {
  34. display.println("Directory exists.");
  35. display.display();
  36. } else {
  37. display.println("Directory does not exist.");
  38. display.display();
  39.  
  40. // Attempt to create the directory (including parent directories)
  41. if (sd.mkdir(path, true)) {
  42. display.println("Directories created successfully.");
  43. display.display();
  44. } else {
  45. display.println("Failed to create directories.");
  46. display.display();
  47. }
  48. }
  49.  
  50. // Turn off the SD card to save power (optional)
  51. display.sdCardSleep();
  52. }
  53.  
  54. void loop()
  55. {
  56. // Nothing to do here
  57. }
Advertisement
Add Comment
Please, Sign In to add comment