/* Use of SensorListener */
import tinyvm.rcx.
class sensors implements SensorListener
/** One of the methods in SensorListener */
method stateChanged(source=Sensor, value=boolean)
/** Another of the methods in SensorListener */
method stateChanged(source=Sensor, value=int)
/* This method is called whenever the raw value changes */
LCD.showNumber(value)
Time.sleep(2)
/** Main method */
method main(s=String[]) static
/* Create a sensor listener instance */
listener = sensors()
/* Active sensor 2 */
Sensor.S2.activate()
/* Add the listener to sensor 2 */
Sensor.S2.addSensorListener(listener)
/* Programs runs forever when sensor listener is active */
|