Robofun 機器人論壇
標題:
關於用藍芽控制自走車的程式
[打印本頁]
作者:
kocli
時間:
2015-10-19 22:40
標題:
關於用藍芽控制自走車的程式
本帖最後由 kocli 於 2015-10-19 22:51 編輯
因為我們買這台自走車的時候他就有附上程式了
但是我看不太懂 可否請各位大大們幫我加上註解讓我瞭解一下這程式在寫什麼@@
勞煩和辛苦各位大大了
const int KEY_NOTHING = 0x0;
const int KEY_UP = 0x1;
const int KEY_DOWN = 0x2;
const int KEY_RIGHT = 0x4;
const int KEY_LEFT = 0x8;
const int DELAY = 300;
unsigned char Motion_val;
unsigned char Receive_val;
unsigned char FLAG;
unsigned char len;
unsigned char Buffer_temp[4];
unsigned char i;
void UART_FUN()
{
for(i=0;i<5;i++)
Buffer_temp
=0x0;
delay(100);
while(blueToothSerial.available())
{
Receive_val=blueToothSerial.read();
//Serial.print(Receive_val);
// Serial.print("\n");
if(Receive_val==0xAA)
{
len=0;
Buffer_temp[len++]=Receive_val;
}
else if(len < 5)
{
Buffer_temp[len++]=Receive_val;
}
}
if(Buffer_temp[0]==0xAA && Buffer_temp[1]==0xBB && Buffer_temp[3]==0xF1)
{
Serial.print("UP \n");
Motion_val=KEY_UP;
}
else if(Buffer_temp[0]==0xAA && Buffer_temp[1]==0xBB && Buffer_temp[3]==0xF2)
{
Serial.print("DOWN \n");
Motion_val=KEY_DOWN ;
}
else if(Buffer_temp[0]==0xAA && Buffer_temp[1]==0xBB && Buffer_temp[3]==0xF4)
{
Serial.print("RIGHT \n");
Motion_val=KEY_RIGHT ;
}
else if(Buffer_temp[0]==0xAA && Buffer_temp[1]==0xBB && Buffer_temp[3]==0xF8)
{
Serial.print("LEFT \n");
Motion_val=KEY_LEFT ;
}
else if(Buffer_temp[0]==0xAA && Buffer_temp[1]==0xBB && Buffer_temp[3]==0x00)
{
Serial.print("KEY_NOTHING \n");
Motion_val=KEY_NOTHING ;
}
bluetooth_car.ino
2015-10-19 22:43 上傳
點擊文件名下載附件
3.7 KB, 下載次數: 1156
自走車
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/)
Powered by Discuz! X3.2