beautypg.com

Push-button, Example code 5.1, Clickledhold – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual

Page 54

background image

CHAPTER 5 • LED AND PUSH-BUTTON FUNCTIONS 53

ClickLedHold

The ClickLedHold function will turn the specified set of LEDs on for a specified amount

of time. Once that amount of time has elapsed, the specified set of LEDs will turn off. The

example below will turn all of the yellow LEDs on for three seconds (3000 milliseconds)

after which the yellow LEDs will turn off.

ClickLedHold(ALLYELLOW, 3000);

Push-Button

When using the push-button, only the press action is available to the developer. The hold

action is reserved for the main menu and cannot be accessed.

To determine if the push-button has been pressed, call the ClickBtnPressed function. This

function will only return TRUE if the button has been pressed since the last time ClickBt-

nPressed was called. The ClickBtn library contains the functions for monitoring the push-

button interface.

The example shown below will print out two statements and turn off all of the LEDs if the

button is pressed.

void Mode( void )
{
if (ClickBtnPressed())
{
printf(“The button was pressed.\n”);
ClickLedOff(ALL);
printf(“All LEDs were turned off.\n”);
}
}

Example Code 5.1

The example below can be found in the Click500ExampleCode folder and is named

“ExampleCode5.1.c.” This example demonstrates how to use the push-button and change

the display state of the LEDs. The first yellow LED will come on at startup. You can then

use the push-button to select different LED states. Selection1 = 1 selects Yellow1 LED on;

Selection1 = 2 causes all LEDs to flash quickly; and Selection1 = 3 turns on all yellow LEDs

for three seconds.