pat. Object
The pat. object allows you to "play" signal patterns on up to five LED pairs — with each pair consisting of a green and red LED — and the LED bar on the Size 3 Linux Tibbo Project PCB (LTPP3), Gen. 2.
LED Pairs
The channel to work with is selected through the pat.channel property. The first channel (channel 0) is the primary channel of your system. It utilizes the green and red status LEDs on your LTPP3(G2).
When a Tibbo BASIC/C application is not running, the green and red status LEDs are used to display various status information.
The remaining four channels (channel 1-4) are identical in function, but use regular I/O lines. Moreover, the pat.greenmap and pat.redmap properties allow you to flexibly map the green and red LED control lines of each channel to any I/O lines of your LTPP3(G2).
The pattern you play can be up to 16 steps long. Each "step" can be either "-" (both LEDs off), "R" (red LED on), "G" (green LED on), or "B" (both LEDs on). You can also define whether the pattern will only execute once or loop and play indefinitely. Additionally, you can make the pattern play at normal, double, or quadruple speed.
You load the new pattern to play with the pat.play method. If the pattern is looped, it will continue playing until you change it. If the pattern is not looped, it will play once and then the on_pat event will be generated. When the event handler is entered, the pat.channel property will be automatically set to the channel number for which the event was generated.
LED patterns 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 four times on startup. In this example we work on channel 0:
void on_sys_init() {
pat.channel = 0; // Not really necessary since 0 is the default value for this property
pat.play("B-B-B-B-",PL_PAT_CANINT);
}
void on_button_pressed() {
pat.play("*R-R-R-", PL_PAT_CANINT);
}
void on_pat() {
if (pat.channel == 0) { // Not really necessary since we are not using any other channels
pat.play("~G",PL_PAT_CANINT);
}
}
In the above example, the power-up pattern is loaded inside the on_sys_init event 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 inside this event's handler. This new pattern is looped (notice "~"). When the button is pressed, a fast pattern (notice "*") is loaded. This one 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.
LED Bar
The pat. Object can control the five blue status indication LEDs on the LTPP3(G2). You load the pattern to play with the pat.playlb method.
In this simple example, we turn on the LEDs sequentially in a loop three times when the application is started. When the button is pressed, a different pattern plays. Whenever a pattern is completed, all five blue LEDs are turned on.
void on_sys_init() {
pat.playlb("L1L2L3L4L5L4L2L2L1L2L3L4L5L4L2L2L1L2L3L4L5L4L2L2L1*", PL_PAT_CANINT);
}
void on_button_pressed() {
pat.playlb("L135L24L135L24L135L24L135L24L135L24L135", PL_PAT_CANINT);
}
void on_pat_ledbar() { pat.playlb("L12345~", PL_PAT_CANINT); }