Problems with my code

Hi all, I to have this problem where the board is not compiling. I saw this video on YouTube where they use a touchscreen TFT and they played flappy bird on it and I was trying to recreate it but it wont compile it says.Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: “Arduino Uno”

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino: In function ‘void initiateGame()’:

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:105:30: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

myGLCD.print(“Score:”,5,220);

                          ^

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:107:34: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

                              ^

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:110:37: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

myGLCD.print("Highest Score: ",5,5);

                                 ^

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:112:31: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

myGLCD.print(">RESET<",255,5);

                           ^

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:114:41: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

myGLCD.print(“TAP TO START”,CENTER,100);

                                     ^

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino: In function ‘void gameOver()’:

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:202:39: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

myGLCD.print(“GAME OVER”, CENTER, 40);

                                   ^

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:203:33: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

myGLCD.print(“Score:”, 100, 80);

                             ^

C:\Users\Documents\Arduino\Flapflap\Flapflap.ino:205:44: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

myGLCD.print(“Restarting…”, CENTER, 120);

                                        ^

C:\Users~1\AppData\Local\Temp\ccfaMP9h.ltrans0.ltrans.o: In function `drawBitmap’:

C:\Users\Documents\Arduino\libraries\UTFT/UTFT.cpp:1154: undefined reference to `bird01’

C:\Users\Documents\Arduino\libraries\UTFT/UTFT.cpp:1154: undefined reference to `bird01’

C:\Users\Documents\Arduino\libraries\UTFT/UTFT.cpp:1154: undefined reference to `bird01’

C:\Users\Documents\Arduino\libraries\UTFT/UTFT.cpp:1154: undefined reference to `bird01’

C:\Users\Documents\Arduino\libraries\UTFT/UTFT.cpp:1170: undefined reference to `bird01’

C:\Users~1\AppData\Local\Temp\ccfaMP9h.ltrans0.ltrans.o:C:\Users\ \Documents\Arduino\libraries\UTFT/UTFT.cpp:1170: more undefined references to `bird01’ follow

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Uno.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

@emacaode, it looks like you did not copy the full code.

In the IDE, copy your code using edit → copy for forum and next paste the copied code in a reply.

TOPIC SPLIT
PLEASE DO NOT HIJACK / NECRO POST !

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

@emacaode, your topic was moved to a more suitable location on the forum.

try
myGLCD.print((char*)"Score", 100,80);

1 Like

Thank you I will try that.

It works for that line of code, but do I do it for all of them?

I’m am a beginner I started about 3 months ago. What does that mean?

How are we supposed to know? You still haven’t posted your complete code despite being asked.

BTW most of what you posted were only warnings NOT errors. Warnings can usually be ignored.

Steve

I do ignore them. But they annoy me, so I try to see what the warning is about and eliminate them one by one.

Occasionally, never mind precisely how often, a warning has saved me a great deal of time and pain.

There’s a point when you can know enough to ignore certain warnings. Noobs and for some time post-noobs should

  1. turn on all warnings in the compiler
  2. use warnings as an opportunity to increase general knowledge and confidence

Just sayin’.

a7

1 Like

Here is my code…

/* This program uses the UTFT and URTouch libraries

#include <UTFT.h>
#include <URTouch.h>
#include <EEPROM.h>
//==== Creating Objects
UTFT myGLCD(SSD1289,38,39,40,41); //Parameters should be adjusted to your Display/Schield model
URTouch myTouch( 6, 5, 4, 3, 2);
//==== Defining Fonts
extern uint8_t SmallFont;
extern uint8_t BigFont;
extern uint8_t SevenSegNumFont;
extern unsigned int bird01[0x41A]; // Bird Bitmap
int x, y; // Variables for the coordinates where the display has been pressed
// Floppy Bird
int xP = 319;
int yP = 100;
int yB = 50;
int movingRate = 3;
int fallRateInt = 0;
float fallRate = 0;
int score = 0;
int lastSpeedUpScore = 0;
int highestScore;
boolean screenPressed = false;
boolean gameStarted = false;
void setup() {
// Initiate display
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);

highestScore = EEPROM.read(0); // Read the highest score from the EEPROM

initiateGame(); // Initiate the game
}
void loop() {
xP=xP-movingRate; // xP - x coordinate of the pilars; range: 319 - (-51)
drawPilars(xP, yP); // Draws the pillars

// yB - y coordinate of the bird which depends on value of the fallingRate variable
yB+=fallRateInt; 
fallRate=fallRate+0.4; // Each inetration the fall rate increase so that we can the effect of acceleration/ gravity
fallRateInt= int(fallRate);

// Checks for collision
if(yB>=180 || yB<=0){ // top and bottom
  gameOver();
}
if((xP<=85) && (xP>=5) && (yB<=yP-2)){ // upper pillar
  gameOver();
}
if((xP<=85) && (xP>=5) && (yB>=yP+60)){ // lower pillar
  gameOver();
}

// Draws the bird
drawBird(yB);
// After the pillar has passed through the screen
if (xP<=-51){
  xP=319; // Resets xP to 319
  yP = rand() % 100+20; // Random number for the pillars height
  score++; // Increase score by one
}
//==== Controlling the bird
if (myTouch.dataAvailable()&& !screenPressed) {
   fallRate=-6; // Setting the fallRate negative will make the bird jump
   screenPressed = true;
}
// Doesn't allow holding the screen / you must tap it
else if ( !myTouch.dataAvailable() && screenPressed){
  screenPressed = false;
}

// After each five points, increases the moving rate of the pillars
if ((score - lastSpeedUpScore) == 5) {
  lastSpeedUpScore = score;
  movingRate++;
}

}
// ===== initiateGame - Custom Function
void initiateGame() {
myGLCD.clrScr();
// Blue background
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(0,0,319,239);
// Ground
myGLCD.setColor(221,216,148);
myGLCD.fillRect(0, 215, 319, 239);
myGLCD.setColor(47,175,68);
myGLCD.fillRect(0, 205, 319, 214);
// Text
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(221, 216, 148);
myGLCD.setFont(BigFont);
myGLCD.print(“Score:”,5,220);
myGLCD.setFont(SmallFont);
myGLCD.print(“HIHIHI”, 140, 220);
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(114, 198, 206);
myGLCD.print(“Highest Score: “,5,5);
myGLCD.printNumI(highestScore, 120, 6);
myGLCD.print(”>RESET<”,255,5);
myGLCD.drawLine(0,23,319,23);
myGLCD.print(“TAP TO START”,CENTER,100);

drawBird(yB); // Draws the bird

// Wait until we tap the sreen
while (!gameStarted) {
if (myTouch.dataAvailable()) {
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
// Reset higest score
if ((x>=250) && (x<=319) &&(y>=0) && (y<=28)) {
highestScore = 0;
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(120, 0, 150, 22);
myGLCD.setColor(0, 0, 0);
myGLCD.printNumI(highestScore, 120, 5);
}
if ((x>=0) && (x<=319) &&(y>=30) && (y<=239)) {
gameStarted = true;
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(0, 0, 319, 32);
}
}
}
// Clears the text “TAP TO START” before the game start
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(85, 100, 235, 116);

}
// ===== drawPlillars - Custom Function
void drawPilars(int x, int y) {
if (x>=270){
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(318, 0, x, y-1);
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(319, 0, x-1, y);
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(318, y+81, x, 203);
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(319, y+80, x-1, 204);
}
else if( x<=268) {
// Draws blue rectangle right of the pillar
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x+51, 0, x+60, y);
// Draws the pillar
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(x+49, 1, x+1, y-1);
// Draws the black frame of the pillar
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(x+50, 0, x, y);
// Draws the blue rectangle left of the pillar
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x-1, 0, x-3, y);
// The bottom pillar
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x+51, y+80, x+60, 204);
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(x+49, y+81, x+1, 203);
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(x+50, y+80, x, 204);
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x-1, y+80, x-3, 204);
}
// Draws the score
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(221, 216, 148);
myGLCD.setFont(BigFont);
myGLCD.printNumI(score, 100, 220);
}
//====== drawBird() - Custom Function
void drawBird(int y) {
// Draws the bird - bitmap
myGLCD.drawBitmap (50, y, 35, 30, bird01);
// Draws blue rectangles above and below the bird in order to clear its previus state
myGLCD.setColor(114, 198, 206);
myGLCD.fillRoundRect(50,y,85,y-6);
myGLCD.fillRoundRect(50,y+30,85,y+36);
}
//======== gameOver() - Custom Function
void gameOver() {
delay(3000); // 1 second
// Clears the screen and prints the text
myGLCD.clrScr();
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(BigFont);
myGLCD.print((char*)“GAME OVER”, CENTER , 40);
myGLCD.print((char*)“Score”, 5,220);
myGLCD.printNumI(score,200, 80);
myGLCD.print((char*)“Restarting…”, CENTER, 120);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(2,CENTER, 150);
delay(1000);
myGLCD.printNumI(1,CENTER, 150);
delay(1000);

// Writes the highest score in the EEPROM
if (score > highestScore) {
highestScore = score;
EEPROM.write(0,highestScore);
}
// Resets the variables to start position values
xP=319;
yB=50;
fallRate=0;
score = 0;
lastSpeedUpScore = 0;
movingRate = 3;
gameStarted = false;
// Restart game
initiateGame();
}

Hi,

To add code please click this link;

Thanks… Tom… :grinning: :+1: :coffee: :australia: