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

lejos.hardware.sensor.RCXThermometer 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.LegacySensorPort;


/**
 * Lego RCX temperature sensor
* The sensor measures both atmospheric pressure and temperature. * *

* The code for this sensor has not been tested. Please report test results to * the leJOS forum. *

* *

*

* * * * * * * * * * * * * * * *
Supported modes
Mode nameDescriptionunit(s)Getter
TemperatureMeasures temperatureDegree Celcius {@link #getTemperatureMode() }
* * * See The * leJOS sensor framework * See {@link lejos.robotics.SampleProvider leJOS conventions for * SampleProviders} * *

* * * @author Soren Hilmer * */ public class RCXThermometer extends AnalogSensor implements SensorConstants { LegacySensorPort port; /** * Create an RCX temperature sensor object attached to the specified port. * @param port port, e.g. Port.S1 */ public RCXThermometer(LegacySensorPort port) { super(port); init(); } protected void init() { setModes(new SensorMode[]{ new TemperatureMode() }); port.setTypeAndMode(TYPE_TEMPERATURE, MODE_RAW); } /** * Return a sample provider in temperature mode */ public SensorMode getTemperatureMode() { return getMode(0); } private class TemperatureMode implements SensorMode { @Override public int sampleSize() { return 1; } @Override public void fetchSample(float[] sample, int offset) { sample[offset] = (785-NXTRawValue(port.getPin1()))/8.0f +273.15f; // Kelvin } @Override public String getName() { return "Temperature"; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy