Scripting


Note: This feature is only available for Process event type, using this in Coin and Boot does nothing.

XTimer

Description

Scripting in profile was introduced starting with v1.2.0. This powerful feature enables XTimer to create custom process flow where custom input state and condition profile are needed.

External Modules Supported

# Name Input Output Protocol Type Pins Mode
1 PCF8574 i2c IO 8 hi lo
2 PCA9685 i2c PWM/O 16 pwm
3 MCP23017 i2c IO 16 hi lo
4 MAX485 uart COM 1 - any all
5 MAX232 uart COM 1 - any all

These are list of modules, devices and protocols supported by the scripting engine specifically used for vending custom input state, operation, and condition.

Scripting keywords

# Name Definition
1 if logical if statement
2 else else statement
3 elseif elseif statement
4 while while loop
5 var declare variable
6 func function declaration
7 return return function
8 array variable array declaration

Scripting Operators

# Name Definition
1 * product/ multiplication
2 / division
3 % modulo
4 + sum
5 - difference
6 ! equals alternative
7 & bit and
8 | bit or
9 ^ bit xor
10 >> right bit shift
11 << left bit shift
12 = equal to
13 <> not equal
14 < less than
15 <= less than or equal
16 > greater than
17 => greater than or equal

Built in macros

# Name Description Args Return
1 digitalRead(int) read pin status hi/lo 1 int
2 digitalWrite(int,int) write pin hi/lo 2 int
3 pinMode(int,int) set internal pin mode in/out 2 int
4 delay(int) delay execution 1 int
5 millis(int) get running millisecond 0 int
6 pcfAddress(int) set pcf8754 address 1 int
7 pcfRead(int) read pcf8754 pin status 1 int
8 pcfWrite(int,int) set pin hi/low output 2 int
9 pcaAddress(int) set pca9685 address 1 int
10 pcaFrequency(int) set pca9685 pwm frequency 1 int
11 pcaPwm(int,int,int) set pca9685 PWM 1 int
12 pcaBegin() initialize pca9685 0 int
13 pcaAngle(int,int) move to angle 0 to 180 2 int
14 pcaWrite(int,int) run pwm on pca9685 pin 1 int
15 pcaAllOff() stop all pca9685 pwm 1 int
16 mcpAddress(int) set mcp23017 address 1 int
17 mcpPinMode(int,int) set pcf8754 mode in our out 2 int
18 mcpRead(int) read mcp23017 pin status hi/lo 1 int
19 mcpWrite(int,int) set mcp23017 pin hi/low output 2 int
20 serWrite(array) uart write array value 1 int
21 serRead() uart read single byte 1 int
22 serAvailable() uart has data buffer 1 int
23 setGlobal(int,int) set global variables elapsed, remaining, and status 1 int
24 lcdWrite(int,int) write status to display on row 2 int
25 plsSet(int,int) builtin pin pulse input set pin and mode 2 int
26 plsStop() builtin pin stop pulse input pin 1 int
27 plsRead(int) builtin pin read raw value/seconds with conversion factor 1 int
28 plsTotal(int) builtin pin read cumulative value with convertion factor 1 int
29 chgCoin(int,int) compute coin change 2 int
30 chgOne() get computed number of 1s 1 int
31 chgFive () get computed number of 5s 1 int
32 chgTen() get computed number of 10s 1 int
33 chgTwenty() get computed number of 20s 1 int
34 chgReset() reset remaining credit to zero 1 int
35 chgGet() reset remaining credit to zero 0 int
36 chgSet(x) reset remaining credit to zero 1 int
37 cntSet(int,int,int,int) pulse output generator builtin pin 1 int
38 srvBegin(int,int) servo builtin pin setup 2 int
39 srvSet(int) servo set angle 1 int
40 iicBegin(int,int) i2c begin(sda,scl) 2 int
41 iicRequest(int,int) request (addr, #bytes) from slave 2 int
42 iicRead() read 1 byte 1 int
43 iicAvailable() if slave response available 1 int

The above are custom built-in functions for advance vending profile and operation

Built in constants

# Name Return
1 HIGH int
2 LOW int
3 INPUT int
4 OUTPUT int
5 INPUT_PULLUP int
6 FALLING int
7 RISING int
8 CHANGE int

The above are mostly used for internal pins! use with care.

Variables

Operators

Functions

Arrays

Examples #1 pin toggle

pinMode(15, OUTPUT)
digitalWrite(15, HIGH)
delay(1000)
digitalWrite(15, LOW)
print "finished"

Examples #2 delay counter

var count = 0
while(count <> 10){
  delay(1000)
  count = count + 1
   lcdWrite(3, count)
}
print "finished"

Examples #3 uart transmit

array data[3] = 0x0C, 0x22, 0x38
serWrite(data)
print "finished"

Examples #4 uart receive

while(serAvailable() > 0){
  var c = serRead()
  print c
}
print "finished"

Examples #5 IIC request 6 bytes data

iicBegin(4,5)
iicRequest(0x30, 6)
while(iicAvailable() > 0){
  var c = iicRead()
  print c
}
print "finished"

Examples #6 Servo builtin pin 18

srvBegin(18)
srvSet(90)