Arduino compatible LCD pong clock.

Here’s a write-up detailing (well, glossing over, really) my journey:

http://robparrett.com/pongclock

And here’s all of my code, the schematic, pcb, and stl for the case:

Really cool idea. I love it! You should sell the kits and I'll grab one.

Mike

very inspiring project, and thanks for documenting it. good job!

Thanks again for your excellent pong clock project. I liked it so much that I modified the code for an 0.96" oled i2c display: http://www.youtube.com/watch?v=QsEBQTWX3SQ My code still has a few bugs like missing the ball every minute and hour but it's getting there.

Mike

Hello,

I have translated the original code that bertomg wrote to Mike’s hardware and works great.

Also I have fixed a critical bug that prevents paddle from missing the ball. Original code (line 361):

 if (newminute && ball_dx == 1) {
    if (target_y < h - paddle_h) {
      target_y = target_y - paddle_h;
    } else {
      target_y = target_y + paddle_h;
    }
  } else if (newhour && ball_dx == -1) {
    if (target_y < h - paddle_h) {
      target_y = target_y - paddle_h;
    } else {
      target_y = target_y + paddle_h;
    }
  }

Should be:

 if (newminute && ball_dx == 1) {
    if (target_y > h - paddle_h) {
      target_y = target_y - paddle_h;
    } else {
      target_y = target_y + paddle_h;
    }
  } else if (newhour && ball_dx == -1) {
    if (target_y > h - paddle_h) {
      target_y = target_y - paddle_h;
    } else {
      target_y = target_y + paddle_h;
    }
  }

This gave me a little headache :stuck_out_tongue:

I have also corrected two more bugs.

The first one is that on the score board. Minutes increments when right player loses meanwhile hours increments when left player loses. This is the opposite behavior that is supposed to be; in original pong game, the right score board increments when right player wins (or left player loses) and vice versa. This is the code with the fix:

  if (newminute && ball_dx == -1) {
    if (target_y > h - paddle_h) {
      target_y = target_y - paddle_h;
    } else {
      target_y = target_y + paddle_h;
    }
  } else if (newhour && ball_dx == 1) {
    if (target_y > h - paddle_h) {
      target_y = target_y - paddle_h;
    } else {
      target_y = target_y + paddle_h;
    }
  }

Basically, changes 1 to -1 and -1 to 1.

The second bug is that when hour changes, both flags newhour and newminute are set to 1 so both of them can lose the game. Some times loses hours, and some times loses the minutes. This is easily fixed in the keeptime() function:

void keeptime() {
  if (second >= 59) {
    newminute = 1;
    second = 0;
    minute = minute + 1;
  }

  if (minute == 00) {
    newminute = 0;
    newhour = 1;
    minute = 0;
    hour = hour + 1;
  }

  if (hour > 12) {
    hour = 1;
  }
}

The diference between the original code and the proposed code is that when we set newhour to 1, we also set new minute to 0 so we ensure that only right player loses to increment left player score (hours).

Hey guys, really glad you enjoyed my project. It's really cool to see it show up on someone else's hardware.

Thanks for not even mentioning the typo that made the sketch not even compile, and sorry for the headaches!

I gave away my finished hardware long ago, but I booted the sketch up on one of the prototypes and observed all the bugs you mentioned. Your fixes are spot-on, so thank you!