Skip to content

Instantly share code, notes, and snippets.

@ajosephau
Last active August 29, 2015 14:20
Show Gist options
  • Save ajosephau/ac97cb6841b1b5ae11fa to your computer and use it in GitHub Desktop.
Save ajosephau/ac97cb6841b1b5ae11fa to your computer and use it in GitHub Desktop.
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
}
}
}
@ajosephau
Copy link
Author

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