basically I need to implement a pause feature in my game (which is a simplified version of frogger) which stops the logs scrolling, and ignores any other input until the character p is pressed again). The way I've started to implement this in a while loop is to end it once another p Is pressed.

   if(serial_input == 'p' || serial_input == 'P') {

    //need to pause the game

if(serial_input == 'p' || serial_input == 'P')

This is how my logs are currently scrolling: /* The following statements change the scrolling speeds of the individual logs */

            current_time = get_clock_ticks();

    if(is_frog_alive() && current_time >= last_move_time1 + 1000) {
        scroll_lane(0, 1);
        last_move_time1 = current_time;
    } else if(is_frog_alive() && current_time >= last_move_time2 + 600) {
                scroll_lane(1, -1);
                last_move_time2 = current_time;
    } else if(is_frog_alive() && current_time >= last_move_time3 + 800) {
                scroll_lane(2, 1);
                last_move_time3 = current_time;
    } else if(is_frog_alive() && current_time >= last_move_time4 + 900) {
                scroll_log_channel(0, -1);
                last_move_time4 = current_time;
    } else if(is_frog_alive() && current_time >= last_move_time5 + 1200) {
                scroll_log_channel(1, 1);
                last_move_time5 = current_time;

And this is implemented by a timer as described:

* We update a global clock tick variable - whose value
* can be retrieved using the get_clock_ticks() function.

Any suggestions would be greatly appreciated

  • 1
    \$\begingroup\$ Please don't try and remove the original question because it's solved. Either accept an answer if that helped you or post your own answer about how you solved it. Or otherwise you might be able to just delete the question because it doesn't have an upvoted answer. \$\endgroup\$
    – PeterJ
    May 27, 2014 at 11:13

1 Answer 1


I've always used interrupts for handling key presses through the usart.

Have something like this. Just remember to initialise it as per the requirements in your chip's datasheet.

ISR(USART0_RX_vect)  //or USART1 if it's usart 1
    uint8_t inByte = UDR0;   //or UDR1 if it's usart 1

    if(inByte == 'P')
        pauseFlag = TRUE; //declare pauseFlag as a global and make it a volatile type

Then you can use the pause flag however you want in the main code. Just check it in a switch statement that periodically checks key press flags.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.