EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #112 background imageLoading...
Page #112 background image
SunFounder ESP32 Starter Kit
(continued from previous page)
IRrecv irrecv(IR_RECEIVE_PIN);
// Create a decode_results object
decode_results results;
2. In the setup() function, serial communication is started at a baud rate of 115200, and the IR receiver is enabled
using irrecv.enableIRIn().
void setup() {
// Start serial communication
Serial.begin(115200);
// Start the IR receiver
irrecv.enableIRIn();
}
3. When you press a key on the remote control, the serial monitor will print the key name if it is received by the IR
receiver.
void loop() {
// If an IR signal is received
if (irrecv.decode(&results)) {
String key = decodeKeyValue(results.value);
if (key != "ERROR") {
// Print the value of the signal to the serial monitor
Serial.println(key);
}
irrecv.resume(); // Continue to receive the next signal
}
}
• Firstly, check if an IR signal is received using the irrecv.decode() function.
• If a signal is received, then call the decodeKeyValue() function to decode the value of the
signal.
• If the signal is successfully decoded, the decoded value is printed to the serial monitor using
Serial.println().
• Finally, irrecv.resume() is called to continue to receive the next signal.
4. The decodeKeyValue() function takes the decoded value of the IR signal as an argument and returns a string
representing the key pressed on the remote control.
String decodeKeyValue(long result)
{
switch(result){
case 0xFF6897:
return "0";
case 0xFF30CF:
return "1";
case 0xFF18E7:
return "2";
case 0xFF7A85:
...
106 Chapter 1. For Arduino User

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish