LightSensor Class Reference

Light-sensor interface (active/passive mode). More...

#include <c++/LightSensor.H>

Inheritance diagram for LightSensor:
Collaboration diagram for LightSensor:

Public Types

enum  Port { S1 = 0 , S2 , S3 , Battery }
 List of sensor identifiers (IDs). More...
 

Public Member Functions

 LightSensor (const Sensor::Port port)
 Instance an active light sensor at {port}.
 
unsigned int get () const
 Get the current lightSensor value.
 
unsigned int sample (unsigned int size=10, int wait=2) const
 Get the average of {size} samples, waiting {wait} mSec between each sample.
 
void mode (bool makeActive) const
 Set the sensor (mode) to active or passive.
 
void passive () const
 Set the sensor to passive (turn off voltage to connector)
 
void active () const
 Set the sensor to active (provide voltage to connector)
 
void on () const
 Turn the sensor on (provide voltage to connector)
 
void off () const
 Turn the sensor off (turn off voltage to connector)
 
void strobe () const
 Quickly turn sensor off then back on.
 
void strobe (const int ms) const
 Turn sensor off, wait for {ms} milliSeconds, then then turn it back on.
 

Protected Attributes

volatile unsigned int & sensor
 The address of our sensor value.
 

Detailed Description

Light-sensor interface (active/passive mode).

The LightSensor Class - using a LightSensor in active or passive mode

At construction time you specify the RCX connector pad to which the LightSensor is attached.

This class provides two methods to read the value of the sensor [get, sample]

Note
access methods from the base class Sensor if you desire access to the raw sensor values or to the power control methods.
See also
The other sensor classes: Sensor, RotationSensor, and TouchSensor

Definition at line 46 of file LightSensor.H.

Member Enumeration Documentation

◆ Port

enum Sensor::Port
inherited

List of sensor identifiers (IDs).

S1, S2, S3 are connector pads 1, 2 and 3 on the RCX.

Battery is the internal sensor allowing a program to read the current battery voltage in milliVolts

Possible Sensor Port Values

See also
Battery
Enumerator
S1 

RCX sensor port 1.

S2 

RCX sensor port 2.

S3 

RCX sensor port 3.

Battery 

RCX battery sensor.

Definition at line 67 of file Sensor.H.

Constructor & Destructor Documentation

◆ LightSensor()

LightSensor::LightSensor ( const Sensor::Port  port)
inline

Instance an active light sensor at {port}.

Parameters
portThe connector pad (1, 2 or 3) to which the light sensor is attached

Definition at line 53 of file LightSensor.H.

Member Function Documentation

◆ active()

void Sensor::active ( ) const
inlineinherited

Set the sensor to active (provide voltage to connector)

See also
Sensor::passive, Sensor::on, Sensor::off, Sensor::mode

Definition at line 133 of file Sensor.H.

References ds_active(), and Sensor::sensor.

Referenced by Sensor::mode(), Sensor::on(), and Sensor::Sensor().

◆ get()

unsigned int LightSensor::get ( ) const
inline

Get the current lightSensor value.

NOTE: ultimately, this will be scaled to fall between 0 and 100.

Returns
unsigned int - the current light sensor reading
See also
LightSensor::sample

Definition at line 61 of file LightSensor.H.

References LIGHT, and Sensor::sensor.

Referenced by sample().

◆ mode()

void Sensor::mode ( bool  makeActive) const
inlineinherited

Set the sensor (mode) to active or passive.

Parameters
makeActive- T/F - Where true means to go active (voltage is supplied to the connector pad)
See also
Sensor::off, Sensor::on, Sensor::active, Sensor::passive

Definition at line 118 of file Sensor.H.

References Sensor::active(), and Sensor::passive().

◆ off()

void Sensor::off ( ) const
inlineinherited

Turn the sensor off (turn off voltage to connector)

See also
Sensor::on, Sensor::active, Sensor::passive, Sensor::mode

Definition at line 145 of file Sensor.H.

References Sensor::passive().

Referenced by Sensor::strobe(), Sensor::strobe(), and Sensor::~Sensor().

◆ on()

void Sensor::on ( ) const
inlineinherited

Turn the sensor on (provide voltage to connector)

See also
Sensor::off, Sensor::active, Sensor::passive, Sensor::mode

Definition at line 139 of file Sensor.H.

References Sensor::active().

Referenced by Sensor::strobe(), and Sensor::strobe().

◆ passive()

void Sensor::passive ( ) const
inlineinherited

Set the sensor to passive (turn off voltage to connector)

See also
Sensor::active, Sensor::on, Sensor::off, Sensor::mode

Definition at line 127 of file Sensor.H.

References ds_passive(), and Sensor::sensor.

Referenced by Sensor::mode(), Sensor::off(), and Sensor::Sensor().

◆ sample()

unsigned int LightSensor::sample ( unsigned int  size = 10,
int  wait = 2 
) const
inline

Get the average of {size} samples, waiting {wait} mSec between each sample.

Parameters
size- Number of samples to average (default = 10 samples)
wait- time (in mS) to wait between samples (default = 2mS)
Returns
unsigned int - The average of the sampled values
See also
LightSensor::get

Definition at line 69 of file LightSensor.H.

References delay(), and get().

◆ strobe() [1/2]

void Sensor::strobe ( ) const
inlineinherited

Quickly turn sensor off then back on.

See also
Sensor::on, Sensor::off, Sensor::active, Sensor::passive, Sensor::mode

Definition at line 151 of file Sensor.H.

References Sensor::off(), and Sensor::on().

◆ strobe() [2/2]

void Sensor::strobe ( const int  ms) const
inlineinherited

Turn sensor off, wait for {ms} milliSeconds, then then turn it back on.

Parameters
ms- Number of milliSeconds to wait between off and back on
See also
Sensor::on, Sensor::off, Sensor::active, Sensor::passive, Sensor::mode

Definition at line 158 of file Sensor.H.

References delay(), Sensor::off(), and Sensor::on().

Member Data Documentation

◆ sensor

volatile unsigned int& Sensor::sensor
protectedinherited

The address of our sensor value.

Definition at line 181 of file Sensor.H.

Referenced by Sensor::active(), get(), Sensor::get(), RotationSensor::off(), RotationSensor::on(), Sensor::passive(), RotationSensor::pos(), and TouchSensor::pressed().


The documentation for this class was generated from the following file:

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS C++ by doxygen 1.9.8