#include <SD.h>
// подключение контактов
const int readPin = A0;
const int CS_PIN = 10;
const float mcuVoltage = 5; // напряжение питания микроконтроллера, в Вольтах
const int adcMax = 1023; // максимальное значение АЦП
const float r2 = 240; // сопротивление резистора R2, кОм
const int MEAS_DELAY = 100; // частота измерений, в миллисекундах
//***********************************************************************************************
// системные настройки
File root;
void setup() {
Serial.begin(115200);
Serial.print("Initializing SD card... ");
if (!SD.begin(CS_PIN)) {
Serial.println("Card initialization failed!");
while (true) delay(1);
}
Serial.println("initialization done.");
for (int n = 0; n < 20; n++) {
long sum = 0;
for (int i = 0; i < 10; i++) //Average the 10 measurements to remove the glitch
{
sum += analogRead(readPin);
delay(5);
}
float gsr_average = sum / 10.; // gsr average
float voltage = gsr_average * (mcuVoltage / adcMax); // где mcuVoltage это напряжение питания микроконтроллера, а adcMax это максимальное значение АЦП
float r1 = r2 * (mcuVoltage / voltage) - r2; // kOhm
File textFile = SD.open("log.txt", FILE_WRITE);
if (textFile) {
textFile.println(String(r1));
textFile.close();
}
delay(MEAS_DELAY);
}
// Example of reading file from the card:
File textFile = SD.open("log.txt");
if (textFile) {
Serial.println("wokwi.txt: ");
while (textFile.available()) {
Serial.write(textFile.read());
}
textFile.close();
} else {
Serial.println("error opening wokwi.txt!");
}
}
void loop() {
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}