Problem with snake game

So i’m a beginner and i just bought a arduino kit from jaycar and was trying their snake game project here:

When i try to compile the code i get the error

XC3900_Snake_Game_2:4: error: ‘A1’ was not declared in this scope
#define JOYX A1

C:\Users\user\Downloads\XC3900_Snake_Game_2\XC3900_Snake_Game_2.ino:96:16: note: in expansion of macro ‘JOYX’


I don’t know how to fix this and would appreciate help. The code is as follows:

#define MAX7219DIN 4
#define MAX7219CS 5
#define MAX7219CLK 6
#define JOYX A1
#define JOYY A0
#define BUTTON 2
#define SPEAKER 3

byte p[8]={0,0,0,0,0,0,0,0};      //bitmap to display
byte nums[10][3]={                   //bitmap of numbers

byte marquee1[]={0,0,0,0,0,0,0,0,0,127,9,9,6,120,4,4,56,84,84,24,0,72,84,36,0,72,84,36,0,0, 0,  62, 68, 68, 56, 68, 68, 56, 0,  0,  72, 84, 36, 0,  62, 68, 68, 0,  116,  84, 120,  0,  120,  4,  4,  0,  62, 68, 68, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0};
byte marquee2[]={0,0,0,0,0,0,70,73,49,0,56,68,68,0,56,68,68,56,0,120,4,4,0,60,84,92,0,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

char sx[64];                        
char sy[64];                      //snake positions, zeroth is front of snake, first slen are valid
char dir=0;                       //1=up, 2=right, 3=down, 4=left
char slen=0;
int score=0;
char gamestate=0;                 //0=idle, 1=play, 2 =game over
unsigned long tc=1500;             //time between game cycles (~speed/difficulty)

void setup() {

void loop() {
    case 0: doidle(); break;
    case 1: dogame(); break;
    case 2: dogameover(); break;
    case 3: dogameend(); break;

void dogameend(){

void dogameover(){
  static int n=0;
  if(digitalRead(BUTTON)==LOW){   //change modes,
    MAX7219sendbm(marquee1);        //blank screen
    while(digitalRead(BUTTON)==LOW){}// wait til released


void dogame(){
  int i;                //loop variable
  char newx,newy;
  int a;
  if(slen==0){        //game is reset > initialise
  newy=sy[0];     //new snake head position
    case 1: newy=newy-1;break;
    case 2: newx=newx+1;break;
    case 3: newy=newy+1;break;
    case 4: newx=newx-1;break;
  if((newx<0)||(newx>7)||(newy<0)||(newy>7)){     //outside walls > game over
    if((newx==sx[i])&&(newy==sy[i])){gamestate=3;}  //collided with self > game over
  for(i=63;i>0;i--){                             //move old positions
  for(i=0;i<8;i++){p[i]=0;}                   //clear display
  for(i=0;i<slen;i++){                        //draw snake
  score++;                //increase score
  slen=(score+50)/25;    //increase length
  tone(SPEAKER,440,10);  //chirp for game rhythm

void doidle(){
  static int n=0;
  if(digitalRead(BUTTON)==LOW){   //change modes,
    MAX7219sendbm(marquee1);        //blank screen
    tc=200;                         //slow down
    slen=0;                         //reset game
    while(digitalRead(BUTTON)==LOW){}// wait til released

void MAX7219shown(byte n){
  byte s[8];

void MAX7219sendbm(byte p[]){
  for(int i=0;i<8;i++){

void MAX7219brightness(byte b){  //0-15 is range high nybble is ignored
  MAX7219senddata(10,b);        //intensity  

void MAX7219init(){
  digitalWrite(MAX7219CS,HIGH);   //CS off
  digitalWrite(MAX7219CLK,LOW);   //CLK low
  MAX7219senddata(15,0);        //test mode off
  MAX7219senddata(12,1);        //display on
  MAX7219senddata(9,0);         //no decode
  MAX7219senddata(11,7);        //scan all
  for(int i=1;i<9;i++){
    MAX7219senddata(i,0);       //blank all

void MAX7219senddata(byte reg, byte data){
  digitalWrite(MAX7219CS,LOW);   //CS on
  for(int i=128;i>0;i=i>>1){
  digitalWrite(MAX7219CLK,LOW);   //CLK toggle    
  for(int i=128;i>0;i=i>>1){
  digitalWrite(MAX7219CLK,LOW);   //CLK toggle    
  digitalWrite(MAX7219CS,HIGH);   //CS off

That code compiles just fine for me.

You sure you selected the correct board to compile for? I have it set to Pro Mini, so should work for any 328p based boards.

Hi, The code you posted compiles OK for me. Win7 and IDE 1.8.5 for UNO.

Tom... :)

Hi, Please do not cross post.

Which board have you got selected

Threads merged.