Class: DigitalLightSensor

Robot.DigitalLightSensor(sensorRadius, position, bufferLength, threshUp, threshDown)

Class containing the digital light sensor features. This extends the implementation of the analog light sensor by adding thresholds to indicate if the sensor is fully white or fully black.

Constructor

new DigitalLightSensor(sensorRadius, position, bufferLength, threshUp, threshDown)

Constructor function for DigitalLightSensor
Parameters:
Name Type Default Description
sensorRadius number The value of the sensor detection circle radius.
position p5.Vector The current position of the sensor in the global coordinate frame.
bufferLength number 1 An integer showing the length of the internal circular buffer that stores the previous sensor values.
threshUp number 0.65 The upper threshold required to return white
threshDown number 0.35 The low threshold required to return black
Source:
See:

Methods

read(tile) → {number}

A function to read the value of the light sensor. It will use the read function from the AnalogLightSensor and compare the value to the thresholds.
Parameters:
Name Type Description
tile World.Tile The tile to read
Source:
See:
  • Robot.AnalogLightSensor.read
Returns:
- 0 (black) or 1 (white).
Type
number

setThresholdDown(threshDown)

A function to set the down threshold. This will constrain the value to between 0 and 1. If the threshold is higher than the up threshold then they will be switched.
Parameters:
Name Type Description
threshDown number New threshold.
Source:

setThresholdUp(threshUp)

A function to set the up threshold. This will constrain the value to between 0 and 1. If the threshold is lower than the down threshold then they will be switched.
Parameters:
Name Type Description
threshUp number New threshold.
Source:

swapThresholds()

A function to swap the thresholds if threshDown is larger than threshUp;
Source:

Documentation generated by JSDoc 4.0.2 on Fri Aug 30 2024 16:12:54 GMT-0600 (Mountain Daylight Time)