Skip to content

+49 1626571232

info@openelab.io

🚀 Free Shipping from 50€ in EU / 80€ Worldwide

M5Stack Beginner: PLUS2 Button User Guide

11 Oct 2024 0 Comments

Introduction

The button on the M5StickC Plus2 is located on the side of the device and is typically used for user input or control functions. The button can be configured to perform various operations, such as short press, long press, and double-click, to meet different control needs. Through programming, users can assign different functions to the button, such as initiating a specific task or controlling the device's operating mode.

M5StickC PLUS2

M5StickC PLUS2

View Product

 

How do you view the underlying logic?

If you are interested in the underlying logic or functions during the learning process, you can click on the relevant links to explore the details further.

1. Dependent Library:

2. It is usually located in the src directory.

   

Code Comments and Function Descriptions

       
1. Display.setRotation(1)

    In M5Stack, the commonly used rotation settings are as follows:

    • 0: Default orientation (portrait).
    • 1: Rotate 90 degrees clockwise (landscape).
    • 2: Rotate 180 degrees clockwise (upside-down portrait).
    • 3: Rotate 270 degrees clockwise (landscape, opposite to 1).
                         

    2. StickCP2.Display.drawString("Button Test", StickCP2.Display.width() / 2,StickCP2.Display.height() / 2);

      • Button Test -> Displays the text content.
      • StickCP2.Display.width() / 2 -> Calculates half of the screen width to determine the X-coordinate for positioning the text at the horizontal center of the screen.
      • StickCP2.Display.height() / 2 -> Calculates half of the screen height to determine the Y-coordinate for positioning the text at the vertical center of the screen.
           
         
      3. StickCP2.update();

      The update() function is used to update the device status or handle events and is commonly found in code for M5StickC Plus 2 (or similar devices). This function is often used in the following scenarios:

      • Updating Display Content: If the screen content needs to be refreshed or updated continuously, the update() function can be used to periodically refresh the display.
      • Handling Button Input: When the device has buttons or touch inputs, the update() function can detect these inputs and update the button states accordingly.
      • Timed Tasks or Event Handling: The update() function may also be used for executing timed tasks or handling periodic events to keep the device operating smoothly.

      In the development libraries for the M5Stack series, update() is typically employed as a standard practice for maintaining device status and managing sensors or inputs. Each time the update() function is called, the device checks the current state and performs the necessary updates.

          
      4. StickCP2.BtnA.wasPressed()

      Function to Detect if Button A is Pressed:

      • wasPressed() method is used to check whether Button A has been pressed during the current or previous loop. It returns a boolean value: true if Button A has been pressed, and false if it has not.
      • wasPressed() is typically used for event triggers, such as switching display content, activating a function, or controlling the behavior of the device. Unlike the regular isPressed(), wasPressed() is more suitable for detecting a single press event rather than a continuous pressed state.
          
      5. StickCP2.BtnA.wasReleased()

        Checks if Button A has been released. If Button A is released, the wasReleased() function will return true, and the code inside the braces will be executed. This function is suitable for detecting the release event of the button rather than its pressed state.

           

        Prev Post
        Next Post

        Leave a comment

        All blog comments are checked prior to publishing

        Someone recently bought a

        Thanks for subscribing!

        This email has been registered!

        Shop the look

        Choose Options

        Edit Option
        Back In Stock Notification
        this is just a warning
        Login
        Shopping Cart
        0 items
        RuffRuff App RuffRuff App by Tsun