Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Optimized LeJOS superoptimization experimentation code
import lejos.nxt.*;
public class OptimisedTest
extends CommonNXTTests
{
public static void main( String[] args )
throws Exception
{
//variables
LightSensor lightSensor = new LightSensor( SensorPort.S1 );
int reading = 0;
int checkValue = ( lightSensor.getHigh() - lightSensor.getLow() ) / 2 + lightSensor.getLow();
boolean turnNXT = false;
//constants
final String appName = "Optimised App";
calibrateLightSensors( appName, lightSensor );
calibrateMotors( Motor.B, Motor.C );
while ( !Button.LEFT.isPressed() )
{
reading = lightSensor.readNormalizedValue();
displayMainInformation( appName, lightSensor, reading, checkValue );
// superoptimised function start
Motor.C.setPower( ( ( reading > checkValue ) ? DEFINED_POWER : 2 ) );
// superoptimised function stop
}
}
}
Owner

ajosephau commented Apr 27, 2015

Please note that this code requires the "CommonNXTTasks.java" file captured in the companion gist: https://gist.github.com/ajosephau/35de84e202390a921c13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment