Hier ist der gesamte code scheint noch ein fehler drin zu sein.
Code:
#include "RP6RobotBaseLib.h"
#define RC_PROMO8
#ifdef RC_PROMO8
#define RC5_KEY_vorwaertsm 2
#define RC5_KEY_rueckwaertsm 8
#define RC5_KEY_linksm 4
#define RC5_KEY_rechtsm 6
#define RC5_KEY_Ledanm 32
#define RC5_KEY_Ledausm 33
#define RC5_KEY_modus1fernbedienung 7
#define RC5_KEY_modus2linieverfolgen 9
#endif
uint8_t vorwaertsm;
uint8_t rueckwaertsm;
uint8_t rechtsm;
uint8_t linksm;
uint8_t Ledanm;
uint8_t Ledausm;
uint8_t Resetm;
uint8_t mleftptmp;
uint8_t mrightptmp;
uint8_t power_links;
uint8_t power_rechts;
uint8_t mleft_ptmp;
uint8_t mright_ptmp;
uint8_t modus1fernbedienung;
uint8_t modus2linieverfolgen;
void ruecksetzen(void)
{
if(getStopwatch2() > 200)
{
vorwaertsm=0;
rueckwaertsm=0;
linksm=0;
rechtsm=0;
setStopwatch2(0);
}
}
void receiveRC5Data(RC5data_t rc5data)
{writeString_P("Toggle Bit:");
writeChar(rc5data.toggle_bit + '0');
writeString_P(" | Device Address:");
writeInteger(rc5data.device, DEC);
writeString_P(" | Key Code:");
writeInteger(rc5data.key_code, DEC);
writeChar('\n');
switch(rc5data.key_code)
{
case RC5_KEY_vorwaertsm:
writeString_P("vorwaertsm: ");
writeIntegerLength(vorwaertsm, DEC, 4);
writeChar('\n');
writeChar('\n');
vorwaertsm=1; //vorwärts fahren
if(vorwaertsm==1&&modus1fernbedienung==1)
{
move(200,FWD,DIST_MM(150),0);
}
break;
case RC5_KEY_rueckwaertsm:
writeString_P("rueckwaertsm: ");
writeIntegerLength(rueckwaertsm, DEC, 4);
writeChar('\n');
writeChar('\n');
rueckwaertsm=1; //rückwärts fahren
if(rueckwaertsm==1&&modus1fernbedienung==1)
{
move(200,BWD,DIST_MM(150),0);
}
break;
case RC5_KEY_rechtsm:
writeString_P("rechtsm: ");
writeIntegerLength(linksm, DEC, 4);
writeChar('\n');
writeChar('\n');
rechtsm=1; //rechts fahren
if(rechtsm==1&&modus1fernbedienung==1)
{
rotate(50, RIGHT, 55, 0);
}
break;
case RC5_KEY_linksm:
writeString_P("linksm: ");
writeIntegerLength(linksm, DEC, 4);
writeChar('\n');
writeChar('\n');
linksm=1; //links fahren
if(linksm==1&&modus1fernbedienung==1)
{
rotate(50, LEFT, 55, 0);
}
break;
case RC5_KEY_Ledanm:
writeString_P("Ledanm: ");
writeIntegerLength(linksm, DEC, 4);
writeChar('\n');
writeChar('\n');
Ledanm=1; // Ledan:
if(Ledanm==1&&modus2linieverfolgen==1)
{
DDRA|=(E_INT1);
PORTA|=E_INT1;
}
break;
case RC5_KEY_Ledausm:
writeString_P("Ledausm: ");
writeIntegerLength(linksm, DEC, 4);
writeChar('\n');
writeChar('\n');
Ledausm=1;
if(Ledausm==1&&modus2linieverfolgen==1)
{ // Ledaus:
DDRA|=(E_INT1);
PORTA &= ~E_INT1;
}
break;
case RC5_KEY_modus1fernbedienung:
writeString_P("modus1fernbedienung: ");
writeIntegerLength(modus1fernbedienung,DEC, 4);
writeChar('\n');
writeChar('\n'); //Fernbedienung
modus1fernbedienung=1;
modus2linieverfolgen=0;
break;
case RC5_KEY_modus2linieverfolgen:
writeString_P("modus2linieverfolgen: ");
writeIntegerLength(modus2linieverfolgen,DEC, 4);
writeChar('\n');
writeChar('\n'); //Linieverfolgen
modus2linieverfolgen=1;
modus1fernbedienung=0;
break;
}
}
void lichtsensoren (void)
{
writeInteger(readADC(ADC_LS_L), 10);
writeString_P(" - ");
writeInteger(readADC(ADC_LS_R), 10);
writeString_P("\n\r");
if (readADC(ADC_LS_L) > readADC(ADC_LS_R))
{
setLEDs(4);
moveAtSpeed(100,50);
}
else
{
setLEDs(32);
moveAtSpeed(50,100);
}
mSleep(0);
}
int main(void)
{
initRobotBase();
setLEDs(0b111111);
writeChar('\n');
writeString_P("RP6 controlled by RC5 TV Remote\n");
writeString_P("___________________________\n");
mSleep(500);
setLEDs(0b000000);
powerON();
startStopwatch2();// Stopuhr 2 wird gestartet
// Set the RC5 Receive Handler:
IRCOMM_setRC5DataReadyHandler(receiveRC5Data);
// Main loop
while(true)
{
if(modus2linieverfolgen==1)
{
lichtsensoren();
}
task_RP6System();
// Motion Control tasks etc.
} // "
//Reset();
return 0;
}
Lesezeichen