Created
May 19, 2023 07:18
-
-
Save hpwit/80798107bde102c27102dd6959818350 to your computer and use it in GitHub Desktop.
read file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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