// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal.h>
// تحديد المدخل الرقمي المستخدم للزر
const int BUTTON_PIN = 2;
int tempSensorPin = A0;
float tempCelsius;
bool displayText = true;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
lcd.begin(16, 1);
pinMode(BUTTON_PIN, INPUT_PULLUP); // تحديد المدخل الرقمي المستخدم للزر كمدخل رقمي
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { // عندما يتم الضغط على الزر
lcd.clear();
displayText = false;
tempCelsius = getTemperature(); // قراءة قيمة درجة الحرارة من الحساس
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(tempCelsius);
lcd.print(" C");
delay(500); // انتظر حتى يتم رفع الزر
while (digitalRead(BUTTON_PIN) == LOW) {}
// انتظر حتى يتم رفع الزر بشكل كامل
} else {
displayText = true;
lcd.setCursor(0, 0);
lcd.print("My name is Othman I study EPU");
delay(500);
lcd.scrollDisplayLeft();
}
}
float getTemperature() {
int reading = analogRead(tempSensorPin);
float voltage = reading * 5.0 / 1023;
float temperature = (voltage - 0.5) * 100;
return temperature;
}