Button Object

Top  Previous  Next

object_button

All external devices and board offered by Tibbo  feature a single button called "setup button". Our modules have a line to connect such a button externally.  The setup button has a special system function: powering-up a Tibbo device with this button pressed (setup button line held LOW) causes the device to enter the serial upgrade mode. This mode is for uploading new TiOS (firmware) file into the device through the serial port.

The button is not doing anything system-related at other times, so it can be used by your Tibbo BASIC application -- hence, the button object. The object offers the folloing:

The button.pressed property returns 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, for instance, to separate button pressing into "short" and "long":

 

sub on_button_released

'see how much time has elapsed

 

       if button.time>4 then

               'the button for pressed for a "long" time -- do one thing

       else

               'the button was pressed for a "short" time -- do another thing

       end if

end sub

 

The button does not requre any pre-configuration and works always.

Note that the on_button_pressed and on_button_released events, as well as the button.time R/O property utilize "debouncing", which filters out very short transitions of the button state. The button.pressed R/O property, however, does not rely on debouncing and returns the immediate state of the button at the very moment the property is read.