#include "c:\winavr\ezrobomaster\ezrmlib.h"
void Dir(char S,char dilemma);
int main()
{
char Azimuth=12; // 1당 30도 -는 오류가 나니까 한바퀴(360) 돌린다음 생각
char Dilemma=0;
char sw1stat, sw2stat;
SysInit();
LgmSetPow(PORT_M1+PORT_M2, 1);
LgmRunDir(PORT_M1+PORT_M2, DIR_CW);
while(1)
{
if(LgsReadType(PORT_A6, LGS_TYPE_TOUCH))
{
LedOn(LED_LEFT);
LedOff(LED_RIGHT);
sw1stat=1;
if(sw2stat) ++Dilemma, sw2stat=0;
if(Dilemma>=5) BzrTemp(300), Dir(1,Azimuth), Dilemma=0;
if(Azimuth>=16)
{
LedOn(LED_ALL);
Delay(300);
LedOff(LED_LEFT);
Dir(0,Azimuth);
Azimuth=12-1;
}
else
{
Dir(1,0), ++Azimuth;
}
}
else if(LgsReadType(PORT_A7, LGS_TYPE_TOUCH))
{
LedOn(LED_RIGHT);
LedOff(LED_LEFT);
sw2stat=1;
if(sw1stat /*|| Dilemma>3*/) ++Dilemma, sw1stat=0;
if(Dilemma>=5)BzrTemp(300), Dir(0,Azimuth), Dilemma=0 ;
if(Azimuth<=8)
{
LedOn(LED_ALL);
Delay(300);
LedOff(LED_RIGHT);
Dir(1,Azimuth);
Azimuth=12+1;
}
else
{
Dir(0,0), --Azimuth;
}
}
}
return 0;
}
void Dir(char S,char dilemma)
{
char i=0;
LgmStopFast(PORT_M1+PORT_M2);
Delay(200);
if(dilemma!=0 && dilemma>12) i=1, dilemma=dilemma-12;
if(dilemma!=0 && dilemma<12) i=1, dilemma=12-dilemma;
LgmRunRev(PORT_M1+PORT_M2);
Delay(200+i*2*150);
LgmStopFast(PORT_M1+PORT_M2);
Delay(500);
LgmSetPow(PORT_M1+PORT_M2, 5);
if(S)
{
LgmRunDir(PORT_M1, DIR_CCW);
LgmRunDir(PORT_M2, DIR_CW);
}
else
{
LgmRunDir(PORT_M1, DIR_CW);
LgmRunDir(PORT_M2, DIR_CCW);
}
Delay(450+i*dilemma*450);
LgmSet(PORT_M1+PORT_M2,DIR_CW,1);
}
일정 시간동안 안에 입력을 받았을때만 딜레마값을 증가시키면
구석 에서 못빠져 나오는 경우느 빙빙 돌아 집에 가는 경우 둘다 쉽게 제어 가능한데
time() 함수가 안되 ㅋ... 그렇다고 delay() 쓰기엔 너무 위험하고
1/1000 마다 프로그램이 한번씩도니까 0.001 씩 카운트 하는 타이머 용 변수를 만들면 되나 ??
sleep 함수 같은건?