So. Hab auch mal ne Frage hierzu.
Hier mein Code (Asuro kann hierbei halt noch ne Vierteldrehung, wenn ein äußerer Taster gedrückt wird, das ist das RECHTS2 bzw. LINKS2, sonst isses ziemlich gleich, Tasterkombinationen finde ich erstmal überflüssig, da das meiner Meinung nach sehr sehr selten zustandekommt):
Code:
#include "asuro.h"
#define k6 taste==1
#define k5 taste==2
#define k4 taste==4
#define k3 taste==8
#define k2 taste==16
#define k1 taste==32
#define WARTEN1 for (i=0; i<500; i++) {Sleep(72);} //warten
#define WARTEN2 for (i=0; i<250; i++) {Sleep(72);} //warten
#define WARTEN3 for (i=0; i<125; i++) {Sleep(72);} //warten
#define VORWERTS BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(180,180); FrontLED(ON);
#define RECHTS1 StatusLED(YELLOW); FrontLED(OFF); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(200,200); WARTEN1; BackLED(ON,OFF); MotorDir(RWD,FWD); WARTEN2;
#define LINKS1 StatusLED(YELLOW); FrontLED(OFF); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(200,200); WARTEN1; BackLED(OFF,ON); MotorDir(FWD,RWD); WARTEN2;
#define RECHTS2 StatusLED(RED); FrontLED(OFF); BackLED(ON,ON); MotorDir (RWD,RWD); MotorSpeed(200,200); WARTEN1; BackLED(ON,OFF); MotorDir(RWD,FWD); WARTEN3;
#define LINKS2 StatusLED(RED); FrontLED(OFF); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(200,200); WARTEN1; BackLED(OFF,ON); MotorDir(FWD,RWD); WARTEN3;
int main(void)
{
char t1, t2, taste;
unsigned int i;
Init();
while(1)
{
t1=PollSwitch();
t2=PollSwitch();
if (t1 && (t1==t2))
{
taste=t1;
if(k6)
{RECHTS2}
else if (k5)
{RECHTS1}
else if (k4)
{RECHTS1}
else if (k3)
{LINKS1}
else if (k2)
{LINKS1}
else if (k1)
{LINKS2}
}
else VORWERTS;
}
return(0);
}
Alles funktioniert super und passt auch, ABER nach einer Weile (manchmal 30s, manchmal auch 2-3 min) "hängt" der sich irgendwie auf. Der macht einmal gar nichts (nur grüne StatusLed leuchtet) oder fährt endlos im Kreis usw.
Ich bin noch ziemlich neu auf diesem Gebiet und wollte mal fragen, was da nicht passt.
Lesezeichen