{"id":1282,"date":"2026-05-07T20:35:41","date_gmt":"2026-05-07T20:35:41","guid":{"rendered":"https:\/\/b9xelectronics.com\/?page_id=1282"},"modified":"2026-05-08T04:09:23","modified_gmt":"2026-05-08T04:09:23","slug":"workbench-c","status":"publish","type":"page","link":"https:\/\/b9xelectronics.com\/?page_id=1282","title":{"rendered":"B9X C"},"content":{"rendered":"\n<p><strong><em>B9X C Language Reference <\/em><\/strong><\/p>\n\n\n\n<p>B9X C is a high level language that utilizes pretty much the same syntax as C.<br>This language is case sensitive. You can use this documentation page as a reference for understanding the functions. B9X C operates as, what technically is called, a finite state machine. This is nothing more than a while(1) {;} loop that you define. All the included functions return immediately. This means there are no blocking functions. The only exception is wait().  By definition, wait(); is defined to block intentionally for the number of milliseconds you provide.<\/p>\n\n\n\n<p>The best way to get started is to view the included examples and try them out on our module.  Below is a download link to a zip file that contains nothing more than text files. This file contains numerous application written exclusively for B9X C. You simply upload the &#8216;config.txt&#8217; and the &#8216;main.c&#8217; text files, for each example to our module, to try them out.<\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-8a0cbb02-5f7b-4927-9897-89a672627c3f\" href=\"https:\/\/b9xelectronics.com\/wp-content\/uploads\/2026\/05\/B9XCExampleApplications.zip\">B9XCExampleApplications<\/a><a href=\"https:\/\/b9xelectronics.com\/wp-content\/uploads\/2026\/05\/B9XCExampleApplications.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-8a0cbb02-5f7b-4927-9897-89a672627c3f\">Download<\/a><\/div>\n\n\n\n<p>To try out the examples, you need to purchase our module. Please go to the &#8216;Shop&#8217; section found on this site or go to                                   <a href=\"https:\/\/b9xelectronics.com\/?product=b9x-c-developer-module\">B9X Developer Module<\/a> to purchase.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong><em>WiFi Network Setup For Static IP<\/em><\/strong><\/p>\n\n\n\n<p>These functions are defined to work with most any WiFi router.<br>The below values are only examples and can be added to the config.txt file. This file<br>can then be uploaded to the module for setting a static IP.<br>Do a module reset after uploading. All fields must be included.<\/p>\n\n\n\n<p>Add To config.txt:<br>[DEVICENAME][B9X_CDEV40]<br>[LOCALHOST][192.168.5.40]<br>[SUBNET][255.255.255.0]<br>[GATEWAY][192.168.5.90]<br>[DNS1][192.168.5.90]<br>[DNS2][8.8.8.8]<br>[LOCALPORT][24000]<\/p>\n\n\n\n<p><strong><em>Variables:<\/em><\/strong><\/p>\n\n\n\n<p>Three types of variables are supported. String variables, double precision floating point, and limited support for<br>arrays of double precision floating point.<\/p>\n\n\n\n<p>There are no declarations required for double precision floating point.<br>i=3.14; is an example of assigning a value to double.<\/p>\n\n\n\n<p>Arrays of double precision floating point variables must be declared before they are used and<br>must begin with the &#8216;@&#8217; character. Up to 20 arrays can be created.<\/p>\n\n\n\n<p>To declare an array:<br>new @arrayVar[]; \/\/ creates an array named @arrayVar and assigns all its 128 values to 0.0<\/p>\n\n\n\n<p>To delete an array:<br>delete @arrayVar[]; \/\/ deletes an array named @arrayVar<\/p>\n\n\n\n<p>To assign a value to an array element:<br>@arrayVar[0]=3.14; \/\/ arrays can only be indexed from 0 to 127<\/p>\n\n\n\n<p>Strings must be declared before they are used.<br>$var=&#8221;&#8221;; is an example of declaring the string variable $var. All string variables must<br>begin with the &#8216;$&#8217; character.<\/p>\n\n\n\n<p>Two types can represent strings:<br>1) quoted string -&gt; &#8220;in quotes&#8221;<br>2) string variable -&gt; $str<\/p>\n\n\n\n<p><strong><em>Math operators for double precision floating point:<\/em><\/strong><\/p>\n\n\n\n<p>Assignment operators: =, +=, -=, *=, \/=<br>Conditional expressions: ? :<br>Logical operators: !, &amp;&amp;, ||<br>Comparison operators: ==, !=, &lt;, &lt;=, &gt;, &gt;=<br>Binary arithmetic operators: +, -, *, \/<br>Modulus operator: %<br>Exponentiation: **<br>Unary arithmetic operators: +, &#8211;<br>Parentheses ( )<\/p>\n\n\n\n<p><strong><em>Native Clauses And Equivalents:<\/em><\/strong><\/p>\n\n\n\n<p>Examples:<\/p>\n\n\n\n<p>1)<br>statement;<br>statement;<br>statement;<\/p>\n\n\n\n<p>2)<br>do while(expression) {<br>statements;<br>}<\/p>\n\n\n\n<p>3)<br>while(expression) {<br>statements;<br>}<\/p>\n\n\n\n<p>4)<br>if(expression) {<br>statements;<br>}<\/p>\n\n\n\n<p>5)<br>if(expression) {<br>statements;<br>}<br>else {<br>statements;<br>}<\/p>\n\n\n\n<p>6) Equivalant for() clause<br>\/\/ example<br>for(i=0;i&lt;10;i++) {<br>statements;<br>}<\/p>\n\n\n\n<p>\/\/ equivalent<br>i=0; \/\/ example -&gt; for(i=0;\u2026;\u2026) {;}<\/p>\n\n\n\n<p>while(i&lt;10) { \/\/ example -&gt; for(\u2026;i&lt;10;\u2026) {;}<br>statements;<br>statements;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    i+=1; \/\/ example -&gt; for(...;...;i++) {;}<\/code><\/pre>\n\n\n\n<p>}<\/p>\n\n\n\n<p>7) Equivalent switch\/case clause<\/p>\n\n\n\n<p>\/\/ example<br>switch(n) {<br>case 1:<br>statements;<br>break;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    case 2:\n        statements;\n        break;\n\n    case 3:\n        statements;\n        break;\n\n    default:\n        statements;\n        break;<\/code><\/pre>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\/\/ equivalent<br>if(n==1) {<br>statements;<br>}<br>if(n==2) {<br>statements;<br>}<br>if(n==3) {<br>statements;<br>}<br>else {<br>statements; \/\/ default statements<br>}<\/p>\n\n\n\n<p><strong><em>Math Functions<\/em><\/strong><\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double fabs(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the absolute value of the double &#8216;value&#8217;<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double log(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the natural logarithm (base e) of the double &#8216;value&#8217;<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double modf(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the decimal part of the double &#8216;value&#8217;.<br>Example: 3.14 will return 0.14<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double log10(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the base-10 logarithm of the double &#8216;value&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double exp(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the Euler&#8217;s number (e \u2248 2.71828) raised<br>to the power of the double &#8216;value&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double sin(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the sine of an angle (in radians) of<br>the double &#8216;value&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double cos(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the cosine of an angle (in radians) of<br>the double &#8216;value&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double tan(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the tangent of an angle of an angle (in radians) of<br>the double &#8216;value&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double asin(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the arc sine (inverse sine) of an angle of<br>the double &#8216;value&#8217; and returns the result in radians. The input must be in the range -1 to 1.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double acos(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the arc cosine (inverse cosine) of an angle of<br>the double &#8216;value&#8217; and returns the result in radians. The input must be in the range -1 to 1.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double atan(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the arc tangent\/inverse tangent of the<br>double &#8216;value&#8217; and returns the result in radians.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double cosh(double value);<br>\/<em>==========================================================<\/em>\/<br>This function returns the hyperbolic cosine of an angle of<br>the double &#8216;value&#8217; in radians.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double sinh(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the hyperbolic sine of an angle of<br>the double &#8216;value&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double sqrt(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the square root of a the double number &#8216;value&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double round(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function is used to round a floating-point number to the<br>nearest integer. Only the first number after the decimal point<br>is considered.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double random(double lowest, double highest);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function is used to provide a random floating-point number<br>in the range &#8216;lowest&#8217; to &#8216;highest&#8217;.<\/p>\n\n\n\n<p><strong><em>String Functions<\/em><\/strong><\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar get_nth_field(double index, stringvar $fields);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the nth field in a series of square bracket delimited string data.<br>Example:<br>$var=&#8221;&#8221;;<br>$fields=&#8221;[one][two][three][four]&#8221;;<br>$var=get_nth_field(3, $fields);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$var would now equals \"three\"<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar get_nth_field(double index, stringvar $fields);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the nth field in a series of less than\/greater than bracket delimited string data.<br>Example:<br>$var=&#8221;&#8221;;<br>$fields=&#8221;&#8221;;<br>$var=get_nth_field_lg(3, $fields);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$var would now equals \"three\"<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar ftoa(double value);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the string equivalent of the provided double &#8216;value&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Example:\nn=3.14;\n$var=ftoa(n);\n\n$var would now equal \"3.14\"<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double strcmp(stringvar $str1, stringvar $str2);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function compares two string variables to see if they are equivalent. This function is case sensitive.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Example:\n$var1=\"hello\";\n$var2=\"hello\";\nn=strcmp($var1, $var2);\n\nn would now equal 0.0 meaning the strings are equivalent. If they were not equal it would return 1.0.<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double strcat(stringvar $str1, stringvar $str2);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function concatenates string variable $str2 onto $str1.<br>Example:<br>$str1=&#8221;&#8221;;<br>$str2=&#8221;&#8221;;<br>$str1=&#8221;hello &#8220;;<br>$str2=&#8221;world!&#8221;;<br>strcat($str1, $str2);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$str1 would now equal \"hello world!\"<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double strcat(stringvar $str, stringquote &#8220;\u2026&#8221;);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function concatenates stringquote onto $str1.<br>Example:<br>$str=&#8221;&#8221;;<br>$str=&#8221;hello &#8220;;<br>strcat($str, &#8220;world!&#8221;);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$str1 would now equal \"hello world!\"<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double strsave(stringquote &#8220;\u2026&#8221;, stringvar $str);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function saves a string variable named stringquote &#8220;\u2026&#8221; with<br>a value of $str into flash memory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Example:\n    $str=\"\";\n    $str=\"3.14\";\n    strsave(\"VAR1\", $str);\n\n    VAR1 will now equal \"3.14\" and saved into flash memory.<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double strget(stringvar $str1, stringvar $str2);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function retrieves a string variable named $str1<br>from flash memory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Example:\n    $str1=\"\";\n    $str2=\"\";\n    $str1=\"VAR1\";\n    strget($str1, $str2);\n\n    $str2 will now equal \"3.14\" that was previously saved using strsave.<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double strget(stringquote &#8220;\u2026&#8221;, stringvar $str);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function retrieves a string variable named stringquote &#8220;\u2026&#8221;,<br>from flash memory, and places it into $str.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Example:\n    $str=\"\";\n    strget(\"VAR1\", $str);\n\n    $str will now equal \"3.14\" that was previously saved using strsave.<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double strtof(stringvar $str);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function will take the string variable $str and return its value as a double.<br>Example:<br>$str=&#8221;&#8221;;<br>value=0;<br>$str=&#8221;3.14&#8243;;<br>value=strtof($str);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    The double variable will now be equal to 3.14 .<\/code><\/pre>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar encrypt_decrypt(double encrypt_decrypt, stringvar $text);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function encrypts\/decrypts the text found in $text. It uses the key<br>contained in the config.sys file. The encryption type is AES 256 bits.<\/p>\n\n\n\n<p>Set encrypt_decrypt to 0 to encrypt the<br>text and 1 to decrypt the text. A maximun of 112 characters of text can<br>can be encrypted.<\/p>\n\n\n\n<p>Example:<br>[KEY][0123456789ABCDEF0123456789ABCDEF]<\/p>\n\n\n\n<p>Note: This key must be exactly 32 bytes long.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p><strong><em>Date And Time Functions<\/em><\/strong><\/p>\n\n\n\n<p>These functions are defined to work with most any NTP Time Server.<br>The below values must be added to the config.txt file and this file<br>must be uploaded to module before using these functions.<br>Do a module reset after uploading.<\/p>\n\n\n\n<p>Add To config.txt:<br>[TIMESERVER][pool.ntp.org]<br>[TIMEZONE][EST5EDT,M3.2.0\/2,M11.1.0]<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_month(double reserved);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the current month.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_day(double reserved);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the current day.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_year(double reserved);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the current year.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_hour(double reserved);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the current hour.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_minute(double reserved);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the current minute.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_second(double reserved);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the current minute.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar get_date_str();<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns a properly formatted string, for text to speech, of the current date.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar get_time_str();<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns a properly formatted string, for text to speech, of the current time.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar get_dow_str();<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns a properly formatted string, for text to speech, of the current weekday.<\/p>\n\n\n\n<p><strong><em>Misc.<\/em><\/strong><\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>call function(stringvar $str);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This routine calls the function with the name that is stored in $str. A function<br>is simply a text file with extension .c . This text file must contain code and<br>a return statement. Functions are uploaded, to your device, using most any browser.<br>If main.c or any function.c file calls a function it must exist on your devices drive.<br>config.txt .<\/p>\n\n\n\n<p>Example:<br>$str=&#8221;&#8221;;<br>$str=&#8221;sayDateTime&#8221;;<br>call function($str);<\/p>\n\n\n\n<p>This example will run the code that is in the sayDateTime.c file. It will return to the calling<br>code when it encounters a &#8216;return;&#8217; statement.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>call function(stringquote &#8220;\u2026&#8221;);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This routine calls the function with the name you provide in quotes. A function<br>is simply a text file with extension &#8216;.c&#8217;. This text file must contain code and<br>a return statement. Functions are uploaded, to your device, using most any browser.<br>If &#8216;main.c&#8217; or any &#8216;somefunction.c&#8217; file calls a function it must exist on your devices drive.<br>config.txt.<\/p>\n\n\n\n<p>Example:<br>call function(&#8220;sayDateTime&#8221;);<\/p>\n\n\n\n<p>This example will run the code that is in the sayDateTime.c file. It will return to the calling<br>code when it encounters a &#8216;return;&#8217; statement.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>return;<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This statement returns from a function to the code that called it. This statement should<br>never be used in &#8216;main.c&#8217;.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double os_function(double osfunction);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This functions executes the os funtion osfunction. Currently, the only available<br>funtion has a value of &#8216;0&#8217; and reboots your device.<\/p>\n\n\n\n<p>Example:<br>os_function(0); reboots your device.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double printf(stringquote &#8220;\u2026&#8221;);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function prints the quoted string and crlf on the console output. The console<br>output is the USB serial port connected to UART0. The printf function is most commonly used<br>to help in debugging your application.<\/p>\n\n\n\n<p>Example:<br>printf(&#8220;Hello World!!!&#8221;);<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double printf(stringvar $str);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function prints the string, contained in $str, and crlf on the console output. The console<br>output is the USB serial port connected to UART0. The printf function is most commonly used<br>to help in debugging your application.<\/p>\n\n\n\n<p>Example:<br>$str=&#8221;&#8221;;<br>$str=&#8221;Hello World!!!&#8221;;<br>printf($str);<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_ticks(double units);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This functions returns the time since the processor started.<br>Units can be &#8216;0&#8217;, &#8216;1&#8217;, &#8216;2&#8217;, &#8216;3&#8217;.<\/p>\n\n\n\n<p>&#8216;0&#8217; returns seconds<br>&#8216;1&#8217; returns milliseconds<br>&#8216;2&#8217; returns microseconds<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double wait(double milliseconds);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function suspends your app for for the milliseconds you provide.<br>This function is useful for timed events and allowing internal background tasks<br>to do their processing. A wait of 10 milliseconds is required in the main loop<br>to prevent watchdog timeout.<\/p>\n\n\n\n<p>Example:<br>wait(1000); \/\/ waits 1 second.<\/p>\n\n\n\n<p><strong><em>ADC Functions<\/em><\/strong><\/p>\n\n\n\n<p>ADC functions are used to convert analog values to digital values<br>that your program can use.On boot, GPIO1, GPIO2, GPIO3, GPIO4<br>are configured as ADC0_0, ADC_1, ADC_2, ADC_3 respectively.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double read_raw_adc(double adcNumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the raw analog value of adcNumber. adcNumber can be<br>0, 1, 2, or 3. This number is in the range of 0 to 4095.<br>0 is 0 volts and 4095 is 3.3 volts. You can find<br>the voltage with the formula volts=(analog value)\/4095.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double read_cal_adc(double adcNumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>Returns the calibrated analog value of adcNumber. adcNumber can be<br>0, 1, 2, or 3. This number is in the range of 0 to 3300 millivolts.<br>0 is 0 volts and 3300 is 3.3 volts. You can find<br>the voltage with the formula volts=(analog value)\/1000.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p><strong><em>Input And Output<\/em><\/strong><\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double make_output(double GPIONumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function sets the provided GPIONumber to an output. You can<br>set the output with set_high(GPIONumber) and set_low(GPIONumber);<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double make_input(double GPIONumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function sets the provided GPIONumber to an input. You can<br>get the input with get_input(GPIONumber).<br>It will return a 0 or a 1.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double set_pullup(double GPIONumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function connects the internal pull up resistor to high or<br>3.3 volts. The get_input(GPIONumber) will return a 1 if<br>left floating or when connected to 3.3 volts.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double set_pulldown(double GPIONumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function connects the internal pull down resistor to low or<br>0 volts. The get_input(GPIONumber) will return a 0 if<br>left floating or when connected to ground.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_input(double GPIONumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function gets the logic level of the provided GPIONumber.<br>It will return either a 0 for 0 volts or a 1 for 3.3 volts.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double set_high(double GPIONumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function sets the logic level of the provided GPIONumber to<br>1 to output 3.3 volts.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double set_low(double GPIONumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function sets the logic level of the provided GPIONumber to<br>0 to output 0 volts.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br><\/p>\n\n\n\n<p><strong><em>MQTT Functions<\/em><\/strong><\/p>\n\n\n\n<p>These functions are for communicating to and from a MQTT server.<br>MQTT stands for Message Queuing Telemetry Transport. A variety of<br>useful information is available on the Internet.<\/p>\n\n\n\n<p>The below values must be added to the config.txt file and this file<br>must be uploaded to module before using these functions. The values<br>you provide are the parameters of the MQTT server to connect to on<br>startup. Do a module reset after uploading. Your device will connect<br>to and maintain a connection with the server upon device reset or<br>power up.<\/p>\n\n\n\n<p>[MQTT_URI][mqtt:\/\/192.168.1.130:1883] this value sets the URI of the server<br>[MQTT_USERNAME][myusername] this value sets the server&#8217;s username<br>[MQTT_PASSWORD][mypassword] this value sets the server&#8217;s password<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>stringvar mqtt_get_message();<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function gets any messages that came from the server for<br>the topics you have subscribed to. The messages contain 4 fields in square bracketed<br>delimited format. The fields are:<\/p>\n\n\n\n<p>[command][message id][topic][payload]<\/p>\n\n\n\n<p>You can parse these fields using the get_nth_field function.<\/p>\n\n\n\n<p>The possible received commands are:<\/p>\n\n\n\n<p>&#8220;DATA&#8221; &#8211; data was received that was published from a remote client<br>&#8220;CONNECT&#8221; &#8211; your device has successfully connected to the server<br>&#8220;DISCONNECT&#8221; &#8211; your device has disconnected from the server<br>&#8220;SUBSCRIBED&#8221; &#8211; your device has successfully subscribed to a topic<br>&#8220;UNSUBSCRIBED&#8221; &#8211; your device has successfully unsubscribed from a topic<br>&#8220;PUBLISHED&#8221; &#8211; your device has successfully published a data payload to a topic<br>&#8220;ERROR&#8221; &#8211; an error has occurred<\/p>\n\n\n\n<p>Depending on the command, all the 4 received fields may not be populated.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double mqtt_subscribe(stringvar $topic);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function subscribes to the provided $topic. Any messages,<br>from remote clients that publish to that topic, will be received<br>by your device when mqtt_get_message is called.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double mqtt_unsubscribe(stringvar $topic);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function unsubscribes to the provided $topic. Any messages,<br>from remote clients that publish to that topic, will NOT be received,<br>by your device, when mqtt_get_message is called.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double mqtt_publish(stringvar $topic, stringvar $payload);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function posts the data provided in $payload to the provided $topic.<br>Any remote clients, that are subscribed to that topic, will<br>receive this payload.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p><strong><em>LED Strip:<\/em><\/strong><\/p>\n\n\n\n<p>These functions are defined to work with the WS2812b led strip.<br>The below values must be added to the config.txt file and this file<br>must be uploaded to module before using these functions.<br>Do a module reset after uploading.<\/p>\n\n\n\n<p>Add To config.txt:<br>[STRIP_LED][46] the data pin of the LED(s)<br>[MAX_LEDS][300] number of LEDs connected<\/p>\n\n\n\n<p>This sets the data pin to GPIO46 on a led strip that can have up to 300 leds.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double led_set_color(double ledNumber, double redColor, double greenColor, double blueColor);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function sets the color of a specific LED specified by ledNumber.<br>The ledNumber is from 0 to [MAX_LEDS]-1. The redColor, greenColor,<br>and blueColor are in the range of 0 to 255. The higher the value,<br>the brighter is that color. Be careful not to set these values too high<br>because they can be too bright.<\/p>\n\n\n\n<p>The led_set_color does not actually change the color of all LEDs. You<br>must call led_all_refresh to update all LED(s) to this setting.<\/p>\n\n\n\n<p>Example:<br>A red color with value of 10 appears to be a normal red color.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double led_all_off();<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function turns all LED(s) off. The update<br>will appear instantly across all LEDs.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double led_all_refresh();<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function updates all LEDs previously set with led_set_color. The update<br>will appear instantly across all LEDs.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p><strong><em>Text To Speech<\/em><\/strong><\/p>\n\n\n\n<p>These functions are defined to work with the SYN6988 TTS Module.<br>The below values must be added to the config.txt file and this file<br>must be uploaded to module before using these functions. The values<br>you provide are the GPIO numbers that connect to that pin on the<br>SYN6988. Do a module reset after uploading.<\/p>\n\n\n\n<p>Add To config.txt:<br>[SYN6988_BUSY][10]<br>[SYN6988_RXD][11]<br>[SYN6988_TXD][12]<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double is_speak_busy(double reserved);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the state of the busy pin. This<br>function returns immediately. When text is spoken, it won&#8217;t finish<br>right away. You can determine when its done when this function<br>returns a zero.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double speak(stringquote &#8220;\u2026&#8221;);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function speaks the provided quoted string. You can determine,<br>when it is done by calling the is_speak_busy function.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double speak(stringvar $text);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function speaks the provided string variable $text. You can determine,<br>when it is done by calling the is_speak_busy function.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p><strong><em>Air Quality Monitoring Functions<\/em><\/strong><\/p>\n\n\n\n<p>These functions are defined to work with the PMS5003 Air Quality Sensor.<br>The below values must be added to the config.txt file and this file<br>must be uploaded to module before using these functions. The values<br>you provide are the GPIO numbers that connect to that pin on the<br>PMS5003. Do a module reset after uploading.<\/p>\n\n\n\n<p>Add To config.txt:<br>[PMS5003_RXD][18]<br>[PMS5003_TXD][5]<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_air_quality(double register);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function gets the air quality values from the PMS5003 sensor.<br>There are 12 registers that provide different air quality units.<br>Registers are numbered from 0 to 11.Please refer to the PMS5003<br>datasheet for their definitions.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p><strong><em>Temperature Functions<\/em><\/strong><\/p>\n\n\n\n<p>These functions are defined to work with the DS18b20 Temperature Sensor.<br>The below value, the data pin GPIO, must be added to the config.txt file<br>and this file must be uploaded to module before using these functions.<br>Do a module reset after uploading.<\/p>\n\n\n\n<p>Add To config.txt:<br>[ONEWIRE_BUS][21]<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_temperature(double sensorNumber);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the temperature reading of a DS18b20 sensor. Up<br>to 2 sensors can be connected to the data pin. The sensorNumber is either<br>0 or 1. The temperature returned is in centigrade, You can easily convert<br>to farenheit using the formula of: &#8216;F=(9*C)\/5 +32.0;&#8217;<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p><strong><em>Motion Functions<\/em><\/strong><\/p>\n\n\n\n<p>These functions are defined to work with the RD-03 RF motion sensor.<br>The below values must be added to the config.txt file and this file<br>must be uploaded to module before using these functions. The values<br>you provide are the GPIO numbers that connect to that pin on the<br>RD-03. Do a module reset after uploading.<\/p>\n\n\n\n<p>Add To config.txt:<br>[RD03_TXD][13]<br>[RD03_RXD][14]<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double get_motion(double inches_or_cm);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function returns the distance from the sensor where motion is<br>detected. Providing 0 will return centimeters and 1 will return inches.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br><strong><em>Display Functions<\/em><\/strong><\/p>\n\n\n\n<p><br>These functions are defined to work with the SSD1306 Display.<br>The below values must be added to the config.txt file and this file<br>must be uploaded to module before using these functions.<br>Do a module reset after uploading.<\/p>\n\n\n\n<p>Add To config.txt:<br>[SSD1306_SDA][16]<br>[SSD1306_SCL][17]<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double display_text(stringquote &#8220;\u2026&#8221;);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function will display text on the ssd1306 display. Be sure<br>to use the square display and not the thin rectangular display.<br>With this the first line is typically yellow and the remaining lines<br>are blue.There are 4 lines to the display. A &#8216;~&#8217; character forces<br>the text before the &#8216;~&#8217; to be displayed.<\/p>\n\n\n\n<p>Example:<br>if stringquote is &#8220;Hello~World~&#8221;, the display will show<br>&#8216;Hello&#8217; on the first line and &#8216;World&#8217; on the second.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br>double display_text(stringvar $text);<br>\/<em>==========================================================<\/em>\/<\/p>\n\n\n\n<p>This function will display text on the ssd1306 display. Be sure<br>to use the square display and not the thin rectangular display.<br>With this the first line is typically yellow and the remaining lines<br>are blue.There are 4 lines to the display. A &#8216;~&#8217; character forces<br>the text before the &#8216;~&#8217; to be displayed.<\/p>\n\n\n\n<p>Example:<br>if $text=&#8221;Hello~World~Today~&#8221;, the display will show<br>&#8216;Hello&#8217; on the first line and &#8216;World&#8217; on the second, and<br>&#8216;Today&#8217; on the third.<\/p>\n\n\n\n<p>\/<em>==========================================================<\/em>\/<br><\/p>\n\n\n\n<p>The information provided here by B9X Electronics (&#8216;we,&#8217; &#8216;us,&#8217; or &#8216;our&#8217;), in this document,<br>is for general informational purposes only. All information in this document<br>is provided in good faith, however, we make no representation or warranty of any kind,<br>express or implied, regarding the accuracy, adequacy, validity, reliability, availability,<br>or completeness of any information in this document. Under no circumstance shall we have any liability<br>to you for any loss or damage of any kind incurred as a result of the use of this document<br>or reliance on any information provided in this document.&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>B9X C Language Reference B9X C is a high level language that utilizes pretty much the same syntax as C.This language is case sensitive. You can use this documentation page as a reference for understanding the functions. B9X C operates as, what technically is called, a finite state machine. This is nothing more than a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1282","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=\/wp\/v2\/pages\/1282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1282"}],"version-history":[{"count":24,"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=\/wp\/v2\/pages\/1282\/revisions"}],"predecessor-version":[{"id":1330,"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=\/wp\/v2\/pages\/1282\/revisions\/1330"}],"wp:attachment":[{"href":"https:\/\/b9xelectronics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}