Lesson 4.2.1. IO Ports. The brightness of the fire
-
Step 1. Go to the folder Arduino-ESP32-IDE and open the app arduino.exe (Fig. 1);
Figure 1. The archive with the Arduino IDE extracted to the folderStep 2. Select New on the File menu, (Fig. 1.1);
Figure 1.1. Create a new sketchStep 3. Select Include Library, M5Stack in the Sketch menu, (Fig. 1.2);
Figure 1.2. Connection library M5Stack
Figure 2. The view from the top. Bus connector input/output
Figure 2.1. The view from the back side. Stickers with captions portsStep 4. Add to the beginning of system functions void setup() function call M5.begin();
Please note that the Arduino IDE does not support the standard functions for working with analog ports of the microcontroller ESP32.
Add to the end system functions void loop() function call M5.update (); is required for correct operation of the device with built-in buttons (Fig. 2.2);
Figure 2.2 an example of the Correct preparation of the sketchStep 5. To work with PWM port (Fig. 2, 2.1) you can use the functions from list 1.
List 1. Analog functions for ESP32
- list itemledcSetup(uint8_t c, uint8_t f, uint8_t r); Sets the number of the channel c, frequency f (Hz) and resolution r (8 bits) for PWM
- ledcAttachPin(uint8_t p, uint8_t c); Assigns the contact p to the channel c
- ledcWrite(uint8_t C, uint8_t d); Sets the value of the filling signal d on channel c
- ledcRead(uint8_t c); Gets the value of the PWM signal of the c channel
Step 7. Write a brightness controller for led (Fig. 3);
Figure 3. Code brightness controller for LEDsStep 6. Prepare the led To 5 V and a resistor of 100 Ω (figure 4) and the cable, which is included in the kit (Fig. 4.1);
Figure 4. The led, resistor and M5Stack
Figure 4.1. CableStep 7. Build the scheme according to figure 5;
Figure 5. Connect the led 21 to the contactStep 8. Click the Upload button (Fig. 6) to flash the device;
Figure 6. Download the firmware to the deviceStep 9. When the device firmware is completed, press the A button to increase the brightness B to decrease brightness of the led (Fig. 7, 7.1) :)
Figure 7. Increasing the brightness of the led with the button A
Figure 7.1. Decrease the brightness of the led with the button B -
Thanks Dimi!
Just a little remark: I can not see any figure of this lesson, Could you please check it? -
@zuobiao thank you! I'm working on a story, photos will be added soon