Hardware Reference
In-Depth Information
while(commandFile.available())
{
refresh_rate = commandFile.parseInt();
}
Serial.print("Refresh Rate = ");
Serial.print(refresh_rate);
Serial.println("ms");
}
else
{
Serial.println("Could not read command file.");
return;
}
This opens the file for reading and parses out any integers read. Because
you defined only one variable, it grabs that one and saves it to the refresh rate
variable, which would need to be defined earlier in the program. You can have
only one file open at a time, and it's good practice to close a file when you're
finished reading from, or writing to a card.
You can now integrate this into your writing program from earlier to adjust
the recording speed based on your speed.txt file, as shown in Listing 13-2.
Listing 13-2: SD Reading and Writing—sd_read_write.ino
//SD read and write
#include <SD.h>
//Set by default for the SD card library
//MOSI = pin 11
//MISO = pin 12
//SCLK = pin 13
//We always need to set the CS pin
const int CS_PIN =10;
const int POW_PIN =8;
//Default rate of 5 seconds
int refresh_rate = 5000;
void setup()
{
Serial.begin(9600);
Serial.println("Initializing Card");
//CS pin is an output
pinMode(CS_PIN, OUTPUT);
//Card will draw power from pin 8, so set it high
pinMode(POW_PIN, OUTPUT);
Search WWH ::




Custom Search