Last active
August 29, 2015 14:20
-
-
Save ajosephau/ac97cb6841b1b5ae11fa to your computer and use it in GitHub Desktop.
Optimized LeJOS superoptimization experimentation code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please note that this code requires the "CommonNXTTasks.java" file captured in the companion gist: https://gist.github.com/ajosephau/35de84e202390a921c13