Hallo V:X,
Weitere Tips und Anregungen sind aber immernoch erwünscht
Noch mehr?
Hier z.B. das Verhalten "RC5 Empfang":
Code:
/*****************************************************************************/
// RC5 Reception Behaviour:
// The TV Remote Control definitions
// ###########################
// Uncomment __one__ (only one!) of the following definitions:
//#define RC_EURO_SKY
//#define RC_PROMO8
#define RC_TOTAL_CONTROL
//#define RC_YOUR_OWN
// ...
// ###########################
// Change the keymapping here:
#ifdef RC_EUROSKY // RC Type: Conrad - EuroSky
#define RC5_KEY_LEFT 22
#define RC5_KEY_RIGHT 21
#define RC5_KEY_FORWARDS 16
#define RC5_KEY_BACKWARDS 17
#define RC5_KEY_STOP 23
#define RC5_KEY_CURVE_LEFT 1
#define RC5_KEY_CURVE_RIGHT 3
#define RC5_KEY_CURVE_BACK_LEFT 7
#define RC5_KEY_CURVE_BACK_RIGHT 9
#define RC5_KEY_LEFT_MOTOR_FWD 1
#define RC5_KEY_LEFT_MOTOR_BWD 7
#define RC5_KEY_RIGHT_MOTOR_FWD 3
#define RC5_KEY_RIGHT_MOTOR_BWD 9
#define RC5_KEY_CONTROL_START ?
#define RC5_KEY_CONTROL_END ?
#endif
#ifdef RC_PROMO8 // RC Type: Conrad - Promo8
#define RC5_KEY_LEFT 21
#define RC5_KEY_RIGHT 22
#define RC5_KEY_FORWARDS 32
#define RC5_KEY_BACKWARDS 33
#define RC5_KEY_STOP 11
#define RC5_KEY_CURVE_LEFT 29
#define RC5_KEY_CURVE_RIGHT 13
#define RC5_KEY_CURVE_BACK_LEFT 10
#define RC5_KEY_CURVE_BACK_RIGHT 62
#define RC5_KEY_LEFT_MOTOR_FWD 1
#define RC5_KEY_LEFT_MOTOR_BWD 7
#define RC5_KEY_RIGHT_MOTOR_FWD 3
#define RC5_KEY_RIGHT_MOTOR_BWD 9
#define RC5_KEY_CONTROL_START ?
#define RC5_KEY_CONTROL_END ?
#endif
#ifdef RC_TOTAL_CONTROL // RC Type: Conrad - TOTAL control
#define RC5_KEY_LEFT 4 // 4
#define RC5_KEY_RIGHT 6 // 6
#define RC5_KEY_FORWARDS 2 // 2
#define RC5_KEY_BACKWARDS 8 // 8
#define RC5_KEY_STOP 5 // 5
#define RC5_KEY_CURVE_LEFT 32 // P+
#define RC5_KEY_CURVE_RIGHT 16 // L+
#define RC5_KEY_CURVE_BACK_LEFT 33 // P-
#define RC5_KEY_CURVE_BACK_RIGHT 17 // L-
#define RC5_KEY_LEFT_MOTOR_FWD 1 // 1
#define RC5_KEY_LEFT_MOTOR_BWD 7 // 7
#define RC5_KEY_RIGHT_MOTOR_FWD 3 // 3
#define RC5_KEY_RIGHT_MOTOR_BWD 9 // 9
#define RC5_KEY_CONTROL_START 23 // ENTER
#define RC5_KEY_CONTROL_END 0 // 0
#endif
#ifdef RC_YOUR_OWN // Your own RC!
#define RC5_KEY_LEFT 4
#define RC5_KEY_RIGHT 6
#define RC5_KEY_FORWARDS 2
#define RC5_KEY_BACKWARDS 8
#define RC5_KEY_STOP 5
#define RC5_KEY_CURVE_LEFT 1
#define RC5_KEY_CURVE_RIGHT 3
#define RC5_KEY_CURVE_BACK_LEFT 7
#define RC5_KEY_CURVE_BACK_RIGHT 9
#define RC5_KEY_LEFT_MOTOR_FWD 10
#define RC5_KEY_LEFT_MOTOR_BWD 11
#define RC5_KEY_RIGHT_MOTOR_FWD 12
#define RC5_KEY_RIGHT_MOTOR_BWD 13
#define RC5_KEY_CONTROL_START ?
#define RC5_KEY_CONTROL_END ?
#endif
//... you can add more Remote control keymappings or implement something
// better than this if you like...
#define RC5RECEPTION_MOVE 1
behaviour_command_t rc5Reception = {0, 0, FWD, false, false, 0, IDLE};
/**
* Behaviour with RC5 Reception.
*/
void behaviour_rc5Reception(void)
{
}
#define RC5RECEPTION_SPEED_ROTATE 60
#define RC5RECEPTION_SPEED_MAX 80
#define RC5RECEPTION_SPEED_L_ARC_LEFT 20
#define RC5RECEPTION_SPEED_L_ARC_RIGHT 80
#define RC5RECEPTION_SPEED_R_ARC_LEFT 80
#define RC5RECEPTION_SPEED_R_ARC_RIGHT 20
/**
* RC5 Event Handler
*/
void receiveRC5Data(RC5data_t rc5data)
{
// Check which key is pressed:
switch(rc5data.key_code)
{
case RC5_KEY_LEFT: // Turn left:
rc5Reception.speed_left = RC5RECEPTION_SPEED_ROTATE;
rc5Reception.speed_right = 0;
rc5Reception.dir = LEFT;
rc5Reception.move = false;
rc5Reception.rotate = true;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_RIGHT: // Turn right:
rc5Reception.speed_left = RC5RECEPTION_SPEED_ROTATE;
rc5Reception.speed_right = 0;
rc5Reception.dir = RIGHT;
rc5Reception.move = false;
rc5Reception.rotate = true;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_FORWARDS: // Move forwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_MAX;
rc5Reception.speed_right = RC5RECEPTION_SPEED_MAX;
rc5Reception.dir = FWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_BACKWARDS: // Move backwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_MAX;
rc5Reception.speed_right = RC5RECEPTION_SPEED_MAX;
rc5Reception.dir = BWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_STOP: // Stop!
rc5Reception.speed_left = 0;
rc5Reception.speed_right = 0;
rc5Reception.dir = FWD;
rc5Reception.move = false;
rc5Reception.rotate = false;
rc5Reception.move_value = 0;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_CURVE_LEFT: // Drive curve left - forwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_L_ARC_LEFT;
rc5Reception.speed_right = RC5RECEPTION_SPEED_L_ARC_RIGHT;
rc5Reception.dir = FWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_CURVE_RIGHT: // Drive curve right - forwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_R_ARC_LEFT;
rc5Reception.speed_right = RC5RECEPTION_SPEED_R_ARC_RIGHT;
rc5Reception.dir = FWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_CURVE_BACK_LEFT: // Drive curve left - backwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_L_ARC_LEFT;
rc5Reception.speed_right = RC5RECEPTION_SPEED_L_ARC_RIGHT;
rc5Reception.dir = BWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_CURVE_BACK_RIGHT: // Drive curve right - backwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_R_ARC_LEFT;
rc5Reception.speed_right = RC5RECEPTION_SPEED_R_ARC_RIGHT;
rc5Reception.dir = BWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_LEFT_MOTOR_FWD: // Only left motor on - forwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_MAX;
rc5Reception.speed_right = 0;
rc5Reception.dir = FWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_LEFT_MOTOR_BWD: // Only left motor on - backwards
rc5Reception.speed_left = RC5RECEPTION_SPEED_MAX;
rc5Reception.speed_right = 0;
rc5Reception.dir = BWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_RIGHT_MOTOR_FWD: // Only right motor on - forwards
rc5Reception.speed_left = 0;
rc5Reception.speed_right = RC5RECEPTION_SPEED_MAX;
rc5Reception.dir = FWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_RIGHT_MOTOR_BWD: // Only right motor on - backwards
rc5Reception.speed_left = 0;
rc5Reception.speed_right = RC5RECEPTION_SPEED_MAX;
rc5Reception.dir = BWD;
rc5Reception.move = true;
rc5Reception.rotate = false;
rc5Reception.move_value = 100;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_CONTROL_START: // Start of the RC5 control mode
rc5Reception.speed_left = 0;
rc5Reception.speed_right = 0;
rc5Reception.dir = FWD;
rc5Reception.move = false;
rc5Reception.rotate = false;
rc5Reception.move_value = 0;
rc5Reception.state = RC5RECEPTION_MOVE;
break;
case RC5_KEY_CONTROL_END: // End of the RC5 control mode
rc5Reception.speed_left = 0;
rc5Reception.speed_right = 0;
rc5Reception.dir = FWD;
rc5Reception.move = false;
rc5Reception.rotate = false;
rc5Reception.move_value = 0;
rc5Reception.state = IDLE;
break;
}
if(rc5Reception.state == RC5RECEPTION_MOVE)
{
if(getStopwatch2() > 500)
{
clearPosLCD(1, 0, 13);
setCursorPosLCD(1, 0);
// Display the received data:
writeStringLCD_P("RC5 ");
writeCharLCD(rc5data.toggle_bit + '0');
writeStringLCD_P(" |");
writeIntegerLCD(rc5data.device, DEC);
writeStringLCD_P(" |");
writeIntegerLCD(rc5data.key_code, DEC);
setStopwatch2(0);
}
}
}
/*****************************************************************************/
Gruß Dirk
Lesezeichen