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