Class: Commands::LightSensor
- Inherits:
-
Object
- Object
- Commands::LightSensor
- Includes:
- Mixins::Sensor
- Defined in:
- lib/commands/light_sensor.rb
Overview
Implements (and extens) the “Light Sensor” block in NXT-G
Instance Attribute Summary collapse
-
#comparison ⇒ Object
Returns the value of attribute comparison.
-
#generate_light ⇒ Object
Returns the value of attribute generate_light.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#trigger_point ⇒ Object
Returns the value of attribute trigger_point.
Instance Method Summary collapse
-
#ambient_mode ⇒ Object
Turns off the sensor’s LED light.
-
#illuminated_mode ⇒ Object
Turns on the sensor’s LED light.
-
#initialize(nxt) ⇒ LightSensor
constructor
A new instance of LightSensor.
-
#intensity ⇒ Object
(also: #light_level)
intensity of light detected 0-100 in %.
-
#method_missing(cmd) ⇒ Object
attempt to return the input_value requested.
-
#raw_value ⇒ Object
returns the raw value of the sensor.
-
#set_mode ⇒ Object
sets up the sensor port.
Methods included from Mixins::Sensor
Constructor Details
#initialize(nxt) ⇒ LightSensor
Returns a new instance of LightSensor.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/commands/light_sensor.rb', line 28 def initialize(nxt) @nxt = nxt # defaults the same as NXT-G @port = 3 @trigger_point = 50 @comparison = ">" @generate_light = true set_mode end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(cmd) ⇒ Object
attempt to return the input_value requested
79 80 81 |
# File 'lib/commands/light_sensor.rb', line 79 def method_missing(cmd) @nxt.get_input_values(NXTComm.const_get("SENSOR_#{@port}"))[cmd] end |
Instance Attribute Details
#comparison ⇒ Object
Returns the value of attribute comparison.
26 27 28 |
# File 'lib/commands/light_sensor.rb', line 26 def comparison @comparison end |
#generate_light ⇒ Object
Returns the value of attribute generate_light.
25 26 27 |
# File 'lib/commands/light_sensor.rb', line 25 def generate_light @generate_light end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
25 26 27 |
# File 'lib/commands/light_sensor.rb', line 25 def port @port end |
#trigger_point ⇒ Object
Returns the value of attribute trigger_point.
26 27 28 |
# File 'lib/commands/light_sensor.rb', line 26 def trigger_point @trigger_point end |
Instance Method Details
#ambient_mode ⇒ Object
Turns off the sensor’s LED light.
40 41 42 |
# File 'lib/commands/light_sensor.rb', line 40 def ambient_mode self.generate_light = false end |
#illuminated_mode ⇒ Object
Turns on the sensor’s LED light.
45 46 47 |
# File 'lib/commands/light_sensor.rb', line 45 def illuminated_mode self.generate_light = true end |
#intensity ⇒ Object Also known as: light_level
intensity of light detected 0-100 in %
58 59 60 |
# File 'lib/commands/light_sensor.rb', line 58 def intensity value_scaled end |
#raw_value ⇒ Object
returns the raw value of the sensor
64 65 66 |
# File 'lib/commands/light_sensor.rb', line 64 def raw_value value_raw end |
#set_mode ⇒ Object
sets up the sensor port
69 70 71 72 73 74 75 76 |
# File 'lib/commands/light_sensor.rb', line 69 def set_mode @generate_light ? mode = NXTComm::LIGHT_ACTIVE : mode = NXTComm::LIGHT_INACTIVE @nxt.set_input_mode( NXTComm.const_get("SENSOR_#{@port}"), mode, NXTComm::PCTFULLSCALEMODE ) end |