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;

    alt text
    Figure 1. Built-in button

    List 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);

    alt text
    Figure 2. Create a new sketch

    Step 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);

    alt text
    Figure 3. The sketch

    Step 4. Click the Upload button (Fig. 4) in order to flash the device;

    alt text
    Figure 4. Download the firmware to the device

    Step 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).

    alt text
    Figure 5. After pressing the red button

    alt text
    Figure 5.1. After clicking on the green button

    alt text
    Figure 5.2. After clicking on the blue button