B9X Basic GUI Module

B9X Electronics Documentation

B9X Basic GUI Module — Complete B9X Basic Language Reference

Complete developer documentation for writing B9X Basic applications on the B9X Basic GUI Module, including the B9X Basic language and the public functions supplied by this module.

Public programming reference only. This documentation describes the language, syntax, callable functions, arguments, return values, and application-level use. It intentionally excludes source-code architecture, firmware internals, private algorithms, implementation details, and other proprietary workings.

1. Language fundamentals

B9X Basic is its own BASIC language. Do not assume that a statement or function from Visual Basic, QBASIC, or another BASIC dialect exists unless it is documented here.

Program structure

A program contains executable statements and may also contain SUB and FUNCTION definitions. Most simple statements end with a semicolon. Block delimiters such as THEN, ELSE, ENDIF, DO, WEND, NEXT, END SUB, and END FUNCTION do not use a semicolon.

' Minimal program
let greeting$ = "Hello from B9X";
counter = 3;
print greeting$;
print counter;

Identifiers and literals

ItemRule
Numeric identifierBegins with a letter or underscore; following characters may include digits.
String identifierUses the same rules and ends with $.
Stored name length31 characters maximum.
Numeric literalDecimal integer, fraction, or scientific notation.
String literalText enclosed in double quotes.
NamesCase-sensitive. Use function names exactly as documented.

Comments

' comment to end of line
// comment to end of line
/* block comment
   across lines */

Truth values

There is no separate Boolean type. Zero is false; any nonzero numeric value is true. Comparisons and logical operations produce numeric 0 or 1.

2. Variables, strings and arrays

Numeric variables

Ordinary numeric values use double-precision floating-point numbers.

x = 12.5;
scientific = 1.2e3;
negative = -7;

String variables

String names end in $. String assignment uses LET. The usable string value is limited to 512 characters.

let first$ = "B9X";
let message$ = first$ + " Basic";

Assignment

count = 1;
let count = count + 1;
let label$ = "ready";

Numeric arrays

DIM creates a one-dimensional numeric array. The declared upper bound is inclusive. String arrays are not implemented.

dim samples[9];
for i = 0 to 9 do
    samples[i] = i ** 2;
next
print samples[4];

The largest legal declared bound is 1023.

Scope

Variables created outside a function are global. FUNCTION parameters have their own temporary parameter values while the function executes. A function may read or modify other global variables. SUB has no parameters.

3. Expressions and operators

PrecedenceOperatorsMeaning
1( )Grouping and calls
2+ - NOT !Unary sign / logical negation
3**Exponentiation; right associative
4* /Multiply/divide
5+ -Add/subtract; + also concatenates strings
6< <= > >=Relational comparison
7== !=Equality/inequality
8AND &&Logical AND
9OR ||Logical OR
result = 2 + 3 * 4;
power = 2 ** 3 ** 2;
if temperature >= 25 and enabled == 1 then
    print "warm and enabled";
endif
let full$ = "B9X " + "Basic";
Equality: use == for comparison. A single = is assignment.

4. Statements and control flow

PRINT

print "ready";
print 2 + 2;

IF / THEN / ELSE / ENDIF

if distance < 20 then
    print "near";
else
    print "far";
endif

WHILE / DO / WEND

count = 0;
while count < 5 do
    print count;
    count = count + 1;
wend

FOR / TO / STEP / NEXT

for i = 1 to 5 do
    print i;
next

for j = 10 to 0 step -2
    print j;
next

STEP defaults to 1. Positive and negative steps are supported. Avoid STEP 0.

Explicit blocks

{
    x = 1;
    print x;
}

Statements not defined by this language

GOTO, GOSUB, INPUT, DATA/READ, SELECT CASE, BREAK, CONTINUE, and line-numbered program flow are not part of the documented grammar. Use structured blocks, SUB, and FUNCTION.

5. SUB and user FUNCTION

SUB

A SUB is a named, argument-free procedure. Call it with CALL.

