#include <SD.h>
File sdcard_file;
int CS_pin = 10; // Pin 10 on Arduino
void setup(){
// put your setup code here, to run once:
pinMode(A0, INPUT);
pinMode(CS_pin, OUTPUT);
Serial.begin(9600);
// SD Card Initialization
if (SD.begin()){
Serial.println("SD card is ready to use.");
}
else {
Serial.println("SD card initialization failed");
return;
}
}
void loop(){
// put your main code here, to run repeatedly
sdcard_file = SD.open("data.txt", FILE_WRITE);
if (sdcard_file) {
long PotValue = analogRead(A0);
long PotVPercent = ((PotValue*100)/1023);
//Serial.println(PotValue);
Serial.print(PotVPercent);
Serial.println(" %");
sdcard_file.print(PotVPercent);
sdcard_file.println(" %");
sdcard_file.close();
}
// if the file didn't open,
else {
Serial.println("error opening test.txt");
}
delay(1000);
}