/*
https://stackoverflow.com/questions/52348930/esp32-direct-port-manipulation/52976497#52976497
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "driver/gpio.h"
#define PIN13 13
uint32_t input = 0;
void setup() {
Serial.begin(115200);
delay(10);
Serial.print("Connecting to ");
REG_WRITE(GPIO_ENABLE_REG, BIT2 + BIT3 + BIT4); //BIT2=LED ONBOAR / BIT3 -> PIN D2 / BIT4 - PIN D4
}
void loop() {
REG_WRITE(GPIO_OUT_W1TS_REG, BIT2 + BIT3 );
vTaskDelay(500/portTICK_PERIOD_MS);
REG_WRITE(GPIO_OUT_W1TC_REG, BIT2 + BIT3);
vTaskDelay(500/portTICK_PERIOD_MS);
//--le a entrada
input = REG_READ(GPIO_IN_REG);
input &= (1 << PIN13);
Serial.print(input);
Serial.print(" ");
if (input == 0)
{
REG_WRITE(GPIO_OUT_W1TS_REG, BIT4); // PIN D4
} else
{
REG_WRITE(GPIO_OUT_W1TC_REG, BIT4);//
}
}
/*
// MESMO CÓDIGO EM CPP
extern "C" void app_main()
{
uint32_t input = 0;
uint32_t bit_lido = 0;
REG_WRITE(GPIO_ENABLE_REG, BIT2 + BIT3 + BIT4); //BIT2=LED ONBOAR / BIT3 -> PIN D2 / BIT4 - PIN D4
while (1)
{
REG_WRITE(GPIO_OUT_W1TS_REG, BIT2 + BIT3 );
vTaskDelay(500/portTICK_PERIOD_MS);
REG_WRITE(GPIO_OUT_W1TC_REG, BIT2 + BIT3);
vTaskDelay(500/portTICK_PERIOD_MS);
//--le a entrada
input = REG_READ(GPIO_IN_REG);
input &= (1 << PIN13);
if (input == 0)
{
REG_WRITE(GPIO_OUT_W1TS_REG, BIT4); // PIN D4
} else
{
REG_WRITE(GPIO_OUT_W1TC_REG, BIT4);//
}
}
}
*/