Code:
#include "asuro.h"
unsigned char right;
unsigned char left;
unsigned char time;
unsigned char dir;
void motorcontrol(unsigned char dir, unsigned char left, unsigned char right, unsigned char time){
int counter = 0;
if(dir == 2){
MotorDir(FWD,FWD);
}
else if(dir == 1) {
MotorDir(RWD,RWD);
}
else if(dir == 0){
MotorDir(BREAK,BREAK);
}
MotorSpeed(left,right);
if(left+10 > right){
BackLED(ON,OFF);
}
else if(left+10 < right){
BackLED(OFF,ON);
}
else{
BackLED(OFF,OFF);
}
do{
Sleep(255);
counter++;
}
while(time >= counter);
}
int switchcontrol(){
if(PollSwitch()==0){
dir = 2;
right = 255;
left = 245;
time = 0;
motorcontrol(dir, left, right, time);
return 0;
}
else if(PollSwitch()==32){
dir = 1;
right = 255;
left = 245;
time = 255;
motorcontrol(dir, left, right, time);
dir = 2;
right = 200;
left = 255;
time = 255;
motorcontrol(dir, left, right, time);
return 0;
}
else if(PollSwitch()==16){
dir = 1;
right = 255;
left = 245;
time = 255;
motorcontrol(dir, left, right, time);
dir = 2;
right = 175;
left = 255;
time = 255;
motorcontrol(dir, left, right, time);
return 0;
}
else if(PollSwitch()==8){
dir = 1;
right = 0;
left = 245;
time = 223;
motorcontrol(dir, left, right, time);
dir = 2;
right = 255;
left = 0;
time = 223;
motorcontrol(dir, left,right,time);
return 0;
}
else if(PollSwitch()==4){
dir = 1;
right = 255;
left = 0;
time = 223;
motorcontrol(dir, left, right, time);
dir = 2;
right = 0;
left = 245;
time = 223;
motorcontrol(dir, left, right, time);
return 0;
}
else if(PollSwitch()==2){
dir = 1;
right = 255;
left = 245;
time = 255;
motorcontrol(dir, left, right, time);
dir = 2;
right = 255;
left = 175;
time = 255;
motorcontrol(dir, left, right, time);
return 0;
}
else if(PollSwitch()==1){
dir = 1;
right = 255;
left = 245;
time = 255;
motorcontrol(dir, left, right, time);
dir = 2;
right = 255;
left = 200;
time = 255;
motorcontrol(dir, left, right, time);
return 0;
}
else if(PollSwitch()>32){
dir = 1;
right = 255;
left = 245;
time = 255;
motorcontrol(dir, left, right, time);
motorcontrol(dir, left,right, time);
motorcontrol(dir, left, right, time);
dir = 2;
right = 255;
left = 0;
time = 200;
motorcontrol(dir, left, right, time);
return 0;
}
}
int statuscontrol(){
StatusLED(GREEN);
int retval;
SerWrite("Programm startet!\n\r",21);
while(1){
retval = switchcontrol();
if(retval == 0){
SerWrite("Alles in Ordnung!\n\r",21);
BackLED(OFF,OFF);
}
else if(retval==1){
SerWrite("Steuerungsfehler!\n\r",21);
break;
}
else {
SerWrite("Unbekannter Fehler!\n\r",22);
dir = 0;
right = 0;
left = 0;
time = 0;
motorcontrol(dir, right, left, time);
BackLED(OFF,OFF);
break;
}
}
while(1){
StatusLED(RED);
dir = 0;
right = 0;
left = 0;
time = 0;
motorcontrol(dir, right, left, time);
BackLED(OFF,OFF);
SerWrite("Ende!\n\r",8);
while(1){
Sleep(255);
}
}
return 0;
}
int main(void){
Init();
while(1){
int statuscontrol();
}
return 0;
}
Das ist ein Beispiel, aber bei mehreren anderen Programmen gibt´s das Problem auch.
Lesezeichen