/*
* ESP32 LED Blink & Rotary Encoder with BLE Gamepad
*
* Este código controla encoders rotativos e um gamepad BLE,
* além de gerenciar um LED indicador e um sistema de inatividade.
*/
#include <AiEsp32RotaryEncoder.h>
#include <Keypad.h>
#include <Arduino.h>
#include <BleGamepad.h>
#include "driver/rtc_io.h"
// LED
#define LED 23
bool ledState = LOW;
unsigned long previousMillis = 0;
const long blinkInterval = 1000;
//=========== Keypad MATRIZ
const byte ROWS = 2; // Four rows
const byte COLS = 5; // Four columns
char keys[ROWS][COLS] = {
{ BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5 },
{ BUTTON_6, BUTTON_7, BUTTON_8, BUTTON_9, BUTTON_10}
};
byte rowPins[ROWS] = { 19, 21 }; // Connect to the row pinouts of the keypad
byte colPins[COLS] = { 15, 2, 4, 16 ,22 }; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); // KeyPad instance
void button_matrix_loop() {
turnLedOn();
// Returns true if there are ANY active keys.
if (keypad.getKeys()) {
for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
{
if (keypad.key[i].stateChanged) // Only find keys that have changed state.
{
switch (keypad.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
Serial.println(" PRESSED.");
break;
case HOLD:
Serial.println(" HOLD.");
break;
case RELEASED:
Serial.println(" RELEASED.");
break;
case IDLE:
Serial.println(" IDLE.");
}
Serial.print(keypad.key[i].kcode);
}
}
}
}
void turnLedOn() {
digitalWrite(LED, HIGH);
ledState = HIGH;
}
//=====================================================================================
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Set pin mode
pinMode(LED, OUTPUT);
}
void loop() {
button_matrix_loop();
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4