rcxlightsensor.java

来自「专业汽车级嵌入式操作系统OSEK的源代码」· Java 代码 · 共 50 行

JAVA
50
字号
package lejos.nxt;/** * Abstraction for an RCX light sensor. *  */public class RCXLightSensor implements SensorConstants {	LegacySensorPort port;		/**	 * Create an RCX light sensor object attached to the specified port.	 * The sensor will be activated, i.e. the LED will be turned on.	 * @param port port, e.g. Port.S1	 */	public RCXLightSensor(LegacySensorPort port)	{		this.port = port;		port.setTypeAndMode(TYPE_REFLECTION,                            MODE_PCTFULLSCALE);	}		/**	  * Activates an RCX light sensor. This method should be called	  * if you want to get accurate values from an RCX	  * sensor. In the case of RCX light sensors, you should see	  * the LED go on when you call this method.	  */	public void activate()	{		port.activate();	}		/**     * Passivates an RCX light sensor. 	 */	public void passivate()	{		port.passivate();	}		/**	 * Read the current sensor value.	 * @return Value as a percentage.	 */	public int readValue()	{		return ((1023 - port.readRawValue()) * 100/ 1023);  	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?