Lesson 2. BUTTONS. Menu
-
This lesson focuses on the built-in buttons. We will learn how to use the buttons on the example of changing the color of the circle.
Step 1. Review the functions buttons (Fig. 1) in list 1;
Figure 1. Built-in buttonList 1. Functions for working with built-in buttons
- M5.BtnA/B/C. read(); Constantly returns true if the button is pressed and false if pressed
- M5.BtnA/B/C. isPressed(); If the button was pressed – always returns true
- M5.BtnA/B/C. isReleased(); If the button is pressed – always returns true
- M5.BtnA/B/C. wasPressed(); One press – one true
- M5.BtnA/B/C. was released(); One UPS – single true
- M5.BtnA/B/C. pressedFor(uint32_t ms); If the button is pressed more than the set time – always returns true
- M5.BtnA/B/C. releasedFor(uint32_t ms); If the button is pressed more than the set time – always returns true
- M5.BtnA/B/C. lastChange(); Constantly returns true if the button has ever been pressed
Step 2. Create a new sketch in the Arduino IDE. On the File menu, select New (Fig. 2);
Figure 2. Create a new sketchStep 3. Please note that for operation of the buttons you want to add to the end system functions void loop() function call M5.update(); Write our code (Fig. 3);
Figure 3. The sketchStep 4. Click the Upload button (Fig. 4) in order to flash the device;
Figure 4. Download the firmware to the deviceStep 5. When the device firmware is completed, the device display labels above the buttons with the corresponding colors are displayed a circle of different colors (Fig. 5 - 5.2).
Figure 5. After pressing the red button
Figure 5.1. After clicking on the green button
Figure 5.2. After clicking on the blue button -
@Dimi The information in step 1 is incorrect.