ファイルを書き込んで読み込むサンプルプログラムです。
#include <Adafruit_Arcada.h> #if !defined(USE_TINYUSB) #error("Please select TinyUSB for the USB stack!") #endif Adafruit_Arcada arcada; void setup() { Serial.begin(9600); arcada.arcadaBegin(); arcada.displayBegin(); arcada.setBacklight(255); arcada.display->fillRect(0, 0, 160, 128, ARCADA_BLACK); arcada.display->setTextColor(ARCADA_WHITE); arcada.display->setCursor(0, 0); arcada.display->print("FileSample"); // Initialize filesystem arcada.filesysBeginMSD(); // Check FAT system if(arcada.filesysBegin() == false) { arcada.haltBox("Not found filesystem"); } // Write test char* filename = "/FileSample/sample.txt"; char* sampleText = "sample text"; if(arcada.exists(filename) == true) { arcada.remove(filename); } File file = arcada.open(filename, O_WRITE | O_CREAT | O_TRUNC); file.write(sampleText, strlen(sampleText)); file.close(); arcada.display->setCursor(0, 20); if(arcada.exists(filename) == true) { arcada.display->print("Successful write file"); } else { arcada.display->print("Can not write file"); } // Read test arcada.display->setCursor(0, 40); if(arcada.exists(filename) == true) { char buffer[1024]; File file = arcada.open(filename, O_READ); int filesize = file.fileSize(); file.read(buffer, filesize); file.close(); buffer[filesize] = '\0'; arcada.display->print("Successful read file"); arcada.display->setCursor(0, 50); arcada.display->print(buffer); } else { arcada.display->print("File not found"); } } void loop() { }
押したボタンが表示されます。