luz#
Inicializando la clase light#
Un sensor de luz se crea utilizando el siguiente constructor:
The light
constructor creates a light object in the specified Three Wire Port:
Parámetro |
Descripción |
---|---|
|
El puerto de 3 cables al que está conectado el sensor de luz, ya sea un puerto en el Cerebro o un Expandedor de 3 cables. |
Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de clase light.
// Create the Brain.
brain Brian;
// Construct a Light Sensor "light" with the Light class.
light Light = light(Brain.ThreeWirePort.A);
This Light
object will be used in all subsequent examples throughout this API documentation when referring to light class methods.
Métodos de clase#
brightness()#
The brightness(units)
method returns the brightness level of light falling on the Light Sensor. The brightness of the Light Sensor is an estimation based on the raw value of the sensor.
Un brillo del 0 % es un valor bruto de 900 o superior. Un brillo del 100 % es un valor bruto de 0.
Parámetros |
Descripción |
---|---|
unidades |
The only valid unit for brightness is |
Devuelve: Un doble que representa el nivel de brillo del sensor de luz en el rango de 0% - 100%.
// Get Light Sensor brightness in range of 0% - 100%.
double value = Light.brightness();
changed()#
The changed(callback)
method registers a callback function for when the value of the Light Sensor changes.
Parámetros |
Descripción |
---|---|
llamar de vuelta |
La función de devolución de llamada que se llamará cuando cambie el valor del sensor de luz. |
Devoluciones: Ninguna.
// Define the lightChanged function with a void return
// type, showing it doesn't return a value.
void lightChanged() {
// The Brain will print that the Light Sensor's value
// changed on the Brain's screen.
Brain.Screen.print("Light Sensor value changed");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Drive the robot forward.
Drivetrain.drive(forward);
// Run lightChanged when the value of the Light Sensor
// changes.
Light.changed(lightChanged);
}