Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SD.h>
- void setup(){
- Serial.begin(9600);
- pinMode(10, OUTPUT);
- SD.begin(4);
- SD.remove("myFile.bin");
- File myFile = SD.open("myFile.bin", FILE_WRITE);
- if(! myFile){
- Serial.println("Failed to open file for writing");
- return;
- }
- Serial.println("Starting Sampling");
- for(short a = 0; a < 256; a++){
- short samp = analogRead(0);
- myFile.write((byte)(samp & 0xff));
- myFile.write((byte)((samp >> 8) & 0xff));
- delay(10);
- }
- Serial.println("End of Sampling");
- myFile.close();
- myFile = SD.open("myFile.bin", FILE_READ);
- if(! myFile){
- Serial.println("Could not open file for reading");
- return;
- }
- for(short a = 0; a < 256; a++){
- short samp = (myFile.read() & 0xff) | ((myFile.read() << 8) & 0xff00);
- Serial.print("Read back ");
- Serial.println(samp);
- }
- myFile.close();
- }
- void loop(){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement