Was not declared in this scope

Hey guys, I’m having trouble with the particle dev and my code. It keeps on telling me that I have 5 errors in my code. Can someone help me solve the issues? I’m new at code and don’t understand much so I need as much help as possible! Thank you! :smiley:
Errors: ‘YELLOW’ was not declared in this scope
’Tft’ was not declared in this scope
’CYAN’ was not declared in this scope
’RED’ was not declared in this scope
’BLUE’ was not declared in this scope

Code:

// Draw Circles - Demonstrate drawCircle and fillCircle APIs
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#include <stdint.h>
#ifdef __AVR__
#include <TouchScreen.h>
#else
/* this block is not required anymore
 * #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
 * #define pgm_read_byte_near(addr) (*(const unsigned char *)(addr))
 * #define pgm_read_word(addr) (*(const unsigned short *)(addr))
 * #define pgm_read_word_near(addr) (*(const unsigned short *)(addr))
 */
#endif
#ifdef __AVR__
#include <TFTShield.h>
#else
/* this block is not required anymore
 * #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
 * #define pgm_read_byte_near(addr) (*(const unsigned char *)(addr))
 * #define pgm_read_word(addr) (*(const unsigned short *)(addr))
 * #define pgm_read_word_near(addr) (*(const unsigned short *)(addr))
 */
#endif

#ifdef SEEEDUINO
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 14   // can be a digital pin, this is A0
  #define XP 17   // can be a digital pin, this is A3
#endif

#ifdef MEGA
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 54   // can be a digital pin, this is A0
  #define XP 57   // can be a digital pin, this is A3
#endif

void setup()
{

Tft.init();  //init TFT library

/*  Demo of
    void drawCircle(int poX, int poY, int r,unsigned int color) and
    void fillCircle(int poX, int poY, int r,unsigned int color);
*/
Tft.drawCircle(100, 100, 30,YELLOW);
Tft.drawCircle(100, 200, 40,CYAN);
Tft.fillCircle(200, 100, 30,RED);
Tft.fillCircle(200, 200, 30,BLUE);
}

void loop()
{

}

Exactly what the errors says, those colors are not declared.

Tft.drawCircle(100, 100, 30,YELLOW);

the compiler doesn’t know what ‘YELLOW’ means unless you tell it, hence the complaint.

@Question, with all those conditionals, there is nothing that does an #include "TFTShield.h"; where I suspect those definitions can be found :wink:

@Question, this block was only meant to work around your “‘pgmspace.h’ no such file” error and is not a boiler plate code to just plunk everywhere you’d need to include a header file.

#ifdef __AVR__
#include <TFTShield.h>
#else
/* this block is not required anymore
 * #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
 * #define pgm_read_byte_near(addr) (*(const unsigned char *)(addr))
 * #define pgm_read_word(addr) (*(const unsigned short *)(addr))
 * #define pgm_read_word_near(addr) (*(const unsigned short *)(addr))
 */
#endif

Just do it like this (no angled braces either, unless it’s a system lib)

#include "TouchScreen.h"
#include "TFTShield.h"

I guess you need to actually understand what these #ifdef ... #else ... #endif blocks do.

e.g. you are not defining any touch screen pins at all with that code above :wink:

@ScruffR Can you please explain to me what #ifdef, #else, and #end is? I really want to know so that in the future I learn how to code. :smiley:

#ifdef SEEDUINO
    this stuff is only run if SEEDUINO has been defined previously with a #define SEEDUINO command and has not been undefined before this #ifdef command.
#else
    typical else call. this block runs if SEEDUINO is not declared
#endif
    ends the if - else block.

Do a google search. There are plenty of tutorials on preprocessor operations

1 Like

Just to clarify what @seanM said.
Different platforms and libraries #define some flags/switches/values they need or you might use for your own code.

These statements starting with the hash symbol (#) are compiler directives and for #ifdef, this does not only mean the code is not run but it’s not even compiled into your binary when the condition is not true.

But for a more indepth info do a web search - these basics should be fairly easy to find and are your duty to find for yourself.