/* SD card read/write SD * SD SPI : ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 10 2010 David A. Mellis 2 2010 Tom Igoe 2011 Gleb Devyatkin - . */ #include <SD.h> File myFile; void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin // (10 on most Arduino boards, 53 on the Mega) must be left as an output // or the SD library functions will not work. pinMode(10, OUTPUT); if (!SD.begin(10)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); // . , , // , . myFile = SD.open("test.txt", FILE_WRITE); // , : if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); // : myFile.close(); Serial.println("done."); } else { // , : Serial.println("error opening test.txt"); } // , : myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:"); // , : while (myFile.available()) { Serial.write(myFile.read()); } // : myFile.close(); } else { // , : Serial.println("error opening test.txt"); } } void loop() { // , }
Source: https://habr.com/ru/post/115176/
All Articles