示例#1
0
 /** call this method when the light sensor is reading the low value - used by readValue */
 public void calibrateLow() {
   // TODO: Should these methods save calibrated data in static memory?
   _zero = port.readRawValue();
 }
示例#2
0
 /**
  * Get the normalized light reading
  *
  * @return normalized raw value (0 to 1023) LEGO NXT light sensor values typically range from 145
  *     (dark) to 890 (sunlight).
  */
 public int getNormalizedLightValue() {
   return 1023 - port.readRawValue();
 }
示例#3
0
 public int getLightValue() {
   if (_hundred == _zero) return 0;
   return 100 * (port.readRawValue() - _zero) / (_hundred - _zero);
 }
示例#4
0
 public void setLaser(boolean laserState) {
   port.setType(laserState ? TYPE_LIGHT_ACTIVE : TYPE_LIGHT_INACTIVE);
   this.laser = laserState;
 }
示例#5
0
 /**
  * Create a laser sensor object attached to the specified port, and sets the laser on or off.
  *
  * @param port port, e.g. Port.S1
  * @param laser true to turn on the laser, false for laser off.
  */
 public LaserSensor(ADSensorPort port, boolean laserState) {
   this.port = port;
   this.laser = laserState;
   port.setTypeAndMode((laserState ? TYPE_LIGHT_ACTIVE : TYPE_LIGHT_INACTIVE), MODE_PCTFULLSCALE);
 }
示例#6
0
 /** call this method when the light sensor is reading the high value - used by readValue */
 public void calibrateHigh() {
   _hundred = port.readRawValue();
 }