Esempio n. 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();
 }
Esempio n. 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();
 }
Esempio n. 3
0
 public int getLightValue() {
   if (_hundred == _zero) return 0;
   return 100 * (port.readRawValue() - _zero) / (_hundred - _zero);
 }
Esempio n. 4
0
 public void setLaser(boolean laserState) {
   port.setType(laserState ? TYPE_LIGHT_ACTIVE : TYPE_LIGHT_INACTIVE);
   this.laser = laserState;
 }
Esempio n. 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);
 }
Esempio n. 6
0
 /** call this method when the light sensor is reading the high value - used by readValue */
 public void calibrateHigh() {
   _hundred = port.readRawValue();
 }