function eval(code)
Evaluate a string containing JavaScript code
code
The result of evaluating the string
function parseInt(string,radix)
Convert a string representing a number into an integer
string
radix The Radix of the string (optional)
The value of the string
function parseFloat(string)
Convert a string representing a number into an float
string
The value of the string
function bitRead(value,bit)
Get the specified bit from the value. Lowest significance bit is 0
value
bit
See description above
function bitWrite(value,bit,data)
Set the given bit in the value. Lowest significance bit is 0
value
bit
data
No return value (undefined)
function bitSet(value,bit)
Write the specified bit from the value. Lowest significance bit is 0
value
bit
No return value (undefined)
function bitClear(value,bit)
Clear the given bit in the value. Lowest significance bit is 0
value
bit
No return value (undefined)
function bit(bit)
Get the value of the specified bit (0->1, 1->2, 2->4, 3->8 etc). Lowest significance bit is 0
bit
See description above
function highByte(value)
Return the high (second) byte of the value
value
See description above
function lowByte(value)
Return the low byte of the value
value
See description above
function setBusyIndicator(pin)
When Espruino is busy, set the pin specified here high. Set this to undefined to disable the feature.
pin
No return value (undefined)
function setSleepIndicator(pin)
When Espruino is asleep, set the pin specified here high. Set this to undefined to disable the feature.
pin
No return value (undefined)
function trace()
Output debugging information
No parameters
No return value (undefined)
function dotty()
Output dotty-format graph of debugging information
No parameters
No return value (undefined)
function dump()
Output current interpreter state such that it can be copied to a new device
No parameters
No return value (undefined)
function load()
Load program memory out of flash
No parameters
No return value (undefined)
function save()
Save program memory into flash
No parameters
No return value (undefined)
function reset()
Reset everything - clear program memory
No parameters
No return value (undefined)
function print(text)
Print the supplied string
text
No return value (undefined)
function memory()
Return an object containing information on memory usage at the start of the call
No parameters
Information about memory usage
function edit(funcName)
Fill the console with the contents of the given function, so you can edit it.
funcName The name of the function to edit (either a string or just the unquoted name)
No return value (undefined)
function echo(echoOn)
Should TinyJS echo what you type back to you? true = yes (Default), false = no. When echo is off, the result of executing a command is not returned. Instead, you must use 'print' to send output.
echoOn
No return value (undefined)
function getTime()
Return the current system time in Seconds (as a floating point number)
No parameters
See description above
function register(code)
Call this function with your registration code to register Espruino. Calling the function without a code will display your serial number.
code The registration code. This is an 8 character string made out of the numbers 0-9 and letters A-F
No return value (undefined)
function peek32(addr)
Read 32 bits of memory at the given location - DANGEROUS!
addr The address in memory to read
The value of memory at the given location
function poke32(addr,value)
Write 32 bits of memory at the given location - VERY DANGEROUS!
addr The address in memory to read
value The value to write
No return value (undefined)
function analogRead(pin)
Get the analog value of the given pin
This is different to Arduino which only returns an integer between 0 and 1023
However only pins connected to an ADC will work (see the datasheet)
pin The pin to use
The analog Value of the Pin between 0 and 1
function analogWrite(pin,value,options)
Set the analog Value of a pin. It will be output using PWM
pin The pin to use
value A value between 0 and 1
options An object containing options.
Currently only freq (pulse frequency in Hz) is available: analogWrite(LED1,0.5,{ freq : 10 });
Note that specifying a frequency will force PWM output, even if the pin has a DAC
No return value (undefined)
function digitalPulse(pin,value,time)
Pulse the pin with the value for the given time in milliseconds
eg. pulse(A0,1,500); pulses A0 high for 500ms
pin The pin to use
value Whether to pulse high (true) or low (false)
time A time in milliseconds
No return value (undefined)
function digitalWrite(pin,value)
Set the digital value of the given pin
If pin is an array of pins, eg. [A2,A1,A0] the value will be treated as an integer where the first array element is the MSB
pin The pin to use
value Whether to pulse high (true) or low (false)
No return value (undefined)
function digitalRead(pin)
Get the digital value of the given pin
If pin is an array of pins, eg. [A2,A1,A0] the value will be treated as an integer where the first array element is the MSB
pin The pin to use
The digital Value of the Pin
function setInterval(function,timeout)
Call the function specified REPEATEDLY after the timeout in milliseconds.
The function may also take an argument, which is an object containing a field called 'time', which is the time in seconds at which the timer happened
This can also be removed using clearInterval
function A Function or String to be executed
timeout The time between calls to the function
An ID that can be passed to clearInterval
function setTimeout(function,timeout)
Call the function specified ONCE after the timeout in milliseconds.
The function may also take an argument, which is an object containing a field called 'time', which is the time in seconds at which the timer happened
This can also be removed using clearTimeout
function A Function or String to be executed
timeout The time until the function will be executed
An ID that can be passed to clearTimeout
function setWatch(function,pin,options)
Call the function specified when the pin changes
The function may also take an argument, which is an object containing a field called 'time', which is the time in seconds at which the pin changed state
This can also be removed using clearWatch
function A Function or String to be executed
pin The pin to watch
options If this is a boolean or integer, it determines whether to call this once (false = default) or every time a change occurs (true)
If this is an object, it can contain the following information: { repeat: true/false(default), edge:'rising'/'falling'/'both'(default)}
An ID that can be passed to clearWatch
function clearInterval(id)
Clear the Interval that was created with setInterval, for example:
var id = setInterval(function () { print('foo'); }, 1000);
clearInterval(id);
If no argument is supplied, all timers and intervals are stopped
id The id returned by a previous call to setInterval
No return value (undefined)
function clearTimeout(id)
Clear the Timeout that was created with setTimeout, for example:
var id = setTimeout(function () { print('foo'); }, 1000);
clearTimeout(id);
If no argument is supplied, all timers and intervals are stopped
id The id returned by a previous call to setTimeout
No return value (undefined)
function changeInterval(id,time)
Change the Interval on a callback created with setInterval, for example:
var id = setInterval(function () { print('foo'); }, 1000); <-- every second
changeInterval(id, 1500); <-- now runs every 1.5 seconds
This takes effect the text time the callback is called (so it is not immediate).
id The id returned by a previous call to setInterval
time The new time period in ms
No return value (undefined)
function clearWatch(id)
Clear the Watch that was created with setWatch. If no parameter is supplied, all watches will be removed.
id The id returned by a previous call to setWatch
No return value (undefined)
This is the built-in JavaScript class for arrays.
Arrays can be defined with '[]', 'new Array()', or 'new Array(length)'
function Array.contains(value)
Return true if this array contains the given value
value The value to check for
Whether value is in the array or not
function Array.indexOf(value)
Return the index of the value in the array, or -1
value The value to check for
the index of the value in the array, or undefined
function Array.join(separator)
Join all elements of this array together into one string, using 'separator' between them. eg. [1,2,3].join(' ')=='1 2 3'
separator The separator
A String representing the Joined array
function Array.push(value)
Push a new value onto the end of this array'
value The value to add
The new size of the array
function Array.pop(value)
Pop a new value off of the end of this array
value The value to add
The value that is popped off
function Array.map(function,thisArg)
Return an array which is made from the following: A.map(function) = [function(A[0]), function(A[1]), ...]
function Function used to map one item to another
thisArg if specified, the function is called with 'this' set to thisArg (optional)
The value that is popped off
function Double.doubleToIntBits(x)
Convert the floating point value given into an integer representing the bits contained in it
x A floating point number
The integer representation of x
function Integer.parseInt(x)
Convert a string representing a number into a number
x A string to convert to an Integer
The integer value of x
function Integer.valueOf(character)
Given a string containing a single character, return the numeric value of it
character A string containing a single character
The integer value of char
function JSON.stringify(d)
Convert the given object into a JSON string which can subsequently be parsed with JSON.parse or eval
d t
A JSON string
function JSON.parse(s)
Parse the given JSON string into a JavaScript object
s r
The JavaScript object created by pasring the data string
This class handles interfacing to an LCD screen
It is currently only available on boards that contain a LCD screen, such as the HY 2.8 inch board
function LCD.WIDTH
The width of the LCD
No parameters
The width of the LCD
function LCD.HEIGHT
The height of the LCD
No parameters
The height of the LCD
function LCD.clear(col)
Clear the LCD
col The colour to clear to
No return value (undefined)
function LCD.fillRect(x1,y1,x2,y2,col)
Fill a rectangular area
x1 The left
y1 The top
x2 The right
y2 The bottom
col The colour to fill to
No return value (undefined)
function LCD.drawRect(x1,y1,x2,y2,col)
Draw an unfilled rectangle 1px wide
x1 The left
y1 The top
x2 The right
y2 The bottom
col The colour to fill to
No return value (undefined)
function LCD.getPixel(x,y)
Set a pixel's colour
x The left
y The top
The colour
function LCD.setPixel(x,y,col)
Get a pixel's colour
x The left
y The top
col The colour
No return value (undefined)
function LCD.col(r,g,b)
Colvert into a colour format suitable for the LCD
r Red (between 0 and 1)
g Green (between 0 and 1)
b Blue (between 0 and 1)
The colour
function LCD.drawString(str,x,y,colbg,colfg)
Draw a string
str The string
x The left
y The top
colbg The colour of the background
colfg The colour of the foreground
No return value (undefined)
function LCD.drawVectorString(str,x,y,size,col)
Draw a string
str The string
x The left
y The top
size The height in pixels of the font
col The colour of the foreground
No return value (undefined)
function LCD.drawLine(x1,y1,x2,y2,col)
Draw a line between x1,y1 and x2,y2
x1 The left
y1 The top
x2 The right
y2 The bottom
col The colour to draw with
No return value (undefined)
function LCD.fillPoly(poly,col)
Draw a filled polygon
poly An array of vertices, of the form [x1,y1,x2,y2,x3,y3,etc]
col The colour of the foreground
No return value (undefined)
This is a standard JavaScript class that contains useful Maths routines
function Math.E
No parameters
The value of E - 2.71828182846
function Math.PI
No parameters
The value of PI - 3.14159265359
function Math.abs(x)
x A floating point value
The absolute value of x (eg, Math.abs(2)==2, but also Math.abs(-2)==2)
function Math.acos(x)
x The value to get the arc cosine of
The arc cosine of x, between 0 and PI
function Math.asin(x)
x The value to get the arc sine of
The arc sine of x, between -PI/2 and PI/2
function Math.atan(x)
x The value to get the arc tangent of
The arc tangent of x, between -PI/2 and PI/2
function Math.atan2(y,x)
y The Y-part of the angle to get the arc tangent of
x The X-part of the angle to get the arc tangent of
The arctangent of Y/X, between -PI and PI
function Math.cos(theta)
theta The angle to get the cosine of
The cosine of theta
function Math.pow(x,y)
x The value to raise to the power
y The power x should be raised to
x raised to the power y (x^y)
function Math.random()
No parameters
A random number between 0 and 1
function Math.round(x)
x The value to round
x, rounded to the nearest integer
function Math.sin(theta)
theta The angle to get the sine of
The sine of theta
function Math.sqrt(x)
x The value to take the square root of
The square root of x
function Math.ceil(x)
x The value to round up
x, rounded upwards to the nearest integer
function Math.floor(x)
x The value to round down
x, rounded downwards to the nearest integer
function Math.exp(x)
x The value raise E to the power of
E^x
function Math.log(x)
x The value to take the logarithm (base E) root of
The log (base E) of x
function Object.length()
Find the length of the object
No parameters
The value of the string
function Object.toString()
Convert the Object to a string
No parameters
A String representing the object
function Object.clone()
Copy this object in its Entirity
No parameters
A copy of this Object
This is the built-in class for Pins, such as D0,D1,LED1, or BTN
You can call the methods on Pin, or you can use Wiring-style functions such as digitalWrite
function Pin.read()
Returns the input state of the pin as a boolean
No parameters
Whether pin is a logical 1 or 0
function Pin.set()
Sets the output state of the pin to a 1
No parameters
No return value (undefined)
function Pin.reset()
Sets the output state of the pin to a 0
No parameters
No return value (undefined)
function Pin.write(value)
Sets the output state of the pin to the parameter given
value Whether to set output high (true/1) or low (false/0)
No return value (undefined)
This class allows use of the built-in SPI ports. Currently it is SPI master only.
SPI1
The first SPI port
SPI2
The second SPI port
SPI3
The third SPI port
function SPI.setup(options)
Set up this SPI port
options An optional structure containing extra information on initialising the SPI port
Please note that baud rate is set to the nearest that can be managed - which may be -+ 50%
{sck:pin, miso:pin, mosi:pin, baud:integer}
No return value (undefined)
function SPI.send(data,nss_pin)
Print a string to the serial port - without a line feed
data The data to send - either an integer, array, or string
nss_pin An nSS pin - this will be lowered before SPI output and raised afterwards (optional)
The data that was returned
This class allows use of the built-in USARTs
Methods may be called on the USB, Serial1, Serial2, Serial3, Serial4, Serial5 and Serial6 objects. While different processors provide different numbers of USARTs, you can always rely on at least Serial1 and Serial2
USB
The USB Serial port
Serial1
The first Serial (USART) port
Serial2
The second Serial (USART) port
Serial3
The third Serial (USART) port
Serial4
The fourth Serial (USART) port
Serial5
The fifth Serial (USART) port
Serial6
The sixth Serial (USART) port
function Serial.setConsole()
Set this Serial port as the port for the console
No parameters
No return value (undefined)
function Serial.setup(baudrate,options)
Setup this Serial port with the given baud rate and options
baudrate The baud rate - the default is 9600
options An optional structure containing extra information on initialising the serial port
{rx:pin,tx:pin}
No return value (undefined)
function Serial.print(string)
Print a string to the serial port - without a line feed
string A String to print
No return value (undefined)
function Serial.println(string)
Print a line to the serial port (newline character sent are ' ')
string A String to print
No return value (undefined)
function Serial.onData(function)
When a character is received on this serial port, the function supplied to onData gets called.
Only one function can ever be supplied, so calling onData(undefined) will stop any function being called
function A function to call when data arrives. It takes one argument, which is an object with a 'data' field
No return value (undefined)
function String.fromCharCode(code)
Return the character represented by the given character code.
code The character code to create a character from (range 0-255)
The character
function String.charAt(pos)
Return a single character at the given position in the String.
pos The character number in the string. Negative values return characters from end of string (-1 = last char)
The character in the string
function String.charCodeAt(pos)
Return the integer value of a single character at the given position in the String.
Note that this returns 0 not 'NaN' for out of bounds characters
pos The character number in the string. Negative values return characters from end of string (-1 = last char)
The integer value of a character in the string
function String.indexOf(substring)
Return the index of substring in this string, or -1 if not found
substring The string to search for
The index of the string, or -1 if not found
function String.substring(start,end)
start The start character index
end The end character index
The part of this string between start and end
function String.substr(start,len)
start The start character index
len The number of characters
Part of this string from start for len characters
function String.split(separator)
Return an array made by splitting this string up by the separator. eg. '1,2,3'.split(',')==[1,2,3]
separator The start character index
Part of this string from start for len characters
function console.log(text)
Print the supplied string
text
No return value (undefined)
This class handles interfacing with a FAT32 filesystem on an SD card
It is currently only available on boards that contain an SD card slot, such as the Olimexino
function fs.list(path)
List all files in the supplied directory
path The path of the directory to list. If it is not supplied, '' is assumed, which will list the root directory
An array of filename strings
function fs.filewrite(path,data)
Write the data to the given file
path The path of the file to write
data The data to write to the file
No return value (undefined)
function fs.fileread(path)
Read all data from a file and return as a string
path The path of the file to read
A string containing the contents of the file
This class allows you to create http servers and make http requests
This is a cut-down version of node.js's library
Please see http://nodemanual.org/latest/nodejs_ref_guide/http.html
NOTE: The HTTP client + server send in ~8 byte chunks. This is normally fine but big servers - eg. Google will reject requests made like this (DDoS protection?)
function http.createServer(callback)
Create an HTTP Server
callback A function(req,res) that will be called when a connection is made
Returns a new httpSrv object
function http.request(options,callback)
Create an HTTP Request - end() must be called on it to complete the operation
options An object containing host,port,path,method fields
callback A function(res) that will be called when a connection is made
Returns a new httpCRq object
function http.get(options,callback)
Create an HTTP Request - convenience function for http.request(). options.method is set to get(), and end is called automatically
options An object containing host,port,path,method fields
callback A function(res) that will be called when a connection is made
Returns a new httpCRq object
The HTTP client request
function httpCRq.end(data)
data A string containing data to send
No return value (undefined)
function httpCRq.end(data)
data A string containing data to send
No return value (undefined)
function httpCRs.on(event,callback)
event The event name to respond to. Current only 'data' is supported
callback A callback function
No return value (undefined)
The HTTP server response
function httpSRs.write(data)
data A string containing data to send
No return value (undefined)
function httpSRs.end(data)
data A string containing data to send
No return value (undefined)
function httpSRs.writeHead(statusCode,headers)
statusCode The HTTP status code
headers An object containing the headers
No return value (undefined)
The HTTP server created by http.createServer
function httpSrv.listen(port)
port The port to listen on
No return value (undefined)
This class helps to convert URLs into Objects of information ready for http.request/get
function url.parse(urlStr)
urlStr A URL to be parsed
An object containing options for http.request or http.get