This is my first time I am asking a question on this forum. Thanks to everyone who is contributing. Learned a lot here.
At the start of my code I want to read a 10 Position Rotary BCD Coded Switch (I only need 8 positions -3 bits-)
I am using GPIO 12-13-14 of the ESP. On my DOIT board the pinout is 6 =GPIO 13, 7 = GPIO 12, 8 = GPIO 14. I will correct that with the wiring. A simple way is to read the input register of the ESP32. Then shift right (12 times -from pin 12-) to get the dec. value of the rotary switch.
Before I can use (read) the input register I have to write/clear the GPIO_ENABLE_W1T(Clear) with 3 bits (0x07) shifted for the right pin positions.
Examples of ESP32 direct port manipulation are hard to find. With the knowledge I've collected so far I've written this code.
Am I on the right track?
Thanks Henk
- void setup() {
- pinMode(12, INPUT_PULLDOWN);
- pinMode(13, INPUT_PULLDOWN);
- pinMode(14, INPUT_PULLDOWN);
- REG_WRITE(GPIO_ENABLE_W1TC_REG, 0x07 << 12); //Enable pin 12-13-14 (0x07 = bin 00000111 only need 3 bits)
- uint32_t input = REG_READ(GPIO_IN_REG); //Read the Input 32bit register
- input = input >> 12; // Shift the found value 12 times to the right to calc the value
- Serial.print (input); //Check the found decimal nr.
- }
- void loop() { }