Skip to content

Instantly share code, notes, and snippets.

@hpwit
Created May 19, 2023 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpwit/80798107bde102c27102dd6959818350 to your computer and use it in GitHub Desktop.
Save hpwit/80798107bde102c27102dd6959818350 to your computer and use it in GitHub Desktop.
read file
#include "FS.h"
#include "SD.h"
#include "SPI.h"
File myFile;
bool FILE_IS_OPEN = false;
int nb_bytes=0;
void setup() {
Serial.begin(1000000);
SD.begin(5, SPI, 80000000);
pinMode(15, INPUT_PULLUP);
}
void loop() {
if (digitalRead(15) == LOW) {
Serial.println("we start...");
while (Serial.available()) Serial.read();
delay(5000);
Serial.println("ready ...");
}
while (digitalRead(15) == LOW) {
if (!FILE_IS_OPEN) {
Serial.println("we open the files...");
myFile = SD.open("/video1.txt", FILE_WRITE);
FILE_IS_OPEN = true;
}
while (Serial.available() && myFile) {
nb_bytes++;
byte b = Serial.read();
myFile.write(b);
Serial.write(b);
}
}
if (FILE_IS_OPEN) {
Serial.println("we close the files...");
myFile.close();
Serial.printf("we've cloed with %d bytes\n",nb_bytes);
FILE_IS_OPEN = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment