Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 8 years ago

急~~~請問NXT樂高機器人程式設計該怎麼寫??

如題,我用Bricx Command Center這個軟體來寫NXT樂高機器人的程式,請問以下機器人動作該怎麼寫??

1.機器人的超音波感應到物體時前進,並於LCD上顯示Forward

2.按下觸碰感應器二下,後退時鳴叫,並於LCD上顯示鳴叫次數

3.機器人啟動後自動於5秒內停止所有動作

求有在玩樂高機器人高手幫我解答,謝謝。

Update:

會NXT樂高程式的高手,請教教我~~~

1 Answer

Rating
  • Favorite Answer

    task main ()

    {

    SetSensorLowspeed(S2);

    SetSensorType(S1,SENSOR_TYPE_TOUCH);

    SetSensorMode(S1,SENSOR_MODE_PULSE);

    int i , j;

    for(i=1;i<6;i++) // 3.機器人5秒內停止

    {

    while(true)

    {

    ClearSensor(S1);

    until(Sensor(S2)>6);

    TextOut(40,50,"Forward"); // 1.在LCD上顯示Forward

    OnFwd(OUT_AC,50);

    until(Sensor(S1)>0);

    Wait(500);

    if (Sensor(S1)==1);

    {

    Off(OUT_AC);

    }

    if(Sensor(S1)==2) // 2.按下觸碰2次,後退時鳴叫

    {

    OnRev(OUT_AC,50);

    for(j=1;j<10;j++)

    {

    PlayTone(250,500);

    NumOut(30,40,j);

    }

    }

    }

    Wait(1000);

    if(i==6)

    {

    Off(OUT_AC);

    }

    }

Still have questions? Get your answers by asking now.