Difference between revisions of "Lua interface"

From Studio Kousagi Wiki
Jump to: navigation, search
(Created page with "The primary language used to develop for NeTV is Lua. This language was chosen because it's both easy to work with and is very fast. ==Motor control library API== There is a mo...")
 
Line 2: Line 2:
  
 
==Motor control library API==
 
==Motor control library API==
There is a motor control API available.
+
There is a motor control API available.  To import the library, run:
 +
require("motor")
 +
 
 +
===Digital I/O===
 +
'''motor.set_digital(v)''' - Sets the digital output pins to the value ''v''.  All pins are set at the same time.
 +
 
 +
===Motor control===
 +
 
 +
'''motor.set_type(m, t)''' - Sets the type of motor ''m'' to the type ''t''.  To switch to a servo, specify "s" for ''t''.  To switch to a motor, specify "m" for ''t''.  Note that you can only set channels 1 and 2 to servo.
 +
 
 +
'''motor.set_speed(m, v)''' - Sets the current speed of motor ''m'' to the speed ''v''.  The speed is specified from -255 to 255.
 +
 
 +
'''motor.set_angle(m, a)''' - Sets the angle of motor ''m'' to ''a'' degrees.  The angle must be between 0 and 180.
 +
 
 +
===Analog input===
 +
'''motor.get_adc(a)''' - Gets the current value from ADC ''a''.  There are 8 ADCs numbered 0-7.  The return value is from 0 - 255.
 +
 
 +
===Miscellaneous functions===
 +
'''netv.sleep(t)''' - Sleep for ''t'' seconds.  ''t' is a Lua Number, and so may be non-integer, e.g. 0.5.

Revision as of 09:26, 16 December 2011

The primary language used to develop for NeTV is Lua. This language was chosen because it's both easy to work with and is very fast.

Motor control library API

There is a motor control API available. To import the library, run:

require("motor")

Digital I/O

motor.set_digital(v) - Sets the digital output pins to the value v. All pins are set at the same time.

Motor control

motor.set_type(m, t) - Sets the type of motor m to the type t. To switch to a servo, specify "s" for t. To switch to a motor, specify "m" for t. Note that you can only set channels 1 and 2 to servo.

motor.set_speed(m, v) - Sets the current speed of motor m to the speed v. The speed is specified from -255 to 255.

motor.set_angle(m, a) - Sets the angle of motor m to a degrees. The angle must be between 0 and 180.

Analog input

motor.get_adc(a) - Gets the current value from ADC a. There are 8 ADCs numbered 0-7. The return value is from 0 - 255.

Miscellaneous functions

netv.sleep(t) - Sleep for t seconds. t' is a Lua Number, and so may be non-integer, e.g. 0.5.