sub blink()
    setHigh(2);
    wait(100);
    setLow(2);
end sub

call blink();

Numeric FUNCTION

function clamp(value, low, high)
    if value < low then
        return low;
    endif
    if value > high then
        return high;
    endif
    return value;
end function

print clamp(120, 0, 100);

String FUNCTION

A string-returning function ends in $. Parameters ending in $ are string parameters.

function greeting$(name$)
    return "Hello, " + name$;
end function

let text$ = greeting$("B9X");
  • User functions may accept up to 8 parameters.
  • A missing numeric return falls back to 0; a missing string return falls back to an empty string.
  • Define a FUNCTION before code that calls it.

6. Core string, formatting and time functions

FunctionDescriptionExample
len(text$)Character count.print len("B9X");
left$(text$, count)Characters from left.let a$ = left$("B9X Basic",3);
right$(text$, count)Characters from right.let a$ = right$("B9X Basic",5);
mid$(text$, start, count)Substring; start is 1-based.let a$ = mid$("B9X Basic",5,5);
chr$(code)One-character string from byte value.let nl$ = chr$(10);
asc(text$)Byte value of first character.print asc("A");
str$(number)Number to compact string.let n$ = str$(12.5);
val(text$)Parse leading decimal number.print val("12.5 volts");
instr(text$,find$)
instr(start,text$,find$)
1-based substring search; 0 if not found.print instr("B9X Basic","Basic");
fmt$(number,format$)Formatted numeric string.print fmt$(1234.5,"#,##0.00");

FMT$ tokens

0 required digit; # optional digit; . decimal; , grouping; % percent; leading + forces sign; E/e scientific notation; semicolon-separated sections may specify positive/negative/zero formats.

7. B9X Basic GUI Module public function reference

Function examples: Every public function below includes a one-line B9X Basic example. Numeric-returning functions use retVal = func();. String-returning functions use let s$ = func$();, matching normal B9X Basic string assignment syntax.

The signatures below are taken from the public B9X Basic registrations in the supplied GUI Module project. number means a numeric argument and string means a string argument.

GUI Module

displayAddButton

displayAddButton(value1, value2, value3, value4, value5, text6$, value7)

Adds a touchable push button.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddButton(1, 20, 40, 130, 45, "START", 2);

displayAddLabel

