|
Pat Object (V1.1) |
Top Previous Next |
The pat object allows you to "play" signal patters on two status LEDs- red and green. The pattern you play can be up to 16 steps long. Each "step" can be either "-" (both LEDs off), or "R" (red LED on), or "G" (green LED on), or "B" (both LEDs on). You can also define whether the pattern will only execute one or loop and play indefinitely. Additionally, you can make the pattern play at "normal" or double speed.
You load the new pattern to play with the pat.play method. If the pattern is looped it will continue playing until you changed it. If the pattern is not looped it will play once and then the on_pat event will be generated.
LED patters offer a convenient way to tell the user what your system is doing. You can devise different patterns for different states of your device.
Here is a simple example in which we keep the green LED on at all times, except when the button is pressed, after which the green LED is turned off and the red LED blinks three times fast. Additionally, both green and red LEDs blink 4 times on startup.
sub on_sys_init pat.play("B-B-B-B-",PL_PAT_CANINT) end sub
sub on_button_pressed pat.play("*R-R-R-",PL_PAT_CANINT) end sub
sub on_pat pat.play("~G",PL_PAT_CANINT) end sub
|
In the above example, the power up pattern is loaded in the on_sys_init handler. This is not a looped pattern, so once it finishes playing the on_pat event is generated and the "permanent" pattern "green LED on" is loaded. This one is looped (as defined by the "~"). When the button is pressed, an fast (see "*") pattern is loaded that makes the red LED blink three times. Again, this is not a looped pattern, so after it finishes playing the on_pat event is generated and the permanent "green" pattern is loaded again.