tinyvm.rcx
Class Sensor

java.lang.Object
  |
  +--tinyvm.rcx.Sensor

public class Sensor
extends Object

Abstraction for a sensor. Example:

   Sensor.S1.activate();
   Sensor.S1.addSensorListener (new SensorListener() {
     public void stateChanged (Sensor src, boolean value) {
       if (value)
         Sound.beep();
     }

     public void stateChanged (Sensor src, int value) {
       LCD.showNumber (value);
       for (int k = 0; k < 10; k++) { }
     }
   });
     
 


Field Summary
static Sensor S1
          Sensor 1.
static Sensor S2
          Sensor 2.
static Sensor S3
          Sensor 3.
 
Method Summary
 void activate()
          Activates the sensor.
 void addSensorListener(SensorListener aListener)
          Adds a sensor listener.
 void passivate()
          Passivates the sensor.
 boolean readBooleanValue()
           
 int readPercentage()
           
 int readRawValue()
           
static int readSensorValue(short aCode, byte aType, byte aMode)
          Low-level API for reading sensor values.
 
Methods inherited from class java.lang.Object
getClass, toString
 

Field Detail

S1

public static final Sensor S1
Sensor 1.

S2

public static final Sensor S2
Sensor 2.

S3

public static final Sensor S3
Sensor 3.
Method Detail

addSensorListener

public void addSensorListener(SensorListener aListener)
Adds a sensor listener.

NOTE 1: You can add at most 4 listeners.
NOTE 2: Calling this method will result in the creation of a non-daemon thread (one per sensor at most), i.e. your program will not terminate on its own.
NOTE 3: Synchronizing inside listener methods could result in a deadlock.


activate

public final void activate()
Activates the sensor. This method should be called if you want to get accurate values from the sensor. In the case of light sensors, you should see the led go on when you call this method.

passivate

public final void passivate()
Passivates the sensor.

readRawValue

public final int readRawValue()

readBooleanValue

public final boolean readBooleanValue()

readPercentage

public final int readPercentage()

readSensorValue

public static int readSensorValue(short aCode,
                                  byte aType,
                                  byte aMode)
Low-level API for reading sensor values.
Parameters:
aCode - Sensor ID (0x1000 + num_in_rcx - 1).
aType - 0 = RAW, 1 = TOUCH, 2 = TEMP, 3 = LIGHT, 4 = ROT.
aMode - 0x00 = RAW, 0x20 = BOOL, 0x40 = EDGE, 0x60 = PULSE, 0x80 = PERCENT, 0xA0 = DEGC, 0xC0 = DEGF, 0xE0 = ANGLE. Also, mode can be OR'd with slope (0..31).