# Espruino Software Reference

Version 1v49

## Contents

### Global Functions

- function NaN()
- function analogRead(pin)
- function analogWrite(pin,value,options)
- function arguments()
- function changeInterval(id,time)
- function clearInterval(id)
- function clearTimeout(id)
- function clearWatch(id)
- function digitalPulse(pin,value,time)
- function digitalRead(pin)
- function digitalWrite(pin,value)
- function dump()
- function echo(echoOn)
- function edit(funcName)
- function eval(code)
- function getSerial()
- function getTime()
- function isNaN(x)
- function load()
- function parseFloat(string)
- function parseInt(string,radix)
- function peek16(addr)
- function peek32(addr)
- function peek8(addr)
- function pinMode(pin,mode)
- function poke16(addr,value)
- function poke32(addr,value)
- function poke8(addr,value)
- function print(text,...)
- function require(moduleName)
- function reset()
- function save()
- function setBusyIndicator(pin)
- function setDeepSleep(sleep)
- function setInterval(function,timeout)
- function setSleepIndicator(pin)
- function setTimeout(function,timeout)
- function setWatch(function,pin,options)
- function trace(root)

### Array

- constructor Array(args,...)
- function Array.forEach(function,thisArg)
- function Array.indexOf(value)
- function Array.isArray(var)
- function Array.join(separator)
- function Array.map(function,thisArg)
- function Array.pop()
- function Array.push(arguments,...)
- function Array.slice(start,end)
- function Array.splice(index,howMany,element1,element2,element3,element4,element5,element6)

### ArrayBuffer

- constructor ArrayBuffer(byteLength)

### ArrayBufferView

- function ArrayBufferView.buffer
- function ArrayBufferView.byteLength
- function ArrayBufferView.byteOffset
- function ArrayBufferView.interpolate(index)
- function ArrayBufferView.interpolate2d(width,x,y)

### CC3000

- function CC3000.connect()

### Double

- function Double.doubleToIntBits(x)

### E

- function E.clip(x,min,max)

### Float32Array

- constructor Float32Array(arr,byteOffset,length)

### Float64Array

- constructor Float64Array(arr,byteOffset,length)

### Function

- function Function.apply(this,args)
- function Function.call(this,a,b,c,d)
- function Function.replaceWith(newFunc)

### Graphics

- function Graphics.clear()
- function Graphics.createArrayBuffer(width,height,bpp,options)
- function Graphics.createCallback(width,height,bpp,callback)
- function Graphics.drawLine(x1,y1,x2,y2)
- function Graphics.drawRect(x1,y1,x2,y2)
- function Graphics.drawString(str,x,y)
- function Graphics.fillPoly(poly)
- function Graphics.fillRect(x1,y1,x2,y2)
- function Graphics.getHeight()
- function Graphics.getPixel(x,y)
- function Graphics.getWidth()
- function Graphics.lineTo(x,y)
- function Graphics.moveTo(x,y)
- function Graphics.setBgColor(r,g,b)
- function Graphics.setColor(r,g,b)
- function Graphics.setFontBitmap()
- function Graphics.setFontVector(size)
- function Graphics.setPixel(x,y,col)
- function Graphics.stringWidth(str)

### Hardware

### I2C

- function I2C.readFrom(address,quantity)
- function I2C.setup(options)
- function I2C.writeTo(address,data)

### Int16Array

- constructor Int16Array(arr,byteOffset,length)

### Int32Array

- constructor Int32Array(arr,byteOffset,length)

### Int8Array

- constructor Int8Array(arr,byteOffset,length)

### Integer

- function Integer.valueOf(character)

### JSON

- function JSON.parse(string)
- function JSON.stringify(data)

### Math

- function Math.E
- function Math.PI
- function Math.abs(x)
- function Math.acos(x)
- function Math.asin(x)
- function Math.atan(x)
- function Math.atan2(y,x)
- function Math.ceil(x)
- function Math.clip(x,min,max)
- function Math.cos(theta)
- function Math.exp(x)
- function Math.floor(x)
- function Math.log(x)
- function Math.pow(x,y)
- function Math.random()
- function Math.round(x)
- function Math.sin(theta)
- function Math.sqrt(x)
- function Math.wrap(x,max)

### Modules

- function Modules.addCached(id,sourcecode)
- function Modules.getCached()
- function Modules.removeAllCached()
- function Modules.removeCached(id)

### Number

- function Number.MAX_VALUE
- function Number.MIN_VALUE
- function Number.NEGATIVE_INFINITY
- function Number.POSITIVE_INFINITY

### Object

- function Object.clone()
- function Object.emit(event,v1,v2)
- function Object.keys(object)
- function Object.length
- function Object.on(event,listener)
- function Object.removeAllListeners(event)
- function Object.toString(radix)

### OneWire

- constructor OneWire(pin)
- function OneWire.read()
- function OneWire.reset()
- function OneWire.search()
- function OneWire.select(rom)
- function OneWire.skip()
- function OneWire.write(data,power)

### Pin

- function Pin.read()
- function Pin.reset()
- function Pin.set()
- function Pin.write(value)
- function Pin.writeAtTime(value,time)

### SPI

- function SPI.send(data,nss_pin)
- function SPI.send4bit(data,bit0,bit1,nss_pin)
- function SPI.send8bit(data,bit0,bit1,nss_pin)
- function SPI.setup(options)

### Serial

- function Serial.onData(function)
- function Serial.print(string)
- function Serial.println(string)
- function Serial.setConsole()
- function Serial.setup(baudrate,options)
- function Serial.write(data)

### String

- constructor String(str)
- function String.charAt(pos)
- function String.charCodeAt(pos)
- function String.fromCharCode(code)
- function String.indexOf(substring)
- function String.split(separator)
- function String.substr(start,len)
- function String.substring(start,end)

### Trig

- function Trig.getErrorArray()
- function Trig.getErrors()
- function Trig.getPosAtTime(time)
- function Trig.getRPM()
- function Trig.getTrigger(num)
- function Trig.killTrigger(num)
- function Trig.setTrigger(num,pos,pins,pulseLength)
- function Trig.setup(pin,options)

### Uint16Array

- constructor Uint16Array(arr,byteOffset,length)

### Uint32Array

- constructor Uint32Array(arr,byteOffset,length)

### Uint8Array

- constructor Uint8Array(arr,byteOffset,length)

### WLAN

- function WLAN.connect(ap,key,callback)
- function WLAN.disconnect()
- function WLAN.getIP()

### console

- function console.log(text,...)

### fs

- function fs.appendFile(path,data)
- function fs.appendFileSync(path,data)
- function fs.readFile(path)
- function fs.readFileSync(path)
- function fs.readdir(path)
- function fs.readdirSync(path)
- function fs.writeFile(path,data)
- function fs.writeFileSync(path,data)

### http

- function http.createServer(callback)
- function http.get(options,callback)
- function http.request(options,callback)

### httpCRq

- function httpCRq.end(data)
- function httpCRq.write(data)

### httpSRq

### httpSRs

- function httpSRs.end(data)
- function httpSRs.write(data)
- function httpSRs.writeHead(statusCode,headers)

### httpSrv

- function httpSrv.listen(port)

### process

- function process.env
- function process.memory()
- function process.version

### url

- function url.parse(urlStr,parseQuery)

## Detail

## Global Functions

(top)

#### Methods and Fields

- function NaN()
- function analogRead(pin)
- function analogWrite(pin,value,options)
- function arguments()
- function changeInterval(id,time)
- function clearInterval(id)
- function clearTimeout(id)
- function clearWatch(id)
- function digitalPulse(pin,value,time)
- function digitalRead(pin)
- function digitalWrite(pin,value)
- function dump()
- function echo(echoOn)
- function edit(funcName)
- function eval(code)
- function getSerial()
- function getTime()
- function isNaN(x)
- function load()
- function parseFloat(string)
- function parseInt(string,radix)
- function peek16(addr)
- function peek32(addr)
- function peek8(addr)
- function pinMode(pin,mode)
- function poke16(addr,value)
- function poke32(addr,value)
- function poke8(addr,value)
- function print(text,...)
- function require(moduleName)
- function reset()
- function save()
- function setBusyIndicator(pin)
- function setDeepSleep(sleep)
- function setInterval(function,timeout)
- function setSleepIndicator(pin)
- function setTimeout(function,timeout)
- function setWatch(function,pin,options)
- function trace(root)

