I've found a Snake game online and for some reason it is not compiling, I think it is something to do with the installed libraries but i'm not sure exactly what.
Here's the Code:
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp
* ----------------------------------------------------------------------------
*/
/**
* Snake Duino v1
*
* Nokia 5110 LCD attached to pins 7, 6, 5, 4, 3
* Active Buzzer attached to pin 8
* Push-buttons attached to pins A2, A3, A4, A5
*
* Inspirated in Snake v1.0, Ouarrak Ayoub
* http://pastebin.com/iAVt9AGJ
*/
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
/* pins */
#define SPEAKER_PIN 8
/* constants */
#define UP 1
#define RIGHT 2
#define DOWN 3
#define LEFT 4
/* frame size */
#define MAX_WIDTH 84
#define MAX_HEIGHT 48
/* defaults */
#define ORIGINAL false
#define SNAKE_LEN 10
/* lcd display */
Adafruit_PCD8544 lcd = Adafruit_PCD8544(7, 6, 5, 4, 3);
int x = 5, y = 5;
/* snake face */
int xC, yC;
/* position food */
int xFood = 0, yFood = 0;
int point = 0, points = 10;
/* directions */
int dr = 0, dc = 1, i;
boolean left = false, right = true, up = false, down = false;
// vetor containing the coordinates of the individual parts
// of the snake {cols[0], row[0]}, corresponding to the head
int snakeCols[260];
// Vector containing the coordinates of the individual parts
// of the snake {cols [snake_lenght], row [snake_lenght]} correspond to the tail
int snakeRow[260];
/* snake lenght */
int snakeLen = SNAKE_LEN;
int level = 0, time = 20;
// sensors input
int btUp, btDown, btRight, btLeft;
void(* reset)(void) = 0;
/*
* setup
*/
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(1));
lcd.begin();
pinMode(SPEAKER_PIN, OUTPUT);
digitalWrite(SPEAKER_PIN, LOW);
xFood = lcd.width() / 2;
yFood = lcd.height() / 2;
intro();
}
/*
* loop
*/
void loop()
{
snake();
}
/*
* snake
*/
void snake()
{
xC = snakeCols[0];
yC = snakeRow[0];
if(point == 0 || point == points)
{
level++;
printLevel();
}
lcd.clearDisplay();
btUp = analogRead(A2);
btLeft = analogRead(A5);
btDown = analogRead(A4);
btRight = analogRead(A3);
moveSnake(btLeft, btRight, btUp, btDown);
// the snake has eaten the food (right or left)
for(int i=0; i < 3; i++)
{
// control the snake's head (x) with x-coordinates of the food
if((xC+1 == xFood) or (xC == xFood+1))
{
// control the snake's head (y) with y-coordinates of the food
if((yC == yFood) or (yC+1 == yFood) or (yC == yFood+1))
{
eatFood();
}
}
// the snake has eaten the food (from above or from bellow)
if((yC == yFood) or (yC == yFood+i))
{
if((xC == xFood) or (xC+i == xFood) or (xC == xFood+i))
{
eatFood();
}
}
}
/* LEFT */
if(left == true)
{
// snake touches the left wall
if(xC == 1) gameover();
if(xC > 1) drawSnake();
}
/* RIGHT */
if(right == true)
{
// snake touches the top wall
if(xC == MAX_WIDTH-1) gameover();
if(xC < MAX_WIDTH-1) drawSnake();
}
/* UP */
if(up == true)
{
// snake touches the above wall
if(yC == 1) gameover();
if(yC > 1) drawSnake();
}
/* DOWN */
if(down == true)
{
// snake touches the ground
if(yC == MAX_HEIGHT-1) gameover();
if(yC < MAX_HEIGHT-1) drawSnake();
}
delay(time);
}
/*
* eatFood
*/
void eatFood()
{
beep(2000, 10);
// increase the point and snake lenght
point++;
snakeLen += 2;
// new coordinates food randonly
xFood = random(1, 80);
yFood = random(1, 46);
drawSnake();
}
/*
* drawSnake
*/
void drawSnake()
{
lcd.drawRect(0, 0, MAX_WIDTH, MAX_HEIGHT, BLACK);
for(int i = snakeLen; i > 0; i--)
{
lcd.drawCircle(snakeCols[i], snakeRow[i], 1, BLACK);
}
lcd.fillRect(xFood, yFood, 3, 3, BLACK);
lcd.display();
for(int i = snakeLen; i > 0; i--)
{
snakeRow[i] = snakeRow[i - 1];
snakeCols[i] = snakeCols[i - 1];
}
snakeRow[0] += dr;
snakeCols[0] += dc;
}
/*
* moveSnake
*/
void moveSnake(int k, int l, int m, int j)
{
/* LEFT */
if(k > 900 and right == false)
{
if((xC > 0 or xC <= lcd.width() - xC))
direc(LEFT);
}
/* RIGHT */
if(l > 900 and left == false)
{
if((xC > 0 or xC <= lcd.width() - xC))
direc(RIGHT);
}
/* UP */
if(m > 900 and down == false)
{
if((yC > 0 or yC <= lcd.height() - yC))
direc(UP);
}
Here is the error Message:
SnakeDuino:42: error: 'Adafruit_PCD8544' does not name a type
Adafruit_PCD8544 lcd = Adafruit_PCD8544(7, 6, 5, 4, 3);
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void setup()':
SnakeDuino:86: error: 'lcd' was not declared in this scope
lcd.begin();
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void snake()':
SnakeDuino:119: error: 'lcd' was not declared in this scope
lcd.clearDisplay();
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void drawSnake()':
SnakeDuino:209: error: 'lcd' was not declared in this scope
lcd.drawRect(0, 0, MAX_WIDTH, MAX_HEIGHT, BLACK);
^
SnakeDuino:209: error: 'BLACK' was not declared in this scope
lcd.drawRect(0, 0, MAX_WIDTH, MAX_HEIGHT, BLACK);
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void moveSnake(int, int, int, int)':
SnakeDuino:237: error: 'lcd' was not declared in this scope
if((xC > 0 or xC <= lcd.width() - xC))
^
SnakeDuino:244: error: 'lcd' was not declared in this scope
if((xC > 0 or xC <= lcd.width() - xC))
^
SnakeDuino:251: error: 'lcd' was not declared in this scope
if((yC > 0 or yC <= lcd.height() - yC))
^
SnakeDuino:258: error: 'lcd' was not declared in this scope
if((yC > 0 or yC <= lcd.height() - yC));
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void showPause()':
SnakeDuino:268: error: 'lcd' was not declared in this scope
lcd.clearDisplay();
^
SnakeDuino:270: error: 'BLACK' was not declared in this scope
lcd.setTextColor(BLACK);
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void printLevel()':
SnakeDuino:290: error: 'lcd' was not declared in this scope
lcd.clearDisplay();
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void gameover()':
SnakeDuino:342: error: 'lcd' was not declared in this scope
lcd.clearDisplay();
^
C:\Users\lachi\AppData\Local\Temp\Temp2_snake-duino-v1-master.zip\snake-duino-v1-master\SnakeDuino\SnakeDuino.ino: In function 'void intro()':
SnakeDuino:395: error: 'lcd' was not declared in this scope
lcd.clearDisplay();
^
SnakeDuino:399: error: 'WHITE' was not declared in this scope
lcd.setTextColor(WHITE, BLACK);
^
SnakeDuino:399: error: 'BLACK' was not declared in this scope
lcd.setTextColor(WHITE, BLACK);
^
exit status 1
'Adafruit_PCD8544' does not name a type
Any help with this would be greatly appreciated