displayAddLabel(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds a text label.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddLabel(2, 20, 100, 280, 35, "Ready", 2, 65535);

displayAddCheckBox

displayAddCheckBox(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds a check box.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddCheckBox(3, 20, 150, 180, 40, "Enable", 0, 2);

displayAddSlider

displayAddSlider(value1, value2, value3, value4, value5, value6, value7, value8)

Adds a slider.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; value6 — numeric argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddSlider(4, 10, 210, 298, 51, 0, 100, 50);

displayAddTextBox

displayAddTextBox(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds an editable text box.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddTextBox(5, 20, 280, 280, 42, "", 32, 2);

displayAddPasswordTextBox

displayAddPasswordTextBox(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds an editable password text box that masks displayed characters.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddPasswordTextBox(6, 20, 335, 280, 42, "", 32, 2);

displayAddIcon

displayAddIcon(value1, value2, value3, value4)

Adds a supplied GUI icon.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddIcon(7, 111, 390, 17);

displaySetIcon

displaySetIcon(value1, value2)

Changes an existing icon element.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetIcon(7, 18);

displayAddBmpFromFile

displayAddBmpFromFile(value1, value2, value3, text4$, value5)

Adds a BMP image from a mounted file-system path.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; text4$ — string argument; value5 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddBmpFromFile(8, 10, 30, "/sdcard/photo.bmp", 1);

displayAddBMPFromSD

displayAddBMPFromSD(value1, value2, value3, text4$, value5)

Adds a BMP image from the SD card.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; text4$ — string argument; value5 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddBMPFromSD(9, 10, 100, "/sdcard/photo.bmp", 1);

displayAddListBox

displayAddListBox(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds a scrollable list box.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddListBox(1, 2, 3, 4, 5, "text", 7, 8);

displayAddAnalogMeter

displayAddAnalogMeter(value1, value2, value3, value4, value5, value6, value7, value8)

Adds an analog needle meter.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; value6 — numeric argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddAnalogMeter(1, 2, 3, 4, 5, 6, 7, 8);

displayAddVerticalBarMeter

displayAddVerticalBarMeter(value1, value2, value3, value4, value5, value6, value7, value8)

Adds a vertical bar meter.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; value6 — numeric argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddVerticalBarMeter(1, 2, 3, 4, 5, 6, 7, 8);

displayAddLamp

displayAddLamp(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds a status lamp.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddLamp(1, 2, 3, 4, 5, "text", 7, 8);

displayAddSwitch

displayAddSwitch(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds a program-controlled switch.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddSwitch(1, 2, 3, 4, 5, "text", 7, 8);

displayAddToggleSwitch

displayAddToggleSwitch(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds a touch-toggle switch.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddToggleSwitch(1, 2, 3, 4, 5, "text", 7, 8);

displayAddRoundedButton

displayAddRoundedButton(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds a rounded push button.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddRoundedButton(1, 2, 3, 4, 5, "text", 7, 8);

displayAddFlipSwitch

displayAddFlipSwitch(value1, value2, value3, value4, value5, text6$, value7, value8)

Adds the touch-toggle/flip-switch form.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; text6$ — string argument; value7 — numeric argument; value8 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddFlipSwitch(1, 2, 3, 4, 5, "text", 7, 8);

displayAddKeyboard

displayAddKeyboard(value1, value2)

Adds the on-screen alphanumeric keyboard.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayAddKeyboard(30, 5);

displaySetText

displaySetText(value1, text2$)

Changes the text/caption of an existing element.

Arguments: value1 — numeric argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetText(2, "Running");

displayClear

displayClear(value1)

Clears the GUI display to a color.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayClear(0);

displayRemoveAllElements

displayRemoveAllElements()

Removes all GUI elements.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayRemoveAllElements();

displayRefresh

displayRefresh()

Refreshes/redraws the GUI display.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayRefresh();

displaySetColors

displaySetColors(value1, value2, value3)

Changes an element's foreground and background RGB565 colors.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetColors(1, 65535, 0);

displaySetValue

displaySetValue(value1, value2)

Sets the numeric value of a value-based GUI element.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetValue(4, 75);

displayGetValue

displayGetValue(value1)

Returns the numeric value of a GUI element.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayGetValue(4);

displaySetChecked

displaySetChecked(value1, value2)

Sets an element's checked/on state.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetChecked(3, 1);

displayGetChecked

displayGetChecked(value1)

Returns an element's checked/on state.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayGetChecked(3);

displaySetEnabled

displaySetEnabled(value1, value2)

Enables or disables an element.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetEnabled(1, 1);

displaySetVisible

displaySetVisible(value1, value2)

Shows or hides an element.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetVisible(1, 1);

displaySetBrightness

displaySetBrightness(value1)

Sets display brightness.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displaySetBrightness(80);

displayText

displayText(text1$)

Writes text to the SSD1306 OLED.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayText("value");

getDisplayMessage$

getDisplayMessage$()

Returns the next queued GUI interaction message, or an empty string when none is waiting.

Arguments: None.

Returns: String value.

Example:

let s$ = getDisplayMessage$();

displayGetText$

displayGetText$(value1)

Returns the current text stored by an element.

Arguments: value1 — numeric argument.

Returns: String value.

Example:

let s$ = displayGetText$(5);

displayInit

displayInit(value1, value2)

Initializes the supported SSD1306 OLED interface.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = displayInit(1, 2);

SD Card and MP3

sdInit

sdInit()

Mount and prepare the SD card for B9X Basic file operations.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdInit();

sdDeinit

sdDeinit()

Unmount/release the SD card when it is no longer required.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdDeinit();

sdMounted

sdMounted()

Returns whether the SD card is currently mounted.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdMounted();

sdExists

sdExists(text1$)

Tests whether a file or directory exists at the supplied path.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdExists("/sdcard/test.txt");

sdFileSize

sdFileSize(text1$)

Returns the size of a file.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdFileSize("/sdcard/test.txt");

sdWriteText

sdWriteText(text1$, text2$)

Writes text to a file.

Arguments: text1$ — string argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdWriteText("/sdcard/test.txt", "Hello B9X");

sdAppendText

sdAppendText(text1$, text2$)

Appends text to an existing file.

Arguments: text1$ — string argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdAppendText("/sdcard/test.txt", "More text");

sdDelete

sdDelete(text1$)

Deletes the specified file.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdDelete("/sdcard/test.txt");

sdRename

sdRename(text1$, text2$)

Renames or moves a file/path.

Arguments: text1$ — string argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdRename("/sdcard/old.txt", "/sdcard/new.txt");

sdMakeDir

sdMakeDir(text1$)

Creates a directory.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sdMakeDir("/sdcard/data");

mp3Play

mp3Play(text1$)

Starts MP3 playback from a file path.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mp3Play("/sdcard/music.mp3");

mp3Stop

mp3Stop()

Stops MP3 playback.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mp3Stop();

mp3Pause

mp3Pause()

Pauses MP3 playback.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mp3Pause();

mp3Resume

mp3Resume()

Resumes paused MP3 playback.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mp3Resume();

mp3IsPlaying

mp3IsPlaying()

Returns whether MP3 playback is active.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mp3IsPlaying();

mp3SetVolume

mp3SetVolume(value1)

Sets MP3 playback volume.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mp3SetVolume(75);

mp3LastResult

mp3LastResult()

Returns the most recent MP3 operation result.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mp3LastResult();

sdReadText$

sdReadText$(text1$)

Reads text from a file and returns it as a string.

Arguments: text1$ — string argument.

Returns: String value.

Example:

let s$ = sdReadText$("/sdcard/test.txt");

sdList$

sdList$(text1$)

Returns a directory listing for the supplied path.

Arguments: text1$ — string argument.

Returns: String value.

Example:

let s$ = sdList$("/sdcard");

sdFindFirst$

sdFindFirst$(text1$)

Begins a file search and returns the first matching entry.

Arguments: text1$ — string argument.

Returns: String value.

Example:

let s$ = sdFindFirst$("/sdcard/*.mp3");

sdFindNext$

sdFindNext$()

Returns the next entry from the current file search.

Arguments: None.

Returns: String value.

Example:

let s$ = sdFindNext$();

sdFindPrevious$

sdFindPrevious$()

Returns the previous entry from the current file search.

Arguments: None.

Returns: String value.

Example:

let s$ = sdFindPrevious$();

mp3LastError$

mp3LastError$()

Returns text describing the most recent MP3 error.

Arguments: None.

Returns: String value.

Example:

let s$ = mp3LastError$();

VoIP and Audio

play

play(text1$)

Starts playback of the supplied audio file.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = play("value");

voipInit

voipInit(value1, value2, value3, value4, value5, value6)

Initializes the B9X VoIP audio interface.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument; value6 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipInit(1, 2, 3, 4, 5, 6);

voipConnect

voipConnect(text1$, value2, text3$, text4$, text5$)

Connects the VoIP client using the supplied host/connection settings.

Arguments: text1$ — string argument; value2 — numeric argument; text3$ — string argument; text4$ — string argument; text5$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipConnect("value", 2, "text", "text", "text");

voipClose

voipClose()

Closes the VoIP connection.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipClose();

voipIsSending

voipIsSending()

Returns whether VoIP audio is currently being sent.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipIsSending();

voipIsConnected

voipIsConnected()

Returns whether the VoIP connection is active.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipIsConnected();

voipStartListening

voipStartListening()

Starts receiving/listening to VoIP audio.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipStartListening();

voipHaltListening

voipHaltListening()

Stops VoIP listening.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipHaltListening();

voipStartSending

voipStartSending()

Starts sending VoIP audio.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipStartSending();

voipHaltSending

voipHaltSending()

Stops sending VoIP audio.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipHaltSending();

voipEnableVOX

voipEnableVOX(value1)

Enables voice-operated transmit using the supplied setting/threshold.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipEnableVOX(1);

voipDisableVOX

voipDisableVOX()

Disables voice-operated transmit.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipDisableVOX();

voipIsVOXActive

voipIsVOXActive()

Returns whether VOX is currently active.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipIsVOXActive();

voipSetVolume

voipSetVolume(value1)

Sets VoIP speaker volume.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipSetVolume(1);

voipSetMicGain

voipSetMicGain(value1)

Sets VoIP microphone gain.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = voipSetMicGain(1);

playInit

playInit(value1, value2, value3)

Initializes WAV/audio playback using the supplied pins/settings.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = playInit(1, 2, 3);

isPlaying

isPlaying()

Returns whether local audio playback is active.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = isPlaying();

Online AI, TTS and Voice

ttsSpeak

ttsSpeak(text1$)

Speaks the supplied text using local TTS.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ttsSpeak("Hello from B9X");

ttsxInit

ttsxInit(value1, value2, value3, text4$, text5$, text6$)

Initializes online TTS using the supplied audio/API settings.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; text4$ — string argument; text5$ — string argument; text6$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ttsxInit(1, 2, 3, "text", "text", "text");

ttsxSpeak

ttsxSpeak(text1$)

Speaks the supplied text using online TTS.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ttsxSpeak("Hello from B9X");

vrxInit

vrxInit(value1, value2, value3, value4, text5$)

Initializes online voice transcription/recognition.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; text5$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = vrxInit(1, 2, 3, 4, "text");

vrxTranscribe

vrxTranscribe(value1)

Records/transcribes speech using the configured online transcription service.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = vrxTranscribe(1);

oaixInit

oaixInit(text1$)

Initializes the OpenAI text interface with the supplied API key.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = oaixInit("YOUR_API_KEY");

oaixAskQuestion

oaixAskQuestion(value1, text2$)

Submits a question/request to the configured OpenAI text interface.

Arguments: value1 — numeric argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = oaixAskQuestion(1, "text");

vrxGetTranscript$

vrxGetTranscript$()

Returns the most recently available transcription text.

Arguments: None.

Returns: String value.

Example:

let s$ = vrxGetTranscript$();

oaixGetAnswer$

oaixGetAnswer$()

Returns the latest OpenAI text answer.

Arguments: None.

Returns: String value.

Example:

let s$ = oaixGetAnswer$();

ttsInit

ttsInit(value1, value2, value3, value4)

Initializes local text-to-speech support.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ttsInit(1, 2, 3, 4);

ttsIsBusy

ttsIsBusy()

Returns whether local text-to-speech is busy.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ttsIsBusy();

MQTT

mqttClientUnsubscribe

mqttClientUnsubscribe(text1$)

Unsubscribes from an MQTT topic.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mqttClientUnsubscribe("b9x/status");

mqttClientSubscribe

mqttClientSubscribe(text1$)

Subscribes to an MQTT topic.

Arguments: text1$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mqttClientSubscribe("b9x/status");

mqttClientPublish

mqttClientPublish(text1$, text2$)

Publishes text to an MQTT topic.

Arguments: text1$ — string argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = mqttClientPublish("b9x/status", "online");

initMQTTClient

initMQTTClient(text1$, text2$, text3$)

Initializes the MQTT client with broker/credential settings.

Arguments: text1$ — string argument; text2$ — string argument; text3$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = initMQTTClient("broker-address", "username", "password");

mqttClientGetMessage$

mqttClientGetMessage$()

Returns the next queued MQTT message.

Arguments: None.

Returns: String value.

Example:

let s$ = mqttClientGetMessage$();

GPIO, ADC, Timing and Sensors

motionInit

motionInit(value1, value2)

Initializes the supported motion/distance interface.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = motionInit(1, 2);

motionGetDistance

motionGetDistance()

Returns the current measured distance.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = motionGetDistance();

wait

wait(value1)

Pauses the B9X Basic program for the requested milliseconds.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = wait(100);

readTemperature

readTemperature(value1)

Reads a supported temperature sensor on the supplied GPIO.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = readTemperature(4);

initADC

initADC()

Initializes ADC support.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = initADC();

readADCMV

readADCMV(value1)

Reads an ADC channel in millivolts.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = readADCMV(0);

readADCRaw

readADCRaw(value1)

Reads a raw ADC channel value.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = readADCRaw(0);

deinitADC

deinitADC()

Releases ADC support.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = deinitADC();

makeInput

makeInput(value1)

Configures a GPIO as an input.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = makeInput(4);

getInput

getInput(value1)

Reads a GPIO input.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = getInput(4);

makeOutput

makeOutput(value1)

Configures a GPIO as an output.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = makeOutput(2);

setHigh

setHigh(value1)

Sets a GPIO output high.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = setHigh(2);

setLow

setLow(value1)

Sets a GPIO output low.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = setLow(2);

getTicks

getTicks(value1)

Returns elapsed operating time in the selected units.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = getTicks(1);

Infrared and WS2812

irInit

irInit(value1)

Initializes infrared reception.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = irInit(4);

irGetCode

irGetCode()

Returns the most recently received infrared code.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = irGetCode();

ws2812Init

ws2812Init(value1, value2)

Initializes a WS2812 addressable LED strip.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ws2812Init(1, 2);

ws2812Fill

ws2812Fill(value1, value2, value3, value4)

Sets all LEDs in a strip to one RGB value.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ws2812Fill(1, 2, 3, 4);

ws2812SetPixel

ws2812SetPixel(value1, value2, value3, value4, value5)

Sets one LED pixel to an RGB value.

Arguments: value1 — numeric argument; value2 — numeric argument; value3 — numeric argument; value4 — numeric argument; value5 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ws2812SetPixel(1, 2, 3, 4, 5);

ws2812Show

ws2812Show(value1)

Updates the physical LED strip with pending pixel values.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ws2812Show(1);

ws2812Clear

ws2812Clear(value1)

Clears the LED strip.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ws2812Clear(1);

ws2812IsBusy

ws2812IsBusy(value1)

Returns whether the LED strip interface is busy.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = ws2812IsBusy(1);

Storage, System and Network

setNVS

setNVS(text1$, text2$)

Stores a string value by key.

Arguments: text1$ — string argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = setNVS("ssid", "MyNetwork");

logData

logData(text1$, text2$)

Writes/logs the supplied data using the module logging facility.

Arguments: text1$ — string argument; text2$ — string argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = logData("value", "text");

getNVS$

getNVS$(text1$)

Reads a saved string value by key.

Arguments: text1$ — string argument.

Returns: String value.

Example:

let s$ = getNVS$("ssid");

memx

memx()

Returns a memory-related status/value supplied by the module.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = memx();

wifiIsConnected

wifiIsConnected()

Returns 1 when Wi-Fi is connected, otherwise 0.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = wifiIsConnected();

getResetType

getResetType()

Returns the most recent reset/restart type.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = getResetType();

restart

restart()

Restarts the module.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = restart();

Math, Formatting and Date/Time

fmt$

fmt$(value1, text2$)

Formats a number according to a format string.

Arguments: value1 — numeric argument; text2$ — string argument.

Returns: String value.

Example:

let s$ = fmt$(1234.5, "#,##0.00");

hour

hour()

Returns local hour 0–23.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = hour();

minute

minute()

Returns local minute 0–59.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = minute();

second

second()

Returns local second 0–59.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = second();

month

month()

Returns local month 1–12.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = month();

day

day()

Returns local day of month.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = day();

year

year()

Returns local four-digit year.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = year();

weekDay

weekDay()

Returns the current local weekday value.

Arguments: None.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = weekDay();

abs

abs(value1)

Returns the absolute value.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = abs(-12.5);

log

log(value1)

Returns the natural logarithm.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = log(10);

log10

log10(value1)

Returns the base-10 logarithm.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = log10(100);

round

round(value1)

Rounds to the nearest integral value.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = round(12.6);

exp

exp(value1)

Returns e raised to the supplied power.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = exp(2);

sin

sin(value1)

Returns sine of a radian value.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sin(1);

cos

cos(value1)

Returns cosine of a radian value.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = cos(1);

tan

tan(value1)

Returns tangent of a radian value.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = tan(1);

asin

asin(value1)

Returns inverse sine in radians.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = asin(0.5);

acos

acos(value1)

Returns inverse cosine in radians.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = acos(0.5);

atan

atan(value1)

Returns inverse tangent in radians.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = atan(1);

sinh

sinh(value1)

Returns hyperbolic sine.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sinh(1);

cosh

cosh(value1)

Returns hyperbolic cosine.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = cosh(1);

rnd

rnd(value1, value2)

Returns a random integer-valued number in the inclusive range.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = rnd(1, 10);

sqrt

sqrt(value1)

Returns square root.

Arguments: value1 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = sqrt(81);

modulo

modulo(value1, value2)

Returns integer remainder after numeric arguments are converted to integers.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = modulo(10, 3);

min

min(value1, value2)

Returns the smaller of two numbers.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = min(10, 20);

max

max(value1, value2)

Returns the larger of two numbers.

Arguments: value1 — numeric argument; value2 — numeric argument.

Returns: Numeric result/status/value as appropriate for the function.

Example:

retVal = max(10, 20);

Built-in icon gallery

The B9X Basic GUI Module includes the following built-in icons. The number shown beside each image is the iconNumber used with displayAddIcon() and displaySetIcon().

result = displayAddIcon(14, 111, 309, 17);  ' icon 17 = Play
result = displaySetIcon(14, 18);            ' change to Pause
Tip: Use the gallery below when choosing an icon in B9X Basic or the B9X Basic Screen Designer.

B9X_GUI_BuiltIn_Icons_1

B9X_GUI_BuiltIn_Icons_2

B9X_GUI_BuiltIn_Icons_3

B9X_GUI_BuiltIn_Icons_4

Icon number reference

IconName
1Home
2Back
3Forward
4Up
5Down
6Menu
7Settings
8Information
9Warning
10Error
11Check
12Close
13Plus
14Minus
15Power
16Refresh
17Play
18Pause
19Stop
20Record
21Volume Up
22Volume Down
23Mute
24Brightness
25Wifi
26Bluetooth
27Lock
28Unlock
29User
30Users
31Temperature
32Humidity
33Light
34Fan
35Pump
36Valve
37Motor
38Heater
39Cooling
40Battery
41Plug
42Clock
43Calendar
44Camera
45Folder
46Save
47Upload
48Download
49Edit
50Trash
51Lamp Off
52Lamp On
53Lamp Dim
54Switch Off
55Switch On
56Selector Left
57Selector Center
58Selector Right
59Door Closed
60Door Open
61Door Locked
62Garage Closed
63Garage Open
64Window Closed
65Window Open
66Blinds Closed
67Blinds Half
68Blinds Open
69Thermostat Heat
70Thermostat Cool
71Thermostat Auto
72Thermostat Off
73Motion Idle
74Motion Detected
75Alarm Disarmed
76Alarm Armed
77Alarm Triggered
78Water Dry
79Water Leak
80Smoke Clear
81Smoke Alarm
82Security Camera On
83Security Camera Off
84Machine Stop
85Machine Run
86Machine Fault
87Machine Maintenance
88Conveyor Stop
89Conveyor Run
90Conveyor Reverse
91Pump Off
92Pump On
93Pump Fault
94Valve Closed
95Valve Open
96Valve Half
97Tank Empty
98Tank Quarter
99Tank Half
100Tank Three Quarter
101Tank Full
102Motor Off
103Motor Forward
104Motor Reverse
105Motor Fault
106Traffic Red
107Traffic Yellow
108Traffic Green
109Mode Auto
110Mode Manual
111Mode Off
112Emergency Stop
113Pressure Low
114Pressure Normal
115Pressure High
116Level Low
117Level Normal
118Level High
119Temperature Cold
120Temperature Normal
121Temperature Hot

8. GUI event messages

getDisplayMessage$() returns the next queued GUI event. When no event is waiting it returns an empty string.

[DMSG][elementNumber][elementType][activity][value][x][y][text]
ActivityValueMeaning
NO_ACTIVITY0No activity
PRESSED1Element pressed
RELEASED2Touch released
CLICKED3Element clicked
VALUE_CHANGED4Value changed
CHECKED5Checked/on
UNCHECKED6Unchecked/off
FOCUSED7Text element focused
TEXT_CHANGED8Text changed
KEY_PRESSED9Keyboard key pressed
KEYBOARD_DONE10Keyboard Done selected
KEYBOARD_CANCELLED11Keyboard Cancel selected
QUEUE_OVERFLOW12Event queue overflow

The GUI uses portrait 320 × 480 coordinates. Element numbers should be unique among active elements. Up to 48 active GUI elements are supported. GUI colors use numeric RGB565 values.

9. Programming patterns

Basic GUI application

START_BUTTON = 1;
STATUS_LABEL = 2;
LEVEL_SLIDER = 3;

result = displayRemoveAllElements();
result = displayClear(0);

result = displayAddButton(START_BUTTON, 20, 40, 130, 45, "START", 2);
result = displayAddLabel(STATUS_LABEL, 20, 100, 280, 35, "Ready", 2, 65535);
result = displayAddSlider(LEVEL_SLIDER, 10, 170, 298, 51, 0, 100, 50);
result = displayRefresh();

while 1 do
    let msg$ = getDisplayMessage$();
    if len(msg$) > 0 then
        print msg$;
    endif
    wait(10);
wend

Editable text and password

result = displayAddTextBox(10, 20, 60, 280, 42, "", 32, 2);
result = displayAddPasswordTextBox(11, 20, 120, 280, 42, "", 32, 2);
result = displayAddKeyboard(30, 10);
result = displayRefresh();

let user$ = displayGetText$(10);
let password$ = displayGetText$(11);

MQTT

result = initMQTTClient("broker-address", "username", "password");
result = mqttClientSubscribe("b9x/status");
result = mqttClientPublish("b9x/status", "online");

let mqttMessage$ = mqttClientGetMessage$();

SD text file

result = sdInit();
result = sdWriteText("/sdcard/test.txt", "B9X Basic");
let text$ = sdReadText$("/sdcard/test.txt");
print text$;

10. Language limits and quick reference

ItemDocumented limit/rule
Identifier storage31 characters maximum
String value512 characters maximum usable value
Numeric array boundMaximum declared upper bound 1023
Array typeOne-dimensional numeric arrays; string arrays are not implemented
User FUNCTION parametersUp to 8
GUI elementsUp to 48 active elements
GUI coordinatesPortrait 320 × 480 pixels
GUI colorsRGB565 numeric values

Reserved/control words used by the language

LET, PRINT, DIM, IF, THEN, ELSE, ENDIF, WHILE, DO, WEND, FOR, TO, STEP, NEXT, SUB, END SUB, CALL, FUNCTION, END FUNCTION, RETURN, AND, OR, NOT.

B9X Basic Screen Designer: The Screen Designer can be used to lay out GUI elements visually and generate B9X Basic GUI creation code. The generated program uses the same public GUI functions documented here.

B9X Basic GUI Module • B9X Electronics • Copyright © 2026 B9X Electronics. All Rights Reserved.