### function NaN

(top)

#### Call type:

function NaN()

#### Parameters

No parameters

#### Returns

Not a Number

### function analogRead

(top)

#### Call type:

function analogRead(pin)

#### Description

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)

#### Parameters

pin The pin to use

#### Returns

The analog Value of the Pin between 0 and 1

### function analogWrite

(top)

#### Call type:

function analogWrite(pin,value,options)

#### Description

Set the analog Value of a pin. It will be output using PWM

#### Parameters

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(A0,0.5,{ freq : 10 });`
Note that specifying a frequency will force PWM output, even if the pin has a DAC

#### Returns

No return value (undefined)

### function arguments

(top)

#### Call type:

function arguments()

#### Description

A variable containing the arguments given to the function

#### Parameters

No parameters

#### Returns

An array containing all the arguments given to the function

### function changeInterval

(top)

#### Call type:

function changeInterval(id,time)

#### Description

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).

#### Parameters

id The id returned by a previous call to setInterval

time The new time period in ms

#### Returns

No return value (undefined)

### function clearInterval

(top)

#### Call type:

function clearInterval(id)

#### Description

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

#### Parameters

id The id returned by a previous call to setInterval

#### Returns

No return value (undefined)

### function clearTimeout

(top)

#### Call type:

function clearTimeout(id)

#### Description

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

#### Parameters

id The id returned by a previous call to setTimeout

#### Returns

No return value (undefined)

### function clearWatch

(top)

#### Call type:

function clearWatch(id)

#### Description

Clear the Watch that was created with setWatch. If no parameter is supplied, all watches will be removed.

#### Parameters

id The id returned by a previous call to setWatch

#### Returns

No return value (undefined)

### function digitalPulse

(top)

#### Call type:

function digitalPulse(pin,value,time)

#### Description

Pulse the pin with the value for the given time in milliseconds

eg. `pulse(A0,1,5);` pulses A0 high for 5ms

digitalPulse is for SHORT pulses that need to be very accurate. If you're doing anything over a few milliseconds, use setTimeout instead

#### Parameters

pin The pin to use

value Whether to pulse high (true) or low (false)

time A time in milliseconds

#### Returns

No return value (undefined)

### function digitalRead

(top)

#### Call type:

function digitalRead(pin)

#### Description

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

#### Parameters

pin The pin to use

#### Returns

The digital Value of the Pin

### function digitalWrite

(top)

#### Call type:

function digitalWrite(pin,value)

#### Description

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

#### Parameters

pin The pin to use

value Whether to pulse high (true) or low (false)

#### Returns

No return value (undefined)

### function dump

(top)

#### Call type:

function dump()

#### Description

Output current interpreter state in a text form such that it can be copied to a new device

Note: 'Internal' functions are currently not handled correctly. You will need to recreate these in the onInit function.

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function echo

(top)

#### Call type:

function echo(echoOn)

#### Description

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.

#### Parameters

echoOn

#### Returns

No return value (undefined)

### function edit

(top)

#### Call type:

function edit(funcName)

#### Description

Fill the console with the contents of the given function, so you can edit it.

NOTE: This is a convenience function - it will not edit 'inner functions'. For that, you must edit the 'outer function' and re-execute it.

#### Parameters

funcName The name of the function to edit (either a string or just the unquoted name)

#### Returns

No return value (undefined)

### function eval

(top)

#### Call type:

function eval(code)

#### Description

Evaluate a string containing JavaScript code

#### Parameters

code

#### Returns

The result of evaluating the string

### function getSerial

(top)

#### Call type:

function getSerial()

#### Description

Get the serial number of this board

#### Parameters

No parameters

#### Returns

The board's serial number

### function getTime

(top)

#### Call type:

function getTime()

#### Description

Return the current system time in Seconds (as a floating point number)

#### Parameters

No parameters

#### Returns

See description above

### function isNaN

(top)

#### Call type:

function isNaN(x)

#### Description

Whether the x is NaN (Not a Number) or not

#### Parameters

x

#### Returns

True is the value is NaN, false if not.

### function load

(top)

#### Call type:

function load()

#### Description

Load program memory out of flash

This command only executes when the Interpreter returns to the Idle state - for instance `a=1;load();a=2;` will still leave 'a' as undefined (or what it was set to in the saved program).

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function parseFloat

(top)

#### Call type:

function parseFloat(string)

#### Description

Convert a string representing a number into an float

#### Parameters

string

#### Returns

The value of the string

### function parseInt

(top)

#### Call type:

function parseInt(string,radix)

#### Description

Convert a string representing a number into an integer

#### Parameters

string

radix The Radix of the string (optional)

#### Returns

The integer value of the string (or NaN)

### function peek16

(top)

#### Call type:

function peek16(addr)

#### Description

Read 16 bits of memory at the given location - DANGEROUS!

#### Parameters

addr The address in memory to read

#### Returns

The value of memory at the given location

### function peek32

(top)

#### Call type:

function peek32(addr)

#### Description

Read 32 bits of memory at the given location - DANGEROUS!

#### Parameters

addr The address in memory to read

#### Returns

The value of memory at the given location

### function peek8

(top)

#### Call type:

function peek8(addr)

#### Description

Read 8 bits of memory at the given location - DANGEROUS!

#### Parameters

addr The address in memory to read

#### Returns

The value of memory at the given location

### function pinMode

(top)

#### Call type:

function pinMode(pin,mode)

#### Description

Set the mode of the given pin - note that digitalRead/digitalWrite/etc set this automatically unless pinMode has been called first. If you want digitalRead/etc to set the pin mode automatically after you have called pinMode, simply call it again with no mode argument: `pinMode(pin)`

#### Parameters

pin The pin to use

mode The mode - a string that is either 'input', 'output', 'input_pullup', or 'input_pulldown'. Do not include this argument if you want to revert to automatic pin mode setting.

#### Returns

No return value (undefined)

### function poke16

(top)

#### Call type:

function poke16(addr,value)

#### Description

Write 16 bits of memory at the given location - VERY DANGEROUS!

#### Parameters

addr The address in memory to write

value The value to write

#### Returns

No return value (undefined)

### function poke32

(top)

#### Call type:

function poke32(addr,value)

#### Description

Write 32 bits of memory at the given location - VERY DANGEROUS!

#### Parameters

addr The address in memory to write

value The value to write

#### Returns

No return value (undefined)

### function poke8

(top)

#### Call type:

function poke8(addr,value)

#### Description

Write 8 bits of memory at the given location - VERY DANGEROUS!

#### Parameters

addr The address in memory to write

value The value to write

#### Returns

No return value (undefined)

### function print

(top)

#### Call type:

function print(text,...)

#### Description

Print the supplied string

#### Parameters

text, ...

#### Returns

No return value (undefined)

### function require

(top)

#### Call type:

function require(moduleName)

#### Description

Load the given module, and return the exported functions

#### Parameters

moduleName A String containing the name of the given module

#### Returns

The result of evaluating the string

### function reset

(top)

#### Call type:

function reset()

#### Description

Reset the interpreter - clear program memory, and do not load a saved program from flash. This does NOT reset the underlying hardware (which allows you to reset the device without it disconnecting from USB).

This command only executes when the Interpreter returns to the Idle state - for instance `a=1;reset();a=2;` will still leave 'a' as undefined.

The safest way to do a full reset is to hit the reset button.

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function save

(top)

#### Call type:

function save()

#### Description

Save program memory into flash. It will then be loaded automatically every time Espruino powers on or is hard-reset.

This command only executes when the Interpreter returns to the Idle state - for instance `a=1;save();a=2;` will save 'a' as 2.

In order to stop the program saved with this command being loaded automatically, hold down Button 1 while also pressing reset. On some boards, Button 1 enters bootloader mode, so you will need to press Reset with Button 1 raised, and then hold Button 1 down a fraction of a second later.

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function setBusyIndicator

(top)

#### Call type:

function setBusyIndicator(pin)

#### Description

When Espruino is busy, set the pin specified here high. Set this to undefined to disable the feature.

#### Parameters

pin

#### Returns

No return value (undefined)

### function setDeepSleep

(top)

#### Call type:

function setDeepSleep(sleep)

#### Description

Set whether we can enter deep sleep mode, which reduces power consumption to around 100uA. This only works on the Espruino Board.

Please see [http://www.espruino.com/Power+Consumption] for more details on this.

#### Parameters

sleep

#### Returns

No return value (undefined)

### function setInterval

(top)

#### Call type:

function setInterval(function,timeout)

#### Description

Call the function specified REPEATEDLY after the timeout in milliseconds.

The function that is being called may also take an argument, which is an object containing a field called 'time' (the time in seconds at which the timer happened)

for example: `setInterval(function (e) { print(e.time); }, 1000);`

This can also be removed using clearInterval

#### Parameters

function A Function or String to be executed

timeout The time between calls to the function

#### Returns

An ID that can be passed to clearInterval

### function setSleepIndicator

(top)

#### Call type:

function setSleepIndicator(pin)

#### Description

When Espruino is asleep, set the pin specified here low (when it's awake, set it high). Set this to undefined to disable the feature.

Please see [http://www.espruino.com/Power+Consumption] for more details on this.

#### Parameters

pin

#### Returns

No return value (undefined)

### function setTimeout

(top)

#### Call type:

function setTimeout(function,timeout)

#### Description

Call the function specified ONCE after the timeout in milliseconds.

The function that is being called may also take an argument, which is an object containing a field called 'time' (the time in seconds at which the timer happened)

for example: `setTimeout(function (e) { print(e.time); }, 1000);`

This can also be removed using clearTimeout

#### Parameters

function A Function or String to be executed

timeout The time until the function will be executed

#### Returns

An ID that can be passed to clearTimeout

### function setWatch

(top)

#### Call type:

function setWatch(function,pin,options)

#### Description

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, and 'state', which is the current state of the pin

This can also be removed using clearWatch

#### Parameters

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)}`

#### Returns

An ID that can be passed to clearWatch

### function trace

(top)

#### Call type:

function trace(root)

#### Description

Output debugging information

#### Parameters

root The symbol to output (optional). If nothing is specified, everything will be output

#### Returns

No return value (undefined)

## Array Class

(top)

This is the built-in JavaScript class for arrays.

Arrays can be defined with `[]`, `new Array()`, or `new Array(length)`

#### Methods and Fields

- constructor Array(args,...)
- function Array.forEach(function,thisArg)
- function Array.indexOf(value)
- function Array.isArray(var)
- function Array.join(separator)
- function Array.map(function,thisArg)
- function Array.pop()
- function Array.push(arguments,...)
- function Array.slice(start,end)
- function Array.splice(index,howMany,element1,element2,element3,element4,element5,element6)

### constructor Array

(top)

#### Call type:

constructor Array(args,...)

#### Description

Create an Array. Either give it one integer argument (>=0) which is the length of the array, or any number of arguments

#### Parameters

args, ... The length of the array OR any number of items to add to the array

#### Returns

An Array

### function Array.forEach

(top)

#### Call type:

function Array.forEach(function,thisArg)

#### Description

Executes a provided function once per array element.

#### Parameters

function Function to be executed

thisArg if specified, the function is called with 'this' set to thisArg (optional)

#### Returns

No return value (undefined)

### function Array.indexOf

(top)

#### Call type:

function Array.indexOf(value)

#### Description

Return the index of the value in the array, or -1

#### Parameters

value The value to check for

#### Returns

the index of the value in the array, or -1

### function Array.isArray

(top)

#### Call type:

function Array.isArray(var)

#### Description

Returns true if the provided object is an array

#### Parameters

var The variable to be tested

#### Returns

True if var is an array, false if not.

### function Array.join

(top)

#### Call type:

function Array.join(separator)

#### Description

Join all elements of this array together into one string, using 'separator' between them. eg. `[1,2,3].join(' ')=='1 2 3'`

#### Parameters

separator The separator

#### Returns

A String representing the Joined array

### function Array.map

(top)

#### Call type:

function Array.map(function,thisArg)

#### Description

Return an array which is made from the following: `A.map(function) = [function(A[0]), function(A[1]), ...]`

#### Parameters

function Function used to map one item to another

thisArg if specified, the function is called with 'this' set to thisArg (optional)

#### Returns

The value that is popped off

### function Array.pop

(top)

#### Call type:

function Array.pop()

#### Description

Pop a new value off of the end of this array

#### Parameters

No parameters

#### Returns

The value that is popped off

### function Array.push

(top)

#### Call type:

function Array.push(arguments,...)

#### Description

Push a new value onto the end of this array'

#### Parameters

arguments, ... One or more arguments to add

#### Returns

The new size of the array

### function Array.slice

(top)

#### Call type:

function Array.slice(start,end)

#### Description

Return a copy of a portion of the calling array

#### Parameters

start Start index

end End index (optional)

#### Returns

A new array

### function Array.splice

(top)

#### Call type:

function Array.splice(index,howMany,element1,element2,element3,element4,element5,element6)

#### Description

Both remove and add items to an array

#### Parameters

index Index at which to start changing the array. If negative, will begin that many elements from the end

howMany An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed.

element1 A new item to add (optional)

element2 A new item to add (optional)

element3 A new item to add (optional)

element4 A new item to add (optional)

element5 A new item to add (optional)

element6 A new item to add (optional)

#### Returns

An array containing the removed elements. If only one element is removed, an array of one element is returned.

## ArrayBuffer Class

(top)

This is the built-in JavaScript class for array buffers.

#### Methods and Fields

- constructor ArrayBuffer(byteLength)

### constructor ArrayBuffer

(top)

#### Call type:

constructor ArrayBuffer(byteLength)

#### Description

Create an Array Buffer object

#### Parameters

byteLength The length in Bytes

#### Returns

An ArrayBuffer object

## ArrayBufferView Class

(top)

This is the built-in JavaScript class that is the prototype for Uint8Array / Float32Array / etc

#### Methods and Fields

- function ArrayBufferView.buffer
- function ArrayBufferView.byteLength
- function ArrayBufferView.byteOffset
- function ArrayBufferView.interpolate(index)
- function ArrayBufferView.interpolate2d(width,x,y)

### function ArrayBufferView.buffer

(top)

#### Call type:

function ArrayBufferView.buffer

#### Description

The buffer this view references

#### Parameters

No parameters

#### Returns

An ArrayBuffer object

### function ArrayBufferView.byteLength

(top)

#### Call type:

function ArrayBufferView.byteLength

#### Description

The length, in bytes, of the view

#### Parameters

No parameters

#### Returns

The Length

### function ArrayBufferView.byteOffset

(top)

#### Call type:

function ArrayBufferView.byteOffset

#### Description

The offset, in bytes, to the first byte of the view within the ArrayBuffer

#### Parameters

No parameters

#### Returns

The byte Offset

### function ArrayBufferView.interpolate

(top)

#### Call type:

function ArrayBufferView.interpolate(index)

#### Description

Interpolate between two adjacent values in the Typed Array

#### Parameters

index Floating point index to access

#### Returns

The result of interpolating between (int)index and (int)(index+1)

### function ArrayBufferView.interpolate2d

(top)

#### Call type:

function ArrayBufferView.interpolate2d(width,x,y)

#### Description

Interpolate between two adjacent values in the Typed Array

#### Parameters

width Integer 'width' of 2d array

x Floating point X index to access

y Floating point Y index to access

#### Returns

The result of interpolating in 2d between the 4 surrounding cells

## CC3000 Class

(top)

#### Methods and Fields

- function CC3000.connect()

### function CC3000.connect

(top)

#### Call type:

function CC3000.connect()

#### Description

Initialise the CC3000 and return a WLAN object

#### Parameters

#### Returns

A WLAN Object

## Double Class

(top)

This is the built-in class for Floating Point values

#### Methods and Fields

- function Double.doubleToIntBits(x)

### function Double.doubleToIntBits

(top)

#### Call type:

function Double.doubleToIntBits(x)

#### Description

Convert the floating point value given into an integer representing the bits contained in it

#### Parameters

x A floating point number

#### Returns

The integer representation of x

## E Class

(top)

This is the built-in JavaScript class for Espruino utility functions.

#### Methods and Fields

- function E.clip(x,min,max)

### function E.clip

(top)

#### Call type:

function E.clip(x,min,max)

#### Description

Clip a number to be between min and max (inclusive)

#### Parameters

x A floating point value to clip

min The smallest the value should be

max The largest the value should be

#### Returns

The value of x, clipped so as not to be below min or above max.

## Float32Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Float32Array(arr,byteOffset,length)

### constructor Float32Array

(top)

#### Call type:

constructor Float32Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## Float64Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Float64Array(arr,byteOffset,length)

### constructor Float64Array

(top)

#### Call type:

constructor Float64Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## Function Class

(top)

This is the built-in class for Functions

#### Methods and Fields

- function Function.apply(this,args)
- function Function.call(this,a,b,c,d)
- function Function.replaceWith(newFunc)

### function Function.apply

(top)

#### Call type:

function Function.apply(this,args)

#### Description

This executes the function with the supplied 'this' argument and parameters

#### Parameters

this The value to use as the 'this' argument when executing the function

args Optional Array of Aruments

#### Returns

The return value of executing this function

### function Function.call

(top)

#### Call type:

function Function.call(this,a,b,c,d)

#### Description

This executes the function with the supplied 'this' argument and parameters

#### Parameters

this The value to use as the 'this' argument when executing the function

a Optional Parameter 1

b Optional Parameter 2

c Optional Parameter 3

d Optional Parameter 4

#### Returns

The return value of executing this function

### function Function.replaceWith

(top)

#### Call type:

function Function.replaceWith(newFunc)

#### Description

This replaces the function with the one in the argument - while keeping the old function's scope. This allows inner functions to be edited, and is used when edit() is called on an inner function.

#### Parameters

newFunc The new function to replace this function with

#### Returns

No return value (undefined)

## Graphics Class

(top)

This class provides Graphics operations that can be applied to a surface.

Use Graphics.createXXX to create a graphics object that renders in the way you want.

NOTE: On boards that contain an LCD, there is a built-in 'LCD' object of type Graphics. For instance to draw a line you'd type: `LCD.drawLine(0,0,100,100)`

#### Methods and Fields

- function Graphics.clear()
- function Graphics.createArrayBuffer(width,height,bpp,options)
- function Graphics.createCallback(width,height,bpp,callback)
- function Graphics.drawLine(x1,y1,x2,y2)
- function Graphics.drawRect(x1,y1,x2,y2)
- function Graphics.drawString(str,x,y)
- function Graphics.fillPoly(poly)
- function Graphics.fillRect(x1,y1,x2,y2)
- function Graphics.getHeight()
- function Graphics.getPixel(x,y)
- function Graphics.getWidth()
- function Graphics.lineTo(x,y)
- function Graphics.moveTo(x,y)
- function Graphics.setBgColor(r,g,b)
- function Graphics.setColor(r,g,b)
- function Graphics.setFontBitmap()
- function Graphics.setFontVector(size)
- function Graphics.setPixel(x,y,col)
- function Graphics.stringWidth(str)

### function Graphics.clear

(top)

#### Call type:

function Graphics.clear()

#### Description

Clear the LCD with the Background Color

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function Graphics.createArrayBuffer

(top)

#### Call type:

function Graphics.createArrayBuffer(width,height,bpp,options)

#### Description

Create a Graphics object that renders to an Array Buffer. This will have a field called 'buffer' that can get used to get at the buffer itself

#### Parameters

width Pixels wide

height Pixels high

bpp Number of bits per pixel

options An object of other options. `{ zigzag : true/false(default), vertical_byte : true/false(default) }`
zigzag = whether to alternate the direction of scanlines for rows
vertical_byte = whether to align bits in a byte vertically or not

#### Returns

The new Graphics object

### function Graphics.createCallback

(top)

#### Call type:

function Graphics.createCallback(width,height,bpp,callback)

#### Description

Create a Graphics object that renders by calling a JavaScript callback function

#### Parameters

width Pixels wide

height Pixels high

bpp Number of bits per pixel

callback A function of the form `function(x,y,col)` that is called whenever a pixel needs to be drawn

#### Returns

The new Graphics object

### function Graphics.drawLine

(top)

#### Call type:

function Graphics.drawLine(x1,y1,x2,y2)

#### Description

Draw a line between x1,y1 and x2,y2 in the current foreground color

#### Parameters

x1 The left

y1 The top

x2 The right

y2 The bottom

#### Returns

No return value (undefined)

### function Graphics.drawRect

(top)

#### Call type:

function Graphics.drawRect(x1,y1,x2,y2)

#### Description

Draw an unfilled rectangle 1px wide in the Foreground Color

#### Parameters

x1 The left

y1 The top

x2 The right

y2 The bottom

#### Returns

No return value (undefined)

### function Graphics.drawString

(top)

#### Call type:

function Graphics.drawString(str,x,y)

#### Description

Draw a string of text in the current font

#### Parameters

str The string

x The left

y The top

#### Returns

No return value (undefined)

### function Graphics.fillPoly

(top)

#### Call type:

function Graphics.fillPoly(poly)

#### Description

Draw a filled polygon in the current foreground color

#### Parameters

poly An array of vertices, of the form `[x1,y1,x2,y2,x3,y3,etc]`

#### Returns

No return value (undefined)

### function Graphics.fillRect

(top)

#### Call type:

function Graphics.fillRect(x1,y1,x2,y2)

#### Description

Fill a rectangular area in the Foreground Color

#### Parameters

x1 The left

y1 The top

x2 The right

y2 The bottom

#### Returns

No return value (undefined)

### function Graphics.getHeight

(top)

#### Call type:

function Graphics.getHeight()

#### Description

The height of the LCD

#### Parameters

No parameters

#### Returns

The height of the LCD

### function Graphics.getPixel

(top)

#### Call type:

function Graphics.getPixel(x,y)

#### Description

Get a pixel's color

#### Parameters

x The left

y The top

#### Returns

The color

### function Graphics.getWidth

(top)

#### Call type:

function Graphics.getWidth()

#### Description

The width of the LCD

#### Parameters

No parameters

#### Returns

The width of the LCD

### function Graphics.lineTo

(top)

#### Call type:

function Graphics.lineTo(x,y)

#### Description

Draw a line from the last position of lineTo or moveTo to this position

#### Parameters

x X value

y Y value

#### Returns

No return value (undefined)

### function Graphics.moveTo

(top)

#### Call type:

function Graphics.moveTo(x,y)

#### Description

Move the cursor to a position - see lineTo

#### Parameters

x X value

y Y value

#### Returns

No return value (undefined)

### function Graphics.setBgColor

(top)

#### Call type:

function Graphics.setBgColor(r,g,b)

#### Description

Set the background color to use for subsequent drawing operations

#### Parameters

r Red (between 0 and 1) OR an integer representing the color in the current bit depth

g Green (between 0 and 1)

b Blue (between 0 and 1)

#### Returns

No return value (undefined)

### function Graphics.setColor

(top)

#### Call type:

function Graphics.setColor(r,g,b)

#### Description

Set the color to use for subsequent drawing operations

#### Parameters

r Red (between 0 and 1) OR an integer representing the color in the current bit depth

g Green (between 0 and 1)

b Blue (between 0 and 1)

#### Returns

No return value (undefined)

### function Graphics.setFontBitmap

(top)

#### Call type:

function Graphics.setFontBitmap()

#### Description

Set Graphics to draw with a Bitmapped Font

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function Graphics.setFontVector

(top)

#### Call type:

function Graphics.setFontVector(size)

#### Description

Set Graphics to draw with a Vector Font of the given size

#### Parameters

size The size as an integer

#### Returns

No return value (undefined)

### function Graphics.setPixel

(top)

#### Call type:

function Graphics.setPixel(x,y,col)

#### Description

Set a pixel's color

#### Parameters

x The left

y The top

col The color

#### Returns

No return value (undefined)

### function Graphics.stringWidth

(top)

#### Call type:

function Graphics.stringWidth(str)

#### Description

Return the size in pixels of a string of text in the current font

#### Parameters

str The string

#### Returns

The length of the string in pixels

## I2C Class

(top)

This class allows use of the built-in I2C ports. Currently it allows I2C Master mode only.

All addresses are in 7 bit format. If you have an 8 bit address then you need to shift it one bit to the right.

#### Instances

- I2C1

  The first I2C port

- I2C2

  The second I2C port

- I2C3

  The third I2C port

#### Methods and Fields

- function I2C.readFrom(address,quantity)
- function I2C.setup(options)
- function I2C.writeTo(address,data)

### function I2C.readFrom

(top)

#### Call type:

function I2C.readFrom(address,quantity)

#### Description

Request bytes from the given slave device, and return them as an array. This is like using Arduino Wire's requestFrom, available and read functions. Sends a STOP

#### Parameters

address The 7 bit address of the device to request bytes from

quantity The number of bytes to request

#### Returns

The data that was returned - an array of bytes

### function I2C.setup

(top)

#### Call type:

function I2C.setup(options)

#### Description

Set up this I2C port

#### Parameters

options An optional structure containing extra information on initialising the I2C port
{scl:pin, sda:pin}

#### Returns

No return value (undefined)

### function I2C.writeTo

(top)

#### Call type:

function I2C.writeTo(address,data)

#### Description

Transmit to the slave device with the given address. This is like Arduino's beginTransmission, write, and endTransmission rolled up into one.

#### Parameters

address The 7 bit address of the device to transmit to

data The Data to send - either a byte, an array of bytes, or a string

#### Returns

No return value (undefined)

## Int16Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Int16Array(arr,byteOffset,length)

### constructor Int16Array

(top)

#### Call type:

constructor Int16Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## Int32Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Int32Array(arr,byteOffset,length)

### constructor Int32Array

(top)

#### Call type:

constructor Int32Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## Int8Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Int8Array(arr,byteOffset,length)

### constructor Int8Array

(top)

#### Call type:

constructor Int8Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## Integer Class

(top)

This is the built-in class for Integer values

#### Methods and Fields

- function Integer.valueOf(character)

### function Integer.valueOf

(top)

#### Call type:

function Integer.valueOf(character)

#### Description

Given a string containing a single character, return the numeric value of it

#### Parameters

character A string containing a single character

#### Returns

The integer value of char

## JSON Class

(top)

#### Methods and Fields

- function JSON.parse(string)
- function JSON.stringify(data)

### function JSON.parse

(top)

#### Call type:

function JSON.parse(string)

#### Description

Parse the given JSON string into a JavaScript object

NOTE: This implementation uses eval() internally, and as such it is unsafe as it can allow arbitrary JS commands to be executed.

#### Parameters

string A JSON string

#### Returns

The JavaScript object created by parsing the data string

### function JSON.stringify

(top)

#### Call type:

function JSON.stringify(data)

#### Description

Convert the given object into a JSON string which can subsequently be parsed with JSON.parse or eval

#### Parameters

data The data to be converted to a JSON string

#### Returns

A JSON string

## Math Class

(top)

This is a standard JavaScript class that contains useful Maths routines

#### Methods and Fields

- function Math.E
- function Math.PI
- function Math.abs(x)
- function Math.acos(x)
- function Math.asin(x)
- function Math.atan(x)
- function Math.atan2(y,x)
- function Math.ceil(x)
- function Math.clip(x,min,max)
- function Math.cos(theta)
- function Math.exp(x)
- function Math.floor(x)
- function Math.log(x)
- function Math.pow(x,y)
- function Math.random()
- function Math.round(x)
- function Math.sin(theta)
- function Math.sqrt(x)
- function Math.wrap(x,max)

### function Math.E

(top)

#### Call type:

function Math.E

#### Parameters

No parameters

#### Returns

The value of E - 2.71828182846

### function Math.PI

(top)

#### Call type:

function Math.PI

#### Parameters

No parameters

#### Returns

The value of PI - 3.14159265359

### function Math.abs

(top)

#### Call type:

function Math.abs(x)

#### Parameters

x A floating point value

#### Returns

The absolute value of x (eg, `Math.abs(2)==2`, but also `Math.abs(-2)==2`)

### function Math.acos

(top)

#### Call type:

function Math.acos(x)

#### Parameters

x The value to get the arc cosine of

#### Returns

The arc cosine of x, between 0 and PI

### function Math.asin

(top)

#### Call type:

function Math.asin(x)

#### Parameters

x The value to get the arc sine of

#### Returns

The arc sine of x, between -PI/2 and PI/2

### function Math.atan

(top)

#### Call type:

function Math.atan(x)

#### Parameters

x The value to get the arc tangent of

#### Returns

The arc tangent of x, between -PI/2 and PI/2

### function Math.atan2

(top)

#### Call type:

function Math.atan2(y,x)

#### Parameters

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

#### Returns

The arctangent of Y/X, between -PI and PI

### function Math.ceil

(top)

#### Call type:

function Math.ceil(x)

#### Parameters

x The value to round up

#### Returns

x, rounded upwards to the nearest integer

### function Math.clip

(top)

#### Call type:

function Math.clip(x,min,max)

#### Description

DEPRECATED - Please use `E.clip()` instead. Clip a number to be between min and max (inclusive)

#### Parameters

x A floating point value to clip

min The smallest the value should be

max The largest the value should be

#### Returns

The value of x, clipped so as not to be below min or above max.

### function Math.cos

(top)

#### Call type:

function Math.cos(theta)

#### Parameters

theta The angle to get the cosine of

#### Returns

The cosine of theta

### function Math.exp

(top)

#### Call type:

function Math.exp(x)

#### Parameters

x The value raise E to the power of

#### Returns

E^x

### function Math.floor

(top)

#### Call type:

function Math.floor(x)

#### Parameters

x The value to round down

#### Returns

x, rounded downwards to the nearest integer

### function Math.log

(top)

#### Call type:

function Math.log(x)

#### Parameters

x The value to take the logarithm (base E) root of

#### Returns

The log (base E) of x

### function Math.pow

(top)

#### Call type:

function Math.pow(x,y)

#### Parameters

x The value to raise to the power

y The power x should be raised to

#### Returns

x raised to the power y (x^y)

### function Math.random

(top)

#### Call type:

function Math.random()

#### Parameters

No parameters

#### Returns

A random number between 0 and 1

### function Math.round

(top)

#### Call type:

function Math.round(x)

#### Parameters

x The value to round

#### Returns

x, rounded to the nearest integer

### function Math.sin

(top)

#### Call type:

function Math.sin(theta)

#### Parameters

theta The angle to get the sine of

#### Returns

The sine of theta

### function Math.sqrt

(top)

#### Call type:

function Math.sqrt(x)

#### Parameters

x The value to take the square root of

#### Returns

The square root of x

### function Math.wrap

(top)

#### Call type:

function Math.wrap(x,max)

#### Description

Wrap a number around if it is less than 0 or greater than or equal to max. For instance you might do: `Math.wrap(angleInDegrees, 360)`

#### Parameters

x A floating point value to wrap

max The largest the value should be

#### Returns

The value of x, wrapped so as not to be below min or above max.

## Modules Class

(top)

#### Methods and Fields

- function Modules.addCached(id,sourcecode)
- function Modules.getCached()
- function Modules.removeAllCached()
- function Modules.removeCached(id)

### function Modules.addCached

(top)

#### Call type:

function Modules.addCached(id,sourcecode)

#### Description

Add the given module to the cache

#### Parameters

id The module name to add

sourcecode The module's sourcecode

#### Returns

No return value (undefined)

### function Modules.getCached

(top)

#### Call type:

function Modules.getCached()

#### Description

Return an array of module names that have been cached

#### Parameters

No parameters

#### Returns

An array of module names

### function Modules.removeAllCached

(top)

#### Call type:

function Modules.removeAllCached()

#### Description

Remove all cached modules

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function Modules.removeCached

(top)

#### Call type:

function Modules.removeCached(id)

#### Description

Remove the given module from the list of cached modules

#### Parameters

id The module name to remove

#### Returns

No return value (undefined)

## Number Class

(top)

This is the built-in JavaScript class for numbers.

#### Methods and Fields

- function Number.MAX_VALUE
- function Number.MIN_VALUE
- function Number.NEGATIVE_INFINITY
- function Number.POSITIVE_INFINITY

### function Number.MAX_VALUE

(top)

#### Call type:

function Number.MAX_VALUE

#### Parameters

No parameters

#### Returns

Maximum representable value

### function Number.MIN_VALUE

(top)

#### Call type:

function Number.MIN_VALUE

#### Parameters

No parameters

#### Returns

Smallest representable value

### function Number.NEGATIVE_INFINITY

(top)

#### Call type:

function Number.NEGATIVE_INFINITY

#### Parameters

No parameters

#### Returns

Smallest representable value

### function Number.POSITIVE_INFINITY

(top)

#### Call type:

function Number.POSITIVE_INFINITY

#### Parameters

No parameters

#### Returns

Smallest representable value

## Object Class

(top)

This is the built-in class for Objects

#### Methods and Fields

- function Object.clone()
- function Object.emit(event,v1,v2)
- function Object.keys(object)
- function Object.length
- function Object.on(event,listener)
- function Object.removeAllListeners(event)
- function Object.toString(radix)

### function Object.clone

(top)

#### Call type:

function Object.clone()

#### Description

Copy this object completely

#### Parameters

No parameters

#### Returns

A copy of this Object

### function Object.emit

(top)

#### Call type:

function Object.emit(event,v1,v2)

#### Description

Call the event listeners for this object, for instance `http.emit('data', 'Foo')`. See Node.js's EventEmitter.

#### Parameters

event The name of the event, for instance 'data'

v1 Optional argument 1

v2 Optional argument 2

#### Returns

No return value (undefined)

### function Object.keys

(top)

#### Call type:

function Object.keys(object)

#### Description

Return all enumerable keys of the given object

#### Parameters

object The object to return keys for

#### Returns

An array of strings - one for each key on the given object

### function Object.length

(top)

#### Call type:

function Object.length

#### Description

Find the length of the object

#### Parameters

No parameters

#### Returns

The value of the string

### function Object.on

(top)

#### Call type:

function Object.on(event,listener)

#### Description

Register an event listener for this object, for instance `http.on('data', function(d) {...})`. See Node.js's EventEmitter.

#### Parameters

event The name of the event, for instance 'data'

listener The listener to call when this event is received

#### Returns

No return value (undefined)

### function Object.removeAllListeners

(top)

#### Call type:

function Object.removeAllListeners(event)

#### Description

Removes all listeners, or those of the specified event.

#### Parameters

event The name of the event, for instance 'data'

#### Returns

No return value (undefined)

### function Object.toString

(top)

#### Call type:

function Object.toString(radix)

#### Description

Convert the Object to a string

#### Parameters

radix If the object is an integer, the radix (between 2 and 36) to use. NOTE: Setting a radix does not work on floating point numbers.

#### Returns

A String representing the object

## OneWire Class

(top)

This class provides a software-defined OneWire master. It is designed to be similar to Arduino's OneWire library.

#### Methods and Fields

- constructor OneWire(pin)
- function OneWire.read()
- function OneWire.reset()
- function OneWire.search()
- function OneWire.select(rom)
- function OneWire.skip()
- function OneWire.write(data,power)

### constructor OneWire

(top)

#### Call type:

constructor OneWire(pin)

#### Description

Create a software OneWire implementation on the given pin

#### Parameters

pin The pin to implement OneWire on

#### Returns

A OneWire object

### function OneWire.read

(top)

#### Call type:

function OneWire.read()

#### Description

Read a byte

#### Parameters

No parameters

#### Returns

The byte that was read

### function OneWire.reset

(top)

#### Call type:

function OneWire.reset()

#### Description

Perform a reset cycle

#### Parameters

No parameters

#### Returns

True is a device was present (it held the bus low)

### function OneWire.search

(top)

#### Call type:

function OneWire.search()

#### Description

Search for devices

#### Parameters

No parameters

#### Returns

An array of devices that were found

### function OneWire.select

(top)

#### Call type:

function OneWire.select(rom)

#### Description

Select a ROM - reset needs to be done first

#### Parameters

rom The rom to select

#### Returns

No return value (undefined)

### function OneWire.skip

(top)

#### Call type:

function OneWire.skip()

#### Description

Skip a ROM

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function OneWire.write

(top)

#### Call type:

function OneWire.write(data,power)

#### Description

Write a byte

#### Parameters

data A byte to write

power Whether to leave power on after write (default is false)

#### Returns

No return value (undefined)

## Pin Class

(top)

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

#### Methods and Fields

- function Pin.read()
- function Pin.reset()
- function Pin.set()
- function Pin.write(value)
- function Pin.writeAtTime(value,time)

### function Pin.read

(top)

#### Call type:

function Pin.read()

#### Description

Returns the input state of the pin as a boolean

#### Parameters

No parameters

#### Returns

Whether pin is a logical 1 or 0

### function Pin.reset

(top)

#### Call type:

function Pin.reset()

#### Description

Sets the output state of the pin to a 0

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function Pin.set

(top)

#### Call type:

function Pin.set()

#### Description

Sets the output state of the pin to a 1

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function Pin.write

(top)

#### Call type:

function Pin.write(value)

#### Description

Sets the output state of the pin to the parameter given

#### Parameters

value Whether to set output high (true/1) or low (false/0)

#### Returns

No return value (undefined)

### function Pin.writeAtTime

(top)

#### Call type:

function Pin.writeAtTime(value,time)

#### Description

Sets the output state of the pin to the parameter given at the specified time

#### Parameters

value Whether to set output high (true/1) or low (false/0)

time Time at which to write

#### Returns

No return value (undefined)

## SPI Class

(top)

This class allows use of the built-in SPI ports. Currently it is SPI master only.

#### Instances

- SPI1

  The first SPI port

- SPI2

  The second SPI port

- SPI3

  The third SPI port

#### Methods and Fields

- function SPI.send(data,nss_pin)
- function SPI.send4bit(data,bit0,bit1,nss_pin)
- function SPI.send8bit(data,bit0,bit1,nss_pin)
- function SPI.setup(options)

### function SPI.send

(top)

#### Call type:

function SPI.send(data,nss_pin)

#### Description

Send data down SPI, and return the result

Sending multiple bytes in one call to send is preferable as they can then be transmitted end to end. Using multiple calls to send() will result in significantly slower transmission speeds.

#### Parameters

data The data to send - either an integer, array, or string (which is the most efficient)

nss_pin An nSS pin - this will be lowered before SPI output and raised afterwards (optional). There will be a small delay between when this is lowered and when sending starts, and also between sending finishing and it being raised.

#### Returns

The data that was returned

### function SPI.send4bit

(top)

#### Call type:

function SPI.send4bit(data,bit0,bit1,nss_pin)

#### Description

Send data down SPI, using 4 bits for each 'real' bit (MSB first). This can be useful for faking one-wire style protocols

Sending multiple bytes in one call to send is preferable as they can then be transmitted end to end. Using multiple calls to send() will result in significantly slower transmission speeds.

#### Parameters

data The data to send - either an integer, array, or string

bit0 The 4 bits to send for a 0 (MSB first)

bit1 The 4 bits to send for a 1 (MSB first)

nss_pin An nSS pin - this will be lowered before SPI output and raised afterwards (optional). There will be a small delay between when this is lowered and when sending starts, and also between sending finishing and it being raised.

#### Returns

No return value (undefined)

### function SPI.send8bit

(top)

#### Call type:

function SPI.send8bit(data,bit0,bit1,nss_pin)

#### Description

Send data down SPI, using 8 bits for each 'real' bit (MSB first). This can be useful for faking one-wire style protocols

Sending multiple bytes in one call to send is preferable as they can then be transmitted end to end. Using multiple calls to send() will result in significantly slower transmission speeds.

#### Parameters

data The data to send - either an integer, array, or string

bit0 The 8 bits to send for a 0 (MSB first)

bit1 The 8 bits to send for a 1 (MSB first)

nss_pin An nSS pin - this will be lowered before SPI output and raised afterwards (optional). There will be a small delay between when this is lowered and when sending starts, and also between sending finishing and it being raised

#### Returns

No return value (undefined)

### function SPI.setup

(top)

#### Call type:

function SPI.setup(options)

#### Description

Set up this SPI port. Master, MSB first, no checksum

#### Parameters

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, mode:integer=0 }`
If sck,miso and mosi are left out, they will automatically be chosen. However if one or more is specified then the unspecified pins will not be set up.
The SPI `mode` is between 0 and 3 - see http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Clock_polarity_and_phase
On STM32F1-based parts, you cannot mix AF and non-AF pins (SPI pins are usually grouped on the chip - and you can't mix pins from two groups). Espruino will not warn you about this.

#### Returns

No return value (undefined)

## Serial Class

(top)

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

#### Instances

- 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

- USB

  The USB Serial port

#### Methods and Fields

- function Serial.onData(function)
- function Serial.print(string)
- function Serial.println(string)
- function Serial.setConsole()
- function Serial.setup(baudrate,options)
- function Serial.write(data)

### function Serial.onData

(top)

#### Call type:

function Serial.onData(function)

#### Description

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

#### Parameters

function A function to call when data arrives. It takes one argument, which is an object with a 'data' field

#### Returns

No return value (undefined)

### function Serial.print

(top)

#### Call type:

function Serial.print(string)

#### Description

Print a string to the serial port - without a line feed

#### Parameters

string A String to print

#### Returns

No return value (undefined)

### function Serial.println

(top)

#### Call type:

function Serial.println(string)

#### Description

Print a line to the serial port (newline character sent are ' ')

#### Parameters

string A String to print

#### Returns

No return value (undefined)

### function Serial.setConsole

(top)

#### Call type:

function Serial.setConsole()

#### Description

Set this Serial port as the port for the console

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function Serial.setup

(top)

#### Call type:

function Serial.setup(baudrate,options)

#### Description

Setup this Serial port with the given baud rate and options

#### Parameters

baudrate The baud rate - the default is 9600

options An optional structure containing extra information on initialising the serial port.
`{rx:pin,tx:pin}`
Note that even after changing the RX and TX pins, if you have called setup before then the previous RX and TX pins will still be connected to the Serial port as well - until you set them to something else using digitalWrite

#### Returns

No return value (undefined)

### function Serial.write

(top)

#### Call type:

function Serial.write(data)

#### Description

Write a character or array of characters to the serial port - without a line feed

#### Parameters

data A byte, a string, or an array of bytes to write

#### Returns

No return value (undefined)

## String Class

(top)

This is the built-in class for Text Strings.

Text Strings in Espruino are not zero-terminated, so you can store zeros in them.

#### Methods and Fields

- constructor String(str)
- function String.charAt(pos)
- function String.charCodeAt(pos)
- function String.fromCharCode(code)
- function String.indexOf(substring)
- function String.split(separator)
- function String.substr(start,len)
- function String.substring(start,end)

### constructor String

(top)

#### Call type:

constructor String(str)

#### Description

Create a new String

#### Parameters

str A value to turn into a string. If undefined or not supplied, an empty String is created.

#### Returns

A String

### function String.charAt

(top)

#### Call type:

function String.charAt(pos)

#### Description

Return a single character at the given position in the String.

#### Parameters

pos The character number in the string. Negative values return characters from end of string (-1 = last char)

#### Returns

The character in the string

### function String.charCodeAt

(top)

#### Call type:

function String.charCodeAt(pos)

#### Description

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

#### Parameters

pos The character number in the string. Negative values return characters from end of string (-1 = last char)

#### Returns

The integer value of a character in the string

### function String.fromCharCode

(top)

#### Call type:

function String.fromCharCode(code)

#### Description

Return the character represented by the given character code.

#### Parameters

code The character code to create a character from (range 0-255)

#### Returns

The character

### function String.indexOf

(top)

#### Call type:

function String.indexOf(substring)

#### Description

Return the index of substring in this string, or -1 if not found

#### Parameters

substring The string to search for

#### Returns

The index of the string, or -1 if not found

### function String.split

(top)

#### Call type:

function String.split(separator)

#### Description

Return an array made by splitting this string up by the separator. eg. `'1,2,3'.split(',')==[1,2,3]`

#### Parameters

separator The start character index

#### Returns

Part of this string from start for len characters

### function String.substr

(top)

#### Call type:

function String.substr(start,len)

#### Parameters

start The start character index

len The number of characters

#### Returns

Part of this string from start for len characters

### function String.substring

(top)

#### Call type:

function String.substring(start,end)

#### Parameters

start The start character index

end The end character index

#### Returns

The part of this string between start and end

## Trig Class

(top)

This class exists in order to interface Espruino with fast-moving trigger wheels. Trigger wheels are physical discs with evenly spaced teeth cut into them, and often with one or two teeth next to each other missing. A sensor sends a signal whenever a tooth passed by, and this allows a device to measure not only RPM, but absolute position.

This class is currently in testing - it is NOT AVAILABLE on normal boards.

#### Methods and Fields

- function Trig.getErrorArray()
- function Trig.getErrors()
- function Trig.getPosAtTime(time)
- function Trig.getRPM()
- function Trig.getTrigger(num)
- function Trig.killTrigger(num)
- function Trig.setTrigger(num,pos,pins,pulseLength)
- function Trig.setup(pin,options)

### function Trig.getErrorArray

(top)

#### Call type:

function Trig.getErrorArray()

#### Description

Get the current error flags from the trigger wheel - and zero them

#### Parameters

No parameters

#### Returns

An array of error strings

### function Trig.getErrors

(top)

#### Call type:

function Trig.getErrors()

#### Description

Get the current error flags from the trigger wheel - and zero them

#### Parameters

No parameters

#### Returns

The error flags

### function Trig.getPosAtTime

(top)

#### Call type:

function Trig.getPosAtTime(time)

#### Description

Get the position of the trigger wheel at the given time (from getTime)

#### Parameters

time The time at which to find the position

#### Returns

The position of the trigger wheel in teeth - as a floating point number

### function Trig.getRPM

(top)

#### Call type:

function Trig.getRPM()

#### Description

Get the RPM of the trigger wheel

#### Parameters

No parameters

#### Returns

The current RPM of the trigger wheel

### function Trig.getTrigger

(top)

#### Call type:

function Trig.getTrigger(num)

#### Description

Get the current state of a trigger

#### Parameters

num The trigger number (0..7)

#### Returns

A structure containing all information about the trigger

### function Trig.killTrigger

(top)

#### Call type:

function Trig.killTrigger(num)

#### Description

Disable a trigger

#### Parameters

num The trigger number (0..7)

#### Returns

No return value (undefined)

### function Trig.setTrigger

(top)

#### Call type:

function Trig.setTrigger(num,pos,pins,pulseLength)

#### Description

Set a trigger for a certain point in the cycle

#### Parameters

num The trigger number (0..7)

pos The position (in degrees) to fire the trigger at

pins An array of pins to pulse (max 4)

pulseLength The time (in msec) to pulse for

#### Returns

No return value (undefined)

### function Trig.setup

(top)

#### Call type:

function Trig.setup(pin,options)

#### Description

Initialise the trigger class

#### Parameters

pin The pin to use for triggering

options Additional options as an object. defaults are: `{teethTotal:60,teethMissing:2,minRPM:30,keyPosition:0}`

#### Returns

No return value (undefined)

## Uint16Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Uint16Array(arr,byteOffset,length)

### constructor Uint16Array

(top)

#### Call type:

constructor Uint16Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## Uint32Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Uint32Array(arr,byteOffset,length)

### constructor Uint32Array

(top)

#### Call type:

constructor Uint32Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## Uint8Array Class

(top)

This is the built-in JavaScript class for a typed array.

Instantiate this in order to efficiently store arrays of data (Espruino's normal arrays store data in a map, which is inefficient for non-sparse arrays).

#### Methods and Fields

- constructor Uint8Array(arr,byteOffset,length)

### constructor Uint8Array

(top)

#### Call type:

constructor Uint8Array(arr,byteOffset,length)

#### Description

Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array

#### Parameters

arr The array or typed array to base this off, or an integer which is the array length

byteOffset The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)

length The length (ONLY IF the first argument was an ArrayBuffer)

#### Returns

A typed array

## WLAN Class

(top)

An instantiation of a WiFi network adaptor

#### Methods and Fields

- function WLAN.connect(ap,key,callback)
- function WLAN.disconnect()
- function WLAN.getIP()

### function WLAN.connect

(top)

#### Call type:

function WLAN.connect(ap,key,callback)

#### Description

Connect to a wireless network

#### Parameters

ap Access point name

key WPA2 key (or undefined for unsecured connection)

callback Function to call back with connection status. It has one argument which is one of 'connect'/'disconnect'/'dhcp'

#### Returns

See description above

### function WLAN.disconnect

(top)

#### Call type:

function WLAN.disconnect()

#### Description

Completely uninitialise and power down the CC3000. After this you'll have to use `require("CC3000").connect()` again.

#### Parameters

No parameters

#### Returns

No return value (undefined)

### function WLAN.getIP

(top)

#### Call type:

function WLAN.getIP()

#### Description

Get the current IP address

#### Parameters

No parameters

#### Returns

See description above

## console Class

(top)

#### Methods and Fields

- function console.log(text,...)

### function console.log

(top)

#### Call type:

function console.log(text,...)

#### Description

Print the supplied string(s)

#### Parameters

text, ... One or more arguments to print

#### Returns

No return value (undefined)

## fs Class

(top)

This library handles interfacing with a FAT32 filesystem on an SD card. The API is designed to be similar to node.js's - However Espruino does not currently support asynchronous file IO, so the functions behave like node.js's xxxxSync functions. Versions of the functions with 'Sync' after them are also provided for compatibility.

Currently this provides minimal file IO - it's great for logging and loading/saving settings, but not good for loading large amounts of data as you will soon fill your memory up.

It is currently only available on boards that contain an SD card slot, such as the Olimexino and the HY. It can not currently be added to boards that did not ship with a card slot.

To use this, you must type `var fs = require('fs')` to get access to the library

#### Methods and Fields

- function fs.appendFile(path,data)
- function fs.appendFileSync(path,data)
- function fs.readFile(path)
- function fs.readFileSync(path)
- function fs.readdir(path)
- function fs.readdirSync(path)
- function fs.writeFile(path,data)
- function fs.writeFileSync(path,data)

### function fs.appendFile

(top)

#### Call type:

function fs.appendFile(path,data)

#### Description

Append the data to the given file, created a new file if it doesn't exist

NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.

#### Parameters

path The path of the file to write

data The data to write to the file

#### Returns

No return value (undefined)

### function fs.appendFileSync

(top)

#### Call type:

function fs.appendFileSync(path,data)

#### Description

Append the data to the given file, created a new file if it doesn't exist

#### Parameters

path The path of the file to write

data The data to write to the file

#### Returns

No return value (undefined)

### function fs.readFile

(top)

#### Call type:

function fs.readFile(path)

#### Description

Read all data from a file and return as a string

NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.

#### Parameters

path The path of the file to read

#### Returns

A string containing the contents of the file

### function fs.readFileSync

(top)

#### Call type:

function fs.readFileSync(path)

#### Description

Read all data from a file and return as a string

#### Parameters

path The path of the file to read

#### Returns

A string containing the contents of the file

### function fs.readdir

(top)

#### Call type:

function fs.readdir(path)

#### Description

List all files in the supplied directory, returning them as an array of strings.

NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.

#### Parameters

path The path of the directory to list. If it is not supplied, '' is assumed, which will list the root directory

#### Returns

An array of filename strings

### function fs.readdirSync

(top)

#### Call type:

function fs.readdirSync(path)

#### Description

List all files in the supplied directory, returning them as an array of strings.

#### Parameters

path The path of the directory to list. If it is not supplied, '' is assumed, which will list the root directory

#### Returns

An array of filename strings

### function fs.writeFile

(top)

#### Call type:

function fs.writeFile(path,data)

#### Description

Write the data to the given file

NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.

#### Parameters

path The path of the file to write

data The data to write to the file

#### Returns

No return value (undefined)

### function fs.writeFileSync

(top)

#### Call type:

function fs.writeFileSync(path,data)

#### Description

Write the data to the given file

#### Parameters

path The path of the file to write

data The data to write to the file

#### Returns

No return value (undefined)

## http Class

(top)

This library allows you to create http servers and make http requests

NOTE: This is currently only available in the Raspberry Pi version

This is a cut-down version of node.js's library

Please see http://nodemanual.org/latest/nodejs_ref_guide/http.html

To use this, you must type `var http = require('http')` to get access to the library

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?)

#### Methods and Fields

- function http.createServer(callback)
- function http.get(options,callback)
- function http.request(options,callback)

### function http.createServer

(top)

#### Call type:

function http.createServer(callback)

#### Description

Create an HTTP Server

#### Parameters

callback A function(req,res) that will be called when a connection is made

#### Returns

Returns a new httpSrv object

### function http.get

(top)

#### Call type:

function http.get(options,callback)

#### Description

Create an HTTP Request - convenience function for `http.request()`. options.method is set to 'get', and end is called automatically

#### Parameters

options An object containing host,port,path,method fields

callback A function(res) that will be called when a connection is made

#### Returns

Returns a new httpCRq object

### function http.request

(top)

#### Call type:

function http.request(options,callback)

#### Description

Create an HTTP Request - end() must be called on it to complete the operation

#### Parameters

options An object containing host,port,path,method fields

callback A function(res) that will be called when a connection is made

#### Returns

Returns a new httpCRq object

## httpCRq Class

(top)

The HTTP client request

#### Methods and Fields

- function httpCRq.end(data)
- function httpCRq.write(data)

### function httpCRq.end

(top)

#### Call type:

function httpCRq.end(data)

#### Description

Finish this HTTP request - optional data to append as an argument

#### Parameters

data A string containing data to send

#### Returns

No return value (undefined)

### function httpCRq.write

(top)

#### Call type:

function httpCRq.write(data)

#### Parameters

data A string containing data to send

#### Returns

No return value (undefined)

## httpSRs Class

(top)

The HTTP server response

#### Methods and Fields

- function httpSRs.end(data)
- function httpSRs.write(data)
- function httpSRs.writeHead(statusCode,headers)

### function httpSRs.end

(top)

#### Call type:

function httpSRs.end(data)

#### Parameters

data A string containing data to send

#### Returns

No return value (undefined)

### function httpSRs.write

(top)

#### Call type:

function httpSRs.write(data)

#### Parameters

data A string containing data to send

#### Returns

No return value (undefined)

### function httpSRs.writeHead

(top)

#### Call type:

function httpSRs.writeHead(statusCode,headers)

#### Parameters

statusCode The HTTP status code

headers An object containing the headers

#### Returns

No return value (undefined)

## httpSrv Class

(top)

The HTTP server created by http.createServer

#### Methods and Fields

- function httpSrv.listen(port)

### function httpSrv.listen

(top)

#### Call type:

function httpSrv.listen(port)

#### Parameters

port The port to listen on

#### Returns

No return value (undefined)

## process Class

(top)

This class contains information about Espruino itself

#### Methods and Fields

- function process.env
- function process.memory()
- function process.version

### function process.env

(top)

#### Call type:

function process.env

#### Description

Returns an Object containing various pre-defined variables. standard ones are BOARD, VERSION

#### Parameters

No parameters

#### Returns

An object

### function process.memory

(top)

#### Call type:

function process.memory()

#### Description

Run a Garbage Collection pass, and return an object containing information on memory usage.

free : Memory that is available to be used

usage : Memory that has been used

total : Total memory

history : Memory used for command history - that is freed if memory is low. Note that this is INCLUDED in the figure for 'free'.

On ARM, stackEndAddress is the address (that can be used with peek/poke/etc) of the END of the stack. The stack grows down, so unless you do a lot of recursion, the bytes above this can be used.

#### Parameters

No parameters

#### Returns

Information about memory usage

### function process.version

(top)

#### Call type:

function process.version

#### Description

Returns the version of Espruino as a String

#### Parameters

No parameters

#### Returns

The version of Espruino

## url Class

(top)

This class helps to convert URLs into Objects of information ready for http.request/get

#### Methods and Fields

- function url.parse(urlStr,parseQuery)

### function url.parse

(top)

#### Call type:

function url.parse(urlStr,parseQuery)

#### Description

A utility function to split a URL into parts

This is useful in web servers for instance when handling a request.

For instance `url.parse("/a?b=c&d=e",true)` returns `{"method":"GET","host":"","path":"/a?b=c&d=e","pathname":"/a","search":"?b=c&d=e","port":80,"query":{"b":"c","d":"e"}}`

#### Parameters

urlStr A URL to be parsed

parseQuery Whether to parse the query string into an object not (default = false)

#### Returns

An object containing options for `http.request` or `http.get`. Contains `method`, `host`, `path`, `pathname`, `search`, `port` and `query`