Skip to content

Analog Sensors

Johan Vandegriff edited this page Dec 15, 2016 · 6 revisions

EVLib has its own interface for Analog sensors. It extends InputExtractor (from the state-machine-framework) of type Double, which means that every AnalogSensor has to have a method that returns a Double: Double getValue().

ftc/evlib/hardware/sensors/AnalogSensor.java

package ftc.evlib.hardware.sensors;

import ftc.electronvolts.util.InputExtractor;

/**
 * This file was made by the electronVolts, FTC team 7393
 * Date Created: 9/11/16
 * 
 * Interface for any type of analog sensor
 * examples: light sensor, distance sensor, potentiometer
 *
 * @see InputExtractor
 * @see Sensors
 */
public interface AnalogSensor extends InputExtractor<Double> {
}

To create an AnalogSensor from an AnalogInput (which is part of the FTC libraries), you can use the ftc/evlib/hardware/sensors/Sensors.java factory class:

AnalogInput analogInput = hardwareMap.analogInput.get("lightSensor");
AnalogSensor lightSensor = Sensors.analog(analogInput);

//To combine on one line:
AnalogSensor lightSensor = Sensors.analog(hardwareMap, "lightSensor");

To get the value of a sensor, call the getValue() method:

telemetry.addData("light sensor", lightSensor.getValue());

See also: DistanceSensor, Digital Sensors