- Code: Select all
package org.lejos.example;
import lejos.nxt.*;
/**
* Example leJOS Project with an ant build file
*/
public class HelloWorld {
public static boolean rotate = false;
public static boolean halt = false;
public static boolean auto = true;
class MyClass {
}
public static void main(String[] args)
{
// Main class
if (auto = true){
/**
* Autodrive
*/
autodrive();
}else{
/**
* guided drive
*/
}
}
public static void headcheck()
{
// Rotate op motor.B input op 2
boolean allowrotate = false;
boolean direction = true;
int intdegrees = 0;
if (allowrotate = true) {
//rotate
Motor.B.resetTachoCount();
if (direction = true) {
//rotate and check left
direction = false;
while (intdegrees <= 15) {
Motor.B.rotateTo(intdegrees);
intdegrees = intdegrees + 5;
}
} else {
//rotate and check right
direction = true;
while (intdegrees >= -15) {
Motor.B.rotateTo(intdegrees);
intdegrees = intdegrees - 5;
}
}
} else {
//no rotate
}
}
public static void forward()
{
while (rotate = true){
Motor.A.forward();
Motor.C.forward();
}
}
public static void backward()
{
while (rotate = true){
Motor.A.backward();
Motor.C.backward();
}
}
public static void left()
{
while (rotate = true){
Motor.A.backward();
Motor.C.forward();
}
}
public static void right()
{
while (rotate = true){
Motor.A.forward();
Motor.C.backward();
}
}
public static void stopall()
{
while (rotate = true){
Motor.A.stop();
Motor.C.stop();
}
}
public static void pressuresensora()
{
TouchSensor pa = new TouchSensor(SensorPort.S4);
while (!pa.isPressed()){
stopall();
}
}
public static void pressuresensorb()
{
TouchSensor pb = new TouchSensor(SensorPort.S1);
while (!pb.isPressed()){
stopall();
}
}
public static void afstand()
{
UltrasonicSensor us = new UltrasonicSensor(SensorPort.S2);
int afstand;
afstand = us.getDistance();
LCD.drawInt(afstand, 1, 1);
if (afstand < 10){
stopall();
}
}
public static void autodrive()
{
while(auto = true){
}
}
}
this is what I have, now I only need a way to put this multithreading in my public void autodrive and then call al the other functions there while driving.
I would appreciate all help caus it's for my thesis or whatever you call it in english (in dutch it's eindwerk.)
regards Shadowstep
