利用兩個馬達跟顏色感應器:
影片:
task main()
{
int actual_position=0;
SetSensorColorFull(S4);
ClearScreen( );
for(int i=0;i<=3;i++)
{
RotateMotor(OUT_A, 10,-360);
Off(OUT_A);
Wait(3000);
actual_position = Sensor(S4);
switch(actual_position)
{
case 1: //Black Color
TextOut(50,LCD_LINE2,"Black\n");
break;
case 2: //Blue Color
TextOut(50,LCD_LINE2,"Blue\n");
break;
case 3: //Green Color
TextOut(50,LCD_LINE2,"Green\n");
break;
case 4: //Yellow Color
TextOut(50,LCD_LINE2,"Yellow\n");
break;
case 5: //Red Color
TextOut(50,LCD_LINE2,"Red\n");
break;
case 6: //White Color
TextOut(50,LCD_LINE2,"White\n");
break;
}
Wait(6000);
RotateMotor(OUT_B, 10,-360);
Off(OUT_B);
Wait(8000);
}
}
沒有留言:
張貼留言