expected primary-expression before '(' token

Hi,

I'm currently working with an mcufiend TFT screen, with multiple libraries, one being for touchscreen and the other being a library from mcufriend for graphics.

When I was working on my own code, I verified and got this error message: "expected primary-expression before '(' token".

The code that got that message was "TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);" but it works in the example program. Isn't the primary expression "TouchScreen ts = TouchScreen"? Could someone please help?

The line you listed is fine

look before that line - what else do you have? missing a coma, a bracket or something?

sometimes the parser gets lost and points you at the wrong line or display an incoherent error message

else post more code so that we can have a look.

Here is the whole page of code, with the example and three included libraries attached. This is just a basic hello world program:

/#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
/

//This is from the paint program example

#define YP A1;
#define XM A2;
#define YM 7;
#define XP 6;

#define TS_LEFT 150;
#define TS_RT 930;
#define TS_TOP 130;
#define TS_BOT 920;

#include <SPI.h>
#include “Adafruit_GFX.h”
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

uint16_t identifier;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint tp;

void setup() {
identifier = 0x6809;
tft.begin(identifier);

text();
smilie(YELLOW, BLACK, RED);
}

void loop() {
uint16_t xpos, ypos; //screen coordinates
tp = ts.getPoint();

pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
pinMode(XP, OUTPUT);
pinMode(YM, OUTPUT);

xpos = map(tp.x, TS_LEFT, TS_RT, 0, tft.width());
ypos = map(tp.y, TS_TOP, TS_BOT, 0, tft.height());
}

unsigned long text() {
tft.fillScreen(BLACK);
tft.setCursor(45, 10);
tft.setTextColor(WHITE);
tft.setTextSize(5.5);
if (xpos == 0 && ypos == 0) {
tft.println(“Hello, World!”);
} else {
tft.println(“Owch!”);
}
}
unsigned long smilie(int color1, int color2, int color3) {
tft.fillCircle(120, 200, 100, color1);
tft.fillCircle(80, 175, 25, color2);
tft.fillCircle(160, 175, 25, color2);
tft.fillRoundRect(70, 220, 100, 50, 25, color3);
}

MCUFRIEND_kbv.h (2.15 KB)

Adafruit_GFX.h (4.83 KB)

TouchScreen.h (800 Bytes)

Touch_shield_kbv.ino (10.7 KB)

Hello,

If you truly believe that the line of code where the error is being shown is correct, you should look at the line preceding it. Sometimes something goes wrong on a line of code and that line isn’t “properly ended”. Therefore the compiler starts interpreting the next line with certain expectations and just can’t figure out that line.

Have you noticed that you sometimes use #define with a semicolon and sometimes without?
What do you think is the correct Syntax?
How do you think the Compiler is interpreting that?

JaBa:
Have you noticed that you sometimes use #define with a semicolon and sometimes without?
What do you think is the correct Syntax?
How do you think the Compiler is interpreting that?

Thank you @JaBa I never noticed that. I will test it now. It shouldn't have a semicolon correct?

Unless you want one. It just copies the text verbatim. Generally, you do not want a semicolon.

Thank you, it worked!

I'm glad you got it working.
You know what I like most about programming? The Computer always does exactly what you tell it to do.
You know what I hate most about programming? The Computer always does exactly what you tell it to do.
Sorry to have answered your question with questions, but it got you thinking and in the end, you realized the error.