und an was lag es?
Jetzt hier noch mal das funktionierende ProgrammCode:#include "asuro.h" int main(void) { Init(); int zeit; unsigned char taste; MotorDir(FWD,FWD); MotorSpeed(120,124); StatusLED(GREEN); FrontLED(ON); while (1){ taste=PollSwitch(); if (taste==1) { MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,152); for(zeit=0;zeit<1000;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(180,0); for (zeit=0; zeit<500; zeit++){ Sleep(72);} MotorSpeed(120,124); for(zeit=0;zeit<500;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<500; zeit++){ Sleep(72);} MotorSpeed(120,121); } else if (taste==32) { MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,152); for(zeit=0;zeit<1000;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<500; zeit++){ Sleep(72);} MotorSpeed(120,124); for(zeit=0;zeit<500;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(180,0); for (zeit=0; zeit<500; zeit++){ Sleep(72);} MotorSpeed(120,121); } else if (taste==16 || taste==2) { MotorSpeed(0,0); StatusLED(RED); MotorDir(RWD,RWD); MotorSpeed(120,120); BackLED(ON,ON); for(zeit=0;zeit<1000;zeit++){ Sleep(72);} BackLED(OFF,OFF); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<1000; zeit++){ Sleep(72);} MotorDir(FWD,FWD); MotorSpeed(120,120); } } while(1); return(0); }
Das beste bis jetzt.
und an was lag es?
Ich habe keine Ahnung.
Ich habe das ganze Programm einfach nochmal geschrieben.
Dann hats funktioniert.
Wenn jemand Lust kann er sich ja mal die beiden Programme angucken und die Unterschiede herrausfinden.
Du hast das return(0); aus der while schleife herausgenommen und am schluss noch ein while(1); hingehängt, aber ich glaube das return war ausschlaggebend.
Danke schön!
Den Fehler mache ich nicht wieder
Danke schön!
Daran hats gelegen.
Könnte mir nochmal einer konkret am Programm erklären wie das mit dem mehrfach auslesen der PollSwitch(); Funktion gemeint ist.
es kann passieren, dass einmal falsce werte zurück kommen, deswegen frägt man das ganze 2 mal ab und vergleicht diese. Wenn beide gleich sind, stimmen die Werte.
Ich denke das mit dem Code bekommst du hin. Wenn nicht helfe ich gerne.
Helf mir doch mal lieber.
Ich versteh dieses 2mal abfragen einfach nicht, deswegen wäre es nett wenn du es in den Code einbauen könntest.
Hier nochmal der Code
Code:#include "asuro.h" int main(void) { Init(); int zeit; unsigned char taste; MotorDir(FWD,FWD); MotorSpeed(120,124); StatusLED(GREEN); FrontLED(ON); while (1){ taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); if (taste==1) { MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,151); for(zeit=0;zeit<1000;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<415; zeit++){ Sleep(72);} MotorSpeed(120,121); for(zeit=0;zeit<500;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(180,0); for (zeit=0; zeit<415; zeit++){ Sleep(72);} MotorSpeed(120,121); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); } else if (taste==32) { taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); taste=PollSwitch(); MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,152); for(zeit=0;zeit<1000;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(180,0); for (zeit=0; zeit<415; zeit++){ Sleep(72);} MotorSpeed(120,122); for(zeit=0;zeit<500;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<415; zeit++){ Sleep(72);} MotorSpeed(120,122); } else if (taste==16 || taste==2) { MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,152); for(zeit=0;zeit<1000;zeit++){ Sleep(72);} BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<1000; zeit++){ Sleep(72);} MotorSpeed(120,122); } } return(0); }
So hier ist der fertige Code:
Code:#include "asuro.h" int main(void){ Init(); int zeit; unsigned int taste1, taste2; MotorDir(FWD,FWD); MotorSpeed(120,124); StatusLED(GREEN); FrontLED(ON); while (1){ taste1=PollSwitch(); taste2=PollSwitch(); if(taste1 == taste2){ if (taste == 1){ MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,151); for(zeit=0;zeit<1000;zeit++){ Sleep(72); } BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<415; zeit++){ Sleep(72); } MotorSpeed(120,121); for(zeit=0;zeit<500;zeit++){ Sleep(72); } BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(180,0); for (zeit=0; zeit<415; zeit++){ Sleep(72); } MotorSpeed(120,121); } else if (taste==32){ MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,152); for(zeit=0;zeit<1000;zeit++){ Sleep(72); } BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(180,0); for (zeit=0; zeit<415; zeit++){ Sleep(72); } MotorSpeed(120,122); for(zeit=0;zeit<500;zeit++){ Sleep(72); } BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<415; zeit++){ Sleep(72); } MotorSpeed(120,122); } else if (taste==16 || taste==2){ MotorSpeed(0,0); StatusLED(RED); BackLED(ON,ON); MotorDir(RWD,RWD); MotorSpeed(150,152); for(zeit=0;zeit<1000;zeit++){ Sleep(72); } BackLED(OFF,OFF); StatusLED(GREEN); MotorDir(FWD,FWD); MotorSpeed(0,180); for (zeit=0; zeit<1000; zeit++){ Sleep(72); } MotorSpeed(120,122); } } } while(1); return 0; }
Lesezeichen