// библиотека для работы с протоколом 1-Wire
#include <OneWire.h>
// библиотека для работы с датчиком DS18B20
#include <DallasTemperature.h>
#include <Servo.h>
#include <Wire.h> // библиотека для управления устройствами по I2C
#include <LiquidCrystal_I2C.h> // подключаем библиотеку для QAPASS 1602
LiquidCrystal_I2C LCD(0x27,16,2); // присваиваем имя LCD для дисплея
Servo arm; // Create a "Servo" object called "arm"
float pos = 0.0; // Variable where the arm's position will be stored (in degrees)
float step = 10.0; // Variable used for the arm's position step
// сигнальный провод датчика
#define ONE_WIRE_BUS 9
uint32_t myTimer1, myTimer2;
float temp_R;
float temperature; // переменная для хранения температуры
float chek;
// создаём объект для работы с библиотекой OneWire
OneWire oneWire(ONE_WIRE_BUS);
// создадим объект для работы с библиотекой DallasTemperature
DallasTemperature sensor(&oneWire);
void setup() {
temp_R = 100;
chek = temp_R - temperature;
// инициализируем работу Serial-порта
Serial.begin(9600);
// начинаем работу с датчиком
sensor.begin();
// устанавливаем разрешение датчика от 9 до 12 бит
sensor.setResolution(12);
pinMode(A1, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
pinMode(A2, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
arm.attach(10); // Attache the arm to the pin 10
arm.write(pos); // Initialize the arm's position to 0 (leftmost)
}
void loop() {
if (abs(chek) > 5) {
if (millis() - myTimer2 >= 1000) { // таймер на 5000 мс
myTimer2 = millis(); // сброс таймера
if (chek > 5) // Check for the yellow button input
{
if (pos > 0) // Check that the position won't go lower than 0°
{
arm.write(pos); // Set the arm's position to "pos" value
pos -= step; // Decrement "pos" of "step" value
delay(150); // Wait 5ms for the arm to reach the position
}
}
if (chek < 5) // Check for the blue button input
{
if (pos < 180) // Check that the position won't go higher than 180°
{
arm.write(pos); // Set the arm's position to "pos" value
pos += step; // Increment "pos" of "step" value
delay(150); // Wait 5ms for the arm to reach the position
}
}
}
}
// отправляем запрос на измерение температуры
sensor.requestTemperatures();
// считываем данные из регистра датчика
temperature = sensor.getTempCByIndex(0);
if (millis() - myTimer1 >= 1000) { // таймер на 5000 мс
myTimer1 = millis(); // сброс таймера
// выводим температуру в Serial-порт
Serial.print("Temp C: ");
Serial.println(temperature);
Serial.print("temp_R: ");
Serial.println(temp_R);
chek = temp_R - temperature;
Serial.print("chek: ");
Serial.println(abs(chek));
Serial.print("pos-: ");
Serial.println(pos);
}
if (!digitalRead(A1)) // Check for the yellow button input
{temp_R=temp_R-1;
delay(100);
}
if (!digitalRead(A2)) // Check for the blue button input
{temp_R=temp_R+1;
delay(100);
}
LCD.init(); // инициализация LCD дисплея
LCD.backlight(); // включение подсветки дисплея
LCD.setCursor(0, 0); // ставим курсор на 1 символ первой строки
LCD.print("T="); // печатаем сообщение на первой строке
LCD.setCursor(3, 0);
LCD.print(temperature);
LCD.setCursor(0, 1); // ставим курсор на 1 символ второй строки
LCD.print("t~="); // печатаем сообщение на второй строке
LCD.setCursor(3, 1);
LCD.print(temp_R);
}