All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lejos.hardware.sensor.EV3TouchSensor Maven / Gradle / Ivy

Go to download

leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.

The newest version!
package lejos.hardware.sensor;

import lejos.hardware.port.AnalogPort;
import lejos.hardware.port.Port;

/**
 * Basic sensor driver for the Lego EV3 Touch sensor
 * @author andy
 *
 */
/**
 * Lego EV3 Touch sensor
* The analog EV3 Touch Sensor is a simple but exceptionally precise tool that detects when its front button is pressed or released. * * * *

*

* * * * * * * * * * * * * * * *
Supported modes
Mode nameDescriptionunit(s)Getter
TouchDetects when its front button is pressedBinary {@link #getTouchMode() }
* * * * * See Sensor Product page * See The * leJOS sensor framework * See {@link lejos.robotics.SampleProvider leJOS conventions for * SampleProviders} * *

* * * @author Your name * */ public class EV3TouchSensor extends AnalogSensor { public EV3TouchSensor(AnalogPort port) { super(port); init(); } public EV3TouchSensor(Port port) { super(port); init(); } protected void init() { setModes(new SensorMode[]{ new TouchMode() }); } /** * Lego EV3 Touch sensor, Touch mode
* Detects when its front button is pressed * *

* Size and content of the sample
* The sample contains one element, a value of 0 indicates that the button is not presse, a value of 1 indicates the button is pressed. * *

* * @return A sampleProvider * See {@link lejos.robotics.SampleProvider leJOS conventions for * SampleProviders} */ public SensorMode getTouchMode() { return getMode(0); } private class TouchMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { sample[offset] = (port.getPin6() > EV3SensorConstants.ADC_REF/2f ? 1.0f : 0.0f); } @Override public String getName() { return "Touch"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy