Advertisement
uas_arduino

Arduino - SD Speed Test

Apr 17th, 2015
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <SD.h>
  2. #include <SPI.h>
  3.  
  4. void setup(){
  5.   SPI.setClockDivider(SPI_CLOCK_DIV4);
  6.   Serial.begin(9600);
  7.   pinMode(10, OUTPUT);
  8.   SD.begin(4);
  9.  
  10.   SD.remove("myFile.bin");
  11.  
  12.   File myFile = SD.open("myFile.bin", FILE_WRITE);
  13.   if(! myFile){
  14.     Serial.println("Failed to open file for writing");
  15.     return;
  16.   }
  17.   byte * data = new byte[128];
  18.   for(int a = 0; a < 128; a++){
  19.     data[a] = 0x00;
  20.   }
  21.  
  22.   long start = millis();
  23.   for(unsigned long a = 0; a < 1024L * 8L * 1L; a++){
  24.     myFile.write(data, 128);
  25.   }
  26.   long ending = millis();
  27.   myFile.close();
  28.  
  29.   Serial.print("Took ");
  30.   Serial.print((ending - start) / 1000);
  31.   Serial.println(" seconds to write the data");
  32.  
  33. }
  34.  
  35. void loop(){
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement