button. Object
All programmable boards, programmable serial controllers, and Tibbo Project System (TPS) devices offered by Tibbo feature a button referred to as the "setup" or "MD" button ("MD" stands for "mode"). All Tibbo programmable modules have a line for connecting this button externally.
The setup button has a special system function: powering-up a Tibbo device with this button pressed (on modules, the MD line held LOW) causes the device to enter the firmware upgrade mode. This mode is for uploading new TiOS (firmware) into the device. The second system function of the MD button is to bypass forgotten passwords.
When a programmable Tibbo device is executing a Tibbo BASIC/C application, the MD button can be used as a general-purpose input button.
The button. object offers the following:
- The button.pressed read-only property returns the current (immediate) state of the button.
- The on_button_pressed event is generated when the button is pressed.
- The on_button_released event is generated when the button is released.
- The button.time read-only property returns the time (in 0.5 intervals) elapsed since the button was last pressed or released. You can use this property to execute different button actions depending on whether the button was "long-pressed" or "short-pressed":
sub on_button_released() if button.time>4 then 'the button was pressed for a "long" time -- do one thing else 'the button was pressed for a "short" time -- do another thing end if end sub
void on_button_released(){ if(button.time>4){ //the button was pressed for a "long" time -- do one thing } else{ //the button was pressed for a "short" time -- do another thing } }
The button does not require any pre-configuration.
Note that the on_button_pressed and on_button_released events, as well as the button.time read-only property utilize "debouncing," which filters out very short transitions of the button state.
The button.pressed read-only property, however, bypasses the debouncing algorithm to return the immediate state of the button at the very moment the property is read.