Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SD.h"
- const int chipSelect = 4;
- const int buffer_length = 256;
- byte buffer[buffer_length];
- File dataFile;
- unsigned long data_length;
- void setup()
- {
- Serial.begin(115200);
- Serial.flush();
- // make sure that the default chip select pin is set to
- // output, even if you don't use it:
- pinMode(10, OUTPUT);
- // see if the card is present and can be initialized:
- if (!SD.begin(chipSelect)) {
- // don't do anything more:
- return;
- }
- dataFile = SD.open("datalog.txt", FILE_WRITE);
- }
- void loop()
- {
- if (Serial.available() > 0) {
- buffer[data_length] = Serial.read();
- ++data_length;
- if(data_length > buffer_length - 1) {
- dataFile.write(buffer, data_length);
- data_length = 0;
- }
- } else { if (data_length > 0) {
- dataFile.write(buffer, data_length);
- data_length = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement