const float BETA = 3950; // should match the Beta Coefficient of the thermistor
#define BUTTON_PIN 4
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int val; // variable to read the value from the analog pin
void setup() {
Serial.begin(9600); // инициализация порта
pinMode(BUTTON_PIN, INPUT_PULLUP);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
//int lastState = HIGH;
void loop() {
int analogValue = analogRead(A1); // ввод значения NTS в переменную
int celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15; // пересчет значения NTC в градусы Цельсия
Serial.print("Температура: "); // вывод в порт слова "Температура"
Serial.print(celsius); // вывод в порт температуры
Serial.println(" ℃"); // вывод в порт обозначения градуса
val = map(celsius, -24, 80, 0, 90); // функция пересчета диапазона с -24 - 80 градусов на угол 0 - 90
myservo.write(val); // sets the servo position according to the scaled value
//int battonPress;
//battonPress = 0;
int value = digitalRead((BUTTON_PIN));
if (value != HIGH) {
Serial.println("pressed");
//battonPress = battonPress + 1;
myservo.write(0);
delay(3000);
}
// for (int i = 0; i < 2; i++) // цикл от 0 до 1
//{
//}
//}
delay(15); // waits for the servo to get there
}