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

lejos.robotics.ColorAdapter 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.robotics;

import lejos.hardware.sensor.*;

public class ColorAdapter implements ColorDetector, ColorIdentifier {
	
	private final float[] bufDetect;
	private final float[] bufID;
	SensorMode colorDetector;
	SensorMode colorIdentifier;
	
	public ColorAdapter(BaseSensor colorSensor) {
		this.colorDetector = colorSensor.getMode("RGB");
		this.colorIdentifier = colorSensor.getMode("ColorID");
		bufDetect=new float[colorDetector.sampleSize()];
		bufID=new float[colorIdentifier.sampleSize()];
	}
	
	public int getColorID() {
		colorIdentifier.fetchSample(bufID, 0);
		return (int)bufID[0];
	}
	 
	@Override
	public Color getColor() {
		colorDetector.fetchSample(bufDetect, 0);
		Color color = new Color((int)(256*bufDetect[0]), (int)(256*bufDetect[1]), (int)(256*bufDetect[2]));
		return color;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy