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 Nokia 3310/5110 LCD tutorial (PCD8544), click on download library from github. I would really appreciate any help.
#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;
}