Switch example for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus
Prerequisites
If not already done so already, install Arduino software and make basic connections, as described in page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus.
Task
We will use GPIO again, as in LED example, but this time as input. It will sense if its voltage is 0 V (logical 0) or 3.3 V (logical 1). Here is again a very basic program:
void setup() {
pinMode(2, OUTPUT);
pinMode(0, INPUT);
}
void loop() {
if (digitalRead(0))
digitalWrite(2, false);
else
digitalWrite(2, true);
}
We set GPIO 2 to be output (LED) and 0 to be input (boot select switch). Switch connects GPIO 0 to 3.3 V when not pressed and to 0 V when pressed. Therefore, the LED will be off till we press the button.
Limitations
Some pins are not available for input. Check this list.