0

Switch and LED example for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32)

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 (mrm-esp32).

Task

We will use GPIO for digital output and input. Input pin will sense if voltage is 0 V (logical 0) or 3.3 V (logical 1).

Connection

Starting from the basic connection, let's add a ML-R LEDs Switches (mrm-leds). The picture shows 5 V power supply to mrm-esp32, although it is not necessary for this example.

Program

The program is quite simple :

void setup() {
  pinMode(25, OUTPUT);
  pinMode(33, INPUT);
}

void loop() {
  digitalWrite(25, digitalRead(33));
}
We set GPIO 25 to be output (red LED) and 25 to be input (switch). Switch connects GPIO 25 to 3.3 V when pressed and to 0 V when not. Therefore, the LED will be off till we press the button.

Limitations

Some pins are not available for input or output. Check this list.

Alternative connections

Lijevo je primjer spajanja na Teensy 3.2. Pločice poredajte jednu do druge na podlogu. Spojite 2 zelene linije Dupont kablovima na ML-R Teen, board for Teensy 3.1/3.2 (mrm-tee) pločicu. U našem primjeru se koristi 1 LED i 1 tipkalo. S pločice MRMS Power Supply 3x B (mrm-ps3xb) (ili druge), dovedite 3.3 V (narančasta linija) do ML-R LEDs Switches (mrm-leds) pločice i 5 V do ML-R Teen, board for Teensy 3.1/3.2 (mrm-tee) pločice.

Isključite prekidač regulatora. Spojite bateriju na regulator. Provjerite još jednom sve spojeve. Uključite prekidač i povežite Teen USB kablom s računalom.

U Arduinu možete čitati prekidač naredbom digitalRead(13). LEDom upravljate naredbom digitalWrite(15, HIGH) (ili LOW).

Kako u kodu efikasno koristiti prekidače, naučite proučivši klasu za naredbe, dio s tipkalima.

Želite li periodički uključivati LED, proučite Arduino timer interrupte.

LEDovi nisu 5 V kompatibilni. Dovođenjem napona većeg od 3.3 V sve će se jače grijati i skraćivat će im se životni vijek, ako ne pregore odmah.