How to output a variable directly to GPIO pins ... i.e. in parallel.
This can be done using the ESP32's registers.
// sending a variable to GPIO pins Bitwise register style
// create a parallel GPIO bus using GPIO 12,13,14,15 i.e. must be consecutive pins
#define PARALLEL_0 12
int RGBled=000; // demo RGB connected to Gpio pin 12,13,14,15
void setup() {
// set the digital pin as outputs:
pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(14, OUTPUT); pinMode(15, OUTPUT);
}
void loop() {
parallel_write(RGBled); //output gpio 12,13,14,15(extra) as a bitwise operation
RGBled++;
delay(1000);
}
void parallel_write(uint8_t value) {
uint32_t output = (REG_READ(GPIO_OUT_REG) & ~(0xFF << PARALLEL_0)) | (((uint32_t)value) << PARALLEL_0);
REG_WRITE(GPIO_OUT_REG, output);
}
|
Using this method simplifies/illiminates multiple writes to each GPIO in turn.