Class: LightSensor
Constant Summary
Constants inherited from Sensor
Instance Attribute Summary
Attributes inherited from Brick
Instance Method Summary collapse
-
#get_light_level ⇒ Object
Get the current light level as a float from 0 to 1.0.
-
#initialize(nxt, port = NXTComm::SENSOR_3) ⇒ LightSensor
constructor
A new instance of LightSensor.
- #use_ambient_mode ⇒ Object
- #use_illuminated_mode ⇒ Object
Methods inherited from Sensor
#name, #off, #read_data, #set_input_mode, #wait_for_event
Constructor Details
#initialize(nxt, port = NXTComm::SENSOR_3) ⇒ LightSensor
Returns a new instance of LightSensor.
23 24 25 26 |
# File 'lib/sensors/light_sensor.rb', line 23 def initialize(nxt, port = NXTComm::SENSOR_3) super(nxt, port) use_illuminated_mode end |
Instance Method Details
#get_light_level ⇒ Object
Get the current light level as a float from 0 to 1.0. 1.0 is maximum, 0 is minimum.
30 31 32 33 |
# File 'lib/sensors/light_sensor.rb', line 30 def get_light_level # TODO: probably need to calibrate this... light level never really reaches 1023 (read_data[:value_scaled]).to_f / 1023.to_f end |
#use_ambient_mode ⇒ Object
41 42 43 |
# File 'lib/sensors/light_sensor.rb', line 41 def use_ambient_mode set_input_mode(NXTComm::LIGHT_INACTIVE, NXTComm::RAWMODE) end |
#use_illuminated_mode ⇒ Object
36 37 38 |
# File 'lib/sensors/light_sensor.rb', line 36 def use_illuminated_mode set_input_mode(NXTComm::LIGHT_ACTIVE, NXTComm::RAWMODE) end |