Files
earlephilhower_arduino-pico/libraries/LittleFS/examples/FSUpload/FSUpload.ino
T
Earle F. Philhower, III 4e50fe866a Add LittleFS, SD, and SDFS Filesystems and File:: interface (#49)
Pull in the ESP8266 File/Dir/etc. filesystem and port LittleFS
and SD/SDFS to the RP2040.

See https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html
for more information
2021-04-02 17:46:12 -07:00

57 lines
1.3 KiB
Arduino

// Released to the public domain
//
// This sketch will read an uploaded file and increment a counter file
// each time the sketch is booted.
// Be sure to install the Pico LittleFS Data Upload extension for the
// Arduino IDE from:
// https://github.com/earlephilhower/arduino-pico-littlefs-plugin/
// The latest release is available from:
// https://github.com/earlephilhower/arduino-pico-littlefs-plugin/releases
// Before running:
// 1) Select Tools->Flash Size->(some size with a FS/filesystem)
// 2) Use the Tools->Pico Sketch Data Upload tool to transfer the contents of
// the sketch data directory to the Pico
#include <LittleFS.h>
void setup() {
Serial.begin(115200);
delay(5000);
LittleFS.begin();
char buff[32];
int cnt = 1;
File f = LittleFS.open("counts.txt", "r");
if (f) {
bzero(buff, 32);
if (f.read((uint8_t *)buff, 31)) {
sscanf(buff, "%d", &cnt);
Serial.printf("I have been run %d times\n", cnt);
}
f.close();
}
cnt++;
sprintf(buff, "%d\n", cnt);
f = LittleFS.open("counts.txt", "w");
if (f) {
f.write(buff, strlen(buff));
f.close();
}
Serial.println("---------------");
File i = LittleFS.open("file1.txt", "r");
if (i) {
while (i.available()) {
Serial.write(i.read());
}
Serial.println("---------------");
i.close();
}
}
void loop() {
}