#include <ESP32Servo.h>
#include <Adafruit_LiquidCrystal.h>
#include <Keypad.h>
//Solo un CORE
BaseType_t app_cpu0 = 0;
BaseType_t app_cpu1 = 1;
//Tarea 1
int led_PIN = 4;
//Tarea 2
Servo myservo;
int pos = 0;
int led_SERVO = 2;
//Tarea 3
Adafruit_LiquidCrystal lcd(23, 22, 18, 5, 21, 19);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = {26, 25, 33, 32};
uint8_t rowPins[ROWS] = {13, 12, 14, 27};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//Tarea 4
int potpin = 34;
int val;
void setup() {
//Serial
Serial.begin(115200);
Serial.println("Hello, ESP32!");
//Tarea 1
pinMode(led_PIN, OUTPUT);
xTaskCreatePinnedToCore(blinkLED,"Tarea 1 - Parpadear LED",1024,NULL,1,NULL,app_cpu0);
//Tarea 2
myservo.attach(led_SERVO);
xTaskCreatePinnedToCore(servoMotor,"Tarea 2 - Servo Motor",1024,NULL,1,NULL,app_cpu0);
//Tarea 3
lcd.begin(16, 2);
lcd.print("Press: ");
lcd.setCursor(1,1);
xTaskCreatePinnedToCore(keyPadLCD,"Tarea 3 - KeyPad con LCD",1024,NULL,1,NULL,app_cpu1);
//Tarea 4
xTaskCreatePinnedToCore(potPrint,"Tarea 4 - Imprimir Pot",1024,NULL,1,NULL,app_cpu1);
}
// Tarea 1
void blinkLED(void *parameter){
while(1){
digitalWrite(led_PIN, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(led_PIN, LOW);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
//Tarea 2
void servoMotor(void *parameter){
while(1){
for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
}
}
// Tarea 3
void keyPadLCD(void *parameter){
while(1){
char key = keypad.getKey();
if (key != NO_KEY) {
lcd.println(key);
lcd.setCursor(1,1);
}
}
}
// Tarea 4
void potPrint(void *parameter){
while(1){
val = analogRead(potpin);
Serial.println(val);
delay(100);
}
}
//Vacío
void loop() {
delay(10);
}