import lejos.nxt.*;//載入模組
class p
{
public static void main(String args[])//進入主程式
{
Button.ESCAPE.addButtonListener(new ButtonListener()//設定取消鍵
{
public void buttonPressed(Button b){System.exit(0);}
public void buttonReleased(Button b){}
});
LightSensor light = new LightSensor(SensorPort.S1);//設定感測器類別
int offset = 37;//光感平均值
int Kp = 10;
int Kp1 = -10;
while(true)
{
int Light = light.readValue();
Motor.C.setSpeed(Kp*(Light - offset)+700);
Motor.B.setSpeed(Kp1*(Light - offset)+700);
Motor.C.backward();
Motor.B.backward();
}
}
}
沒有留言:
張貼留言