The display functions draw text and graphics on the screen of products that have a built-in display.
On products without a display, every display function is simply ignored, so the same script remains safe to run on any device.
Available for OS7.1.0 and later
display.print(string)
Appends a string at the current cursor position. The cursor advances as characters are written, so calling display.print() repeatedly continues the text from where it left off, much like a typewriter.
Arguments
| Argument | Type | Description |
|---|---|---|
string |
string | The text to draw. |
display.clear()
Clears the entire screen.
display.raw(table)
Draws a raw framebuffer directly to the screen.
The table is a byte array in which each element holds a single byte from 0 to 255. The bytes are laid out vertically, following the framebuffer format of the display.
Arguments
| Argument | Type | Description |
|---|---|---|
table |
table | A byte array of framebuffer data. Each element is a value from 0 to 255. |
Example: Typewriter Text
The following example reveals each message one character at a time, producing a typewriter effect.
local messages = {
"Hello from obniz",
"Lua is running on the device.",
"Bye!",
}
local msg_index = 1
local char_index = 0
local tick = 0
local interval = 120 -- milliseconds per character
os.log(" - Lua PowerOn");
display.clear();
function on_offline_loop()
loop()
end
function on_online_loop()
loop()
end
function loop()
if tick + interval < os.getTick() then
tick = os.getTick()
local msg = messages[msg_index]
if char_index < #msg then
-- Append the next single character
char_index = char_index + 1
display.print(msg:sub(char_index, char_index));
else
-- Move on to the next message
char_index = 0
msg_index = msg_index + 1
if msg_index > #messages then
msg_index = 1
end
end
end
end