EasyManua.ls Logo

Keyestudio ESP32 - Page 164

Keyestudio ESP32
344 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
ESP32 Starter Kit
(continued from previous page)
int distance = 0; //Define a variable to receive the distance
int EchoPin = 14; //Connect Echo pin to IO14
int TrigPin = 13; //Connect Trig pin to IO13
int ligth_sensor = 33; //Define the photoresistor pin
int sound_sensor = 32; //efine the sound sensor pin
int pot_sensor = 25; //Define the potentiometer pin
void setup() {
//LCD 1602
lcd.init(); // initialize the lcd
lcd.backlight(); //Turn on the LCD backlight
lcd.setCursor(3, 0);
lcd.print("keyestudio"); //LCD displays "keyestudio"
//IR receiver
irrecv.enableIRIn(); // start receiving signals
//Ultrasonic
pinMode(TrigPin, OUTPUT); //Set Trig pin to output
pinMode(EchoPin, INPUT); //Set Echo pin to input
}
void loop() {
if (irrecv.decode(&results)) {
if (results.value != 0) { //Prevent the button from being pressed repeatedly
ir_rec = results.value; //The signal is assigned to the variable ir_rec
show_clear();
}
irrecv.resume(); //Release the IRremote and receive the next value.
}
switch (ir_rec) {
case 0xFF02FD: show_clear(); break;
case 0xFF6897: show_temperature(); break;
case 0xFF9867: show_humidity(); break;
case 0xFFB04F: show_distance(); break;
case 0xFF30CF: show_luminance(); break;
case 0xFF18E7: show_sound(); break;
case 0xFF7A85: show_pot(); break;
}
delay(300);
}
void show_clear() { //Clear display
lcd.setCursor(0, 1);
lcd.print(" ");
}
void show_temperature() { //Display temperature
if (xht.receive(dat)) { //Check correct return to true
lcd.setCursor(0, 1);
lcd.print("Temperature:");
lcd.setCursor(13, 1);
lcd.print(dat[2]);
(continues on next page)
160 Chapter 8. Arduino Tutorial

Table of Contents