Files
2021-09-25 18:18:46 +08:00

54 lines
2.7 KiB
Arduino
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with STAMP-PICO sample source code
* 配套 STAMP-PICO 示例源代码
* Visit the website for more informationhttps://docs.m5stack.com/en/core/stamp_pico
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/stamp_pico
*
* describeSPIFFS Add(Write is to clean up the contents of the file and write it again.)
* 向SPIFFS中添加信息(write是将文件内容完全清除重新写)
* date2021/9/25
*******************************************************************************
*/
#include <Arduino.h>
#include <SPIFFS.h>
String file_name = "/M5Stack/notes.txt"; //Sets the location and name of the file to be operated on. 设置被操作的文件位置和名称
bool SPIFFS_FORMAT = true; //Whether to initialize the SPIFFS. 是否初始化SPIFFS
//You don't need to format the flash file system every time you use it.
//无需每次使用闪存都进行格式化
void setup() {
Serial.begin(115200);
if(SPIFFS_FORMAT){
Serial.println("\nSPIFFS format start..."); //Screen prints format String. 屏幕打印格式化字符串
SPIFFS.format(); // Formatting SPIFFS. 格式化SPIFFS
Serial.println("SPIFFS format finish");
}
if(SPIFFS.begin()){ // Start SPIFFS, return 1 on success. 启动闪存文件系统,若成功返回1
Serial.println("\nSPIFFS Started.");
} else {
Serial.println("SPIFFS Failed to Start.");
}
if (SPIFFS.exists(file_name)){ //Check whether the file_name file exists in the flash memory. 确认闪存中是否有file_name文件
Serial.println("FOUND.");
Serial.println(file_name);
File dataFile = SPIFFS.open(file_name, "a"); // Create a File object dafaFile to add information to file_name in the SPIFFS. 建立File对象dafaFile用于向SPIFFS中的file_name添加信息
dataFile.println("This is Appended Info."); // Adds string information to dataFile. 向dataFile添加字符串信息
dataFile.close(); // Close the file when writing is complete. 完成写入后关闭文件
Serial.println("Finished Appending data to SPIFFS");
}else {
Serial.println("NOT FOUND.");
Serial.print(file_name);
Serial.println("is creating.");
File dataFile = SPIFFS.open(file_name, "w"); // Create aFile object dafaFile to write information to file_name in the SPIFFS. 建立File对象dafaFile用于向SPIFFS中的file_name写入信息
dataFile.close(); // Close the file when writing is complete. 完成写入后关闭文件
Serial.println("Please disable format and Reupload");
}
}
void loop() {
}