Go Down

Topic: Nokia 5510 LCD pong problem (Read 2156 times) previous topic - next topic

b_river

Jan 14, 2012, 01:27 am Last Edit: Jan 14, 2012, 07:30 pm by b_river Reason: 1
I'm new to the arduino programming scene and I have been trying to make a simple pong game with the nokia 5510 lcd. I am able to display the ball and paddles and update the paddles using a pot. The only problem I'm having is how slow the ball and paddles update. Considering that I only have two delays in the program I think the problem is with the nokia 5510 library I have with it. Can anyone recommend a better library or tell me how to optimize the speed of my program. My code is below. The library files can be found at this link http://ladyada.net/products/nokia5110/, click on download library from github. I would really appreciate any help.


Code: [Select]




#include <nokia_3310_lcd.h>

#include "PCD8544.h"
#include "stdlib.h"

// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
PCD8544 nokia = PCD8544(3, 4, 5, 7, 6);
Nokia_3310_lcd nokia1;

int pot;
int score = 0;
int score1 = 0;
int j = 24;
int nj = 0;
int ni = 0;
int nr = 0;
int i = 42;
int s = 1;
int t = -1;
int r = 0;
int v = 0;



char buf[10];
char buf1[10];
char buf2[10];

void setup(void) {
pinMode(A3,INPUT);
pinMode(10,OUTPUT);
pinMode(2,OUTPUT);
pinMode(13,INPUT);

  nokia.init(40);
 

  digitalWrite(2,HIGH);


}



void loop(void) {
 



digitalWrite(10,LOW);

nokia.fillcircle(i,j,2,WHITE);

nokia.fillrect(0,r,3,16,WHITE);
nokia.fillrect(81,r,3,16,WHITE);



readPot();


if(j == 48)
s = -1;

else if(j == 0)
s=1;


if(i == 84)
t = -1;

else if(i == 3)
{
  if(j < (pot+8) && j > (pot-8))
     t = 1;
  else
  {
     i = 42;
     score++;
     digitalWrite(10,HIGH);
  }
}
else if(i == 81)
{
  if(j < (pot+8) && j > (pot-8))
     t = -1;
  else
  {
     i = 42;
     score1++;
     digitalWrite(10,HIGH);
  }
}

j = j + s;
i = i + t;




nokia.fillrect(0,r,3,16,BLACK);
nokia.fillrect(81,r,3,16,BLACK);
itoa(score,buf2,6);
itoa(score1,buf1,6);
nokia.drawstring(24,0, buf1);
nokia.drawstring(60,0, buf2);

 
nokia.fillcircle(i,j,2,BLACK);
}


 

/*while(digitalRead(13) != 1)
{
nokia.drawstring(20,6,"Press the");
nokia.drawstring(20,20,"Button to");
nokia.drawstring(30,36,"Start");
}
  */                                                   
 






void readPot(void)
{
 
pot = analogRead(A3);
pot =8 + (pot / 20);
r = pot - 8;
 
}




PaulS

Code: [Select]
  while(1)
gane();

What? This is EXACTLY what loop() is for!

Quote
Considering that I only have two delays in the program I think the problem is with the nokia 5510 library I have with it.

The delays don't help, that is for sure. Why do you feel the need to clear the screen on every pass? That is what is killing your response rate. Simply draw where the ball and paddles were, in the background color, and draw the new position in the correct color.
The art of getting good answers lies in asking good questions.

nickgammon

And this:

Quote
Code: [Select]
while(1)
   gane();

}

void loop(void) {
}

...


void game()
{
 while(1)
 {
  ...
 }
}



There is another while(1) inside game. They must be on special!

Plus, how does this work? You call gane() but there is a game() function. Surely not.

Quote
Considering that I only have two delays in the program I think the problem is with the nokia 5510 library


Half-second delays:

Quote
Code: [Select]
delay(500);
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

Quote
click on download library from gethub


GitHub.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

b_river

Thanks for the replies. The two delays are just so when someone scores it sets a led off for a long enough period so you can actually see it. I took them out but the program still runs about the same speed. I tried to redraw the objects in the background color but I don't think I'm doing it right. The ball just flickers and the program runs the same speed. Also I come from a computer science background so I use while(1) loops a lot to debug programs, I guess it's just a habit now.

I updated the code in the original post.

nickgammon

Your main loop seems to be redrawing everything as Paul said. Can't you just draw most of it once, and then move the paddles and ball only?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up