back to Icon
Description
This function is used to wait while an icon is still being pressed. It takes as inputs the initial x and y positions of the first touch and then calls LCD.Touch() and .Pressed() within the function to continue to check if the icon is still being pressed. Once the icon is no longer being pressed, the function will exit.
Note that the LCD.Touch() function must be called to get initial touch values for x and y to send into the .WhilePressed() function.
Syntax
.WhilePressed(float xi, float yi);
Parameters
xi: float initial pixel position in x direction of current touch
y:i float initial pixel position in y direction of current touch
Returns
None.
Examples
#include <FEHLCD.h> int main(void) { // declare a single icon called software_button FEHIcon::Icon software_button; // set its parameters with "BUTTON" as the label, // top left corner at 120,80 and size 80 by 80, // and make the border scarlet and the text gray software_button.SetProperties("BUTTON", 120, 80, 80, 80, SCARLET, GRAY); // draw the icon software_button.Draw(); // declare int n to keep track of number of presses and // floats x and y for touch positions int n=0; float x, y; // continuously check to see if the icon is pressed and // increment the number of presses label if so but wait // until the icon is unpressed before updating while (true) { LCD.Touch(&x,&y); if (software_button.Pressed(x,y,0)) { n++; software_button.WhilePressed(x,y); software_button.Deselect(); LCD.Clear(BLACK); software_button.ChangeLabelInt(n); } } }