JY-MCU 3208 – Ping Pong Game

Following the previous post, I coded a simple pong game utilising the analog signal to control the bat.

Below are the code snippets. Post a comment below if you want the full code.

C Code – Rendering function

void renderADCToDotArray(uint8_t row, uint8_t column)
{
	if(row >= 8) row = 7;
	if(column >= 32) column = 31;

	byte r = (1 << row);

	byte col=0;
	for (byte i = 0; i < 32; i++) leds[col++] = 0; 	leds[column] = r; } byte renderADCToLineAndDotArray(uint8_t lineRow, uint8_t row, uint8_t column, uint8_t wall) { 	if(lineRow >= 7) lineRow = 6;
	if(lineRow = 8) row = 7;
	if(column >= 32) column = 31;
	if(wall >= 32) wall = 31;

	byte r = (1 << row);
	byte lr = (1<
	byte col=0;
	for (byte i = 0; i < 32; i++) leds[col++] = 0;
	leds[column] = r;
	leds[LinePosition] |= lr;
	leds[wall] = 0xFF;

	return lr;
}

C Code – Main function

int main(void)
{
	uint16_t buffer[4];
	uint8_t score = 0;
	char mode = 1;
	byte row, col;
	char rowSign, colSign;
	row = 0; col = 4;
	rowSign = 1; colSign = 1;
	byte line;
	byte delayTime = MaxSpeed;
	byte delayCount = 0;
	char isGameOver = 0;
	uint8_t wallPosition = 31;

	HTpinsetup();
	HTsetup();
	keysetup();
	clocksetup();

	/* Initialize ADC */
	init_adc();

	sei();               //enable interrupts
	for (byte i=0;i> 5;
				 line = renderADCToLineAndDotArray(line, row, col, wallPosition);
				 if(delayCount > delayTime)
				 {
					 delayCount = 0;
					 if (delayTime > 1)
					 {
						 delayTime = MaxSpeed - (score >> 1);
					 }
					 if(wallPosition > LinePosition)
					 {
						 wallPosition = 31 - (score >> 1);
					 }

					 row = row + (rowSign * 1);
					 if(row >= 7)
					 {
						 rowSign = -1;
					 }
					 else if (row = wallPosition - 1)
					 {
						 colSign = -1;
					 }
					 else if (col 					 {
						 colSign = 1;
					 }

					 if(col == LinePosition)
					 {
						if(((1						}
					 }
					 if(col = 8)
			 {
				 rowSign = -1;
			 }
			 else if (row = 31)
			 {
				 colSign = -1;
			 }
			 else if (col 			 {
				 colSign = 1;
			 }

			 HTsendscreen();
		}
	}
  return(0);
}
This entry was posted in Uncategorized. Bookmark the permalink.

5 Responses to JY-MCU 3208 – Ping Pong Game

  1. Veda says:

    Hi,

    I would like to have the full code 🙂

    Thanks,
    Veda

  2. Rany says:

    Fantastic Project …. 🙂

  3. Jeff Wong says:

    Hello Rudi, saw your screenkey project in your old blog. I have a project which utilizes multiple screenkeys, so if you are interested in some freelance work, please get back to me and we will get into the details. Thanks!

  4. Bárbara says:

    Hello,

    I would like to have the full code.

    Thank you.

  5. luc says:

    HI! i’m interesting in this great hack! please send me the full code! thanks

Leave a Reply

Your email address will not be published. Required fields are marked *