Mindsensors 分別讀取8個light sensor值 in leJOS (by祥瑞)

import lejos.nxt.*;
import lejos.nxt.addon.NXTLineLeader;
import lejos.util.Delay;

class LLRead {
    public static void main(String args[]) {
        Button.ESCAPE.addButtonListener(new ButtonListener() {
            public void buttonPressed(Button b) {System.exit(0);}
            public void buttonReleased(Button b) {}
        });
        
        NXTLineLeader LL = new NXTLineLeader(SensorPort.S1);
        int address;
        byte[] buf = new byte[8];
        int ret;
        int value;
        while(true) {
            for(address=0x49; address<=0x50; address++) {
                ret = LL.getData(address, buf, 2);
                value = (ret == 0 ? (buf[0] & 0xff) : -1);
                LCD.drawString("S" + (address-0x49) + " " + value, 0, address-0x49);
            }
            Delay.msDelay(200);
            LCD.clear();
        }
    }
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *