Skip to content

Commit db1e57f

Browse files
committed
simple.ino -> SimpleStorageWriteRead.ino
1 parent 2e5de5b commit db1e57f

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

examples/simple/simple.ino renamed to examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
/*
2-
This examples demonstrates the usage of the "Arduino_UnifiedStorage" library,
3-
which allows the program to easily switch between different storage mediums.
2+
SimpleStorageWriteRead
43
5-
By uncommenting the appropriate lines, you can choose to use either an SD card,
6-
a USB storage device, or internal storage as the storage medium.
4+
Demonstrates basic usage of the "Arduino_UnifiedStorage" library to write and read data to storage.
5+
Supports SD card, USB storage, and internal storage (default, uncomment to choose).
76
8-
The example code is set up to use an SD card by default.
7+
n the setup function, the code initializes serial communication, mounts the storage medium,
8+
creates a root directory with three subdirectories, and writes data to three files in each subdirectory.
99
10-
In the setup function, the code initializes the serial communication and checks if the storage medium is successfully mounted.
11-
It then creates a root directory and three subdirectories within it.
12-
After creating the subdirectories, the code creates three files inside each subdirectory and writes data to them.
10+
Following this, the code showcases reading data from files by using "seek" and "available" methods,
11+
switching file modes to read, resetting file pointers to the start,
12+
and printing the read data to the serial monitor using a while loop.
13+
14+
Created 28th July 2023
15+
By Cristian Dragomir
16+
17+
Modified 24th August 2023
18+
By Ali Jahangiri
19+
20+
https://github.com/arduino-libraries/Arduino_UnifiedStorage/blob/main/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino
1321
14-
Next, the code demonstrates how to read data from the files using the "seek" and "available" methods.
15-
It changes the mode of the files to read mode, moves the file pointers to the beginning, and reads the data from each file using a while loop.
16-
The read data is printed to the serial monitor.
1722
*/
1823

1924
#include "Arduino_UnifiedStorage.h"
2025

21-
SDStorage unifiedStorage = SDStorage(); // or
22-
//USBStorage unifiedStorage = USBStorage() // or
23-
//InternalStorage unifiedStorage = InternalStorage();
26+
// Uncomment one of the three lines below to select between SD card, USB or internal storage
27+
//SDStorage unifiedStorage = SDStorage(); // Create an instance for interacting with SD card storage
28+
//USBStorage unifiedStorage = USBStorage() // Create an instance for interacting with USB storage
29+
InternalStorage unifiedStorage = InternalStorage(); // Create an instance for interacting with internal Flash storage (default)
2430

2531
void setup() {
2632
Serial.begin(115200);
2733
while (!Serial);
2834

2935
if(!unifiedStorage.begin()==0){
30-
Serial.println("error mounting SD Card");
36+
Serial.println("Error mounting storage device.");
3137
}
32-
// Create a root directory
3338

39+
// Create a root directory in storage device
3440
Folder root = unifiedStorage.getRootFolder();
3541

3642
// Create subdirectories inside the root directory
3743
Folder subdir1 = root.createSubfolder("subdir1");
3844
Folder subdir2 = root.createSubfolder("subdir2");
3945
Folder subdir3 = root.createSubfolder("subdir3");
4046

41-
// Create files inside the subdirectories
47+
// Create .txt files inside the subdirectories
4248
UFile file1 = subdir1.createFile("file1.txt", FileMode::WRITE);
4349
UFile file2 = subdir2.createFile("file2.txt", FileMode::WRITE);
4450
UFile file3 = subdir3.createFile("file3.txt", FileMode::WRITE);

0 commit comments

Comments
 (0)