Hey guys,
Basically I am creating a class and defining an X and Y variable within the class. I want to create an array of this class. Think I am going somewhere wrong with the syntax. So in relation to my code I want to create an array code arrayTail of size 10 and type XY.
I get this error the line( XY arrayTail;): expected unqualified-id before ‘[’ token
the problem is located at the bottom of my code.
(overall I am to create a programme that creates a snake or line on an LCD screen that moves just as a snake would e.g. winds, in relation to an analogue stick input)
My code:
#include <SPI.h>
#include <EEPROM.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(3,4,5,6,7); //Initialise display object
int lastX;
int tempX;
int lastY;
int tempY;
// analog
int pin_x = 0;
int pin_y = 1;
int initialLength = 5;
void setup(){
Serial.begin(9600); //Begin Serial Communication
display.begin();
display.setContrast(25);
display.clearDisplay();
display.setTextSize(1); //Initial Display
display.setTextColor(BLACK);
}
void loop(){
// read in analogue stick values
int Ax = analogRead(pin_x);
int Ay = analogRead(pin_y);
// map the analogue values to mmatch that of the pixels in the LCD screen
Ax = map(Ax, 0, 660, 0, 84);
Ay = map(Ay, 0, 660, 0, 84);
//Draw the snake
if(Ax != lastX || Ay != lastY)
{
// display.drawLine(Ax,Ay,1,BLACK);
}
display.display();
}
class XY
{
int x;
int y;
};
class Tail
{
XY arrayTail;
Tail()
{
initialize();
}
void initialize()
{
arrayTail = new XY[10];
}
};