#include <SD.h>
#define CS_PIN 2
File root;
int led=15;
int temp=A0;
int slider=A1;
const float BETA = 3950;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(temp, INPUT);
pinMode(slider, INPUT);
Serial.print("Initializing SD card... ");
if (!SD.begin(CS_PIN)) {
Serial.println("Card initialization failed!");
while (true);
}
Serial.println("initialization done.");
// Example of reading file from the card:
File textFile = SD.open("wokwi.txt", FILE_WRITE);
// Check if the file is available
if (textFile) {
// Write some data to the file
textFile.println("Hello, Wokwi!");
textFile.println("This is a test.");
// Close the file
textFile.close();
Serial.println("Data written to wokwi.txt.");
} else {
Serial.println("Error opening wokwi.txt for writing!");
}
}
void loop() {
int pot_val=analogRead(slider);
int temp_value=analogRead(temp);
float celsius = 1 / (log(1 / (1023. / temp_value - 1)) / BETA + 1.0 / 298.15) - 273.15;
if(celsius>50 || pot_val>900 || pot_val<300)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led,LOW);
}
delay(10); // this speeds up the simulation
}