You know what, you're right. I'm looking at an older project where I used this library before, and I totally had to include SPI.h in that file, I just didn't notice. I guess it makes sense - it's like the entire project needs to be told to include that file before the library within the project can be told to include it.
But now I'm having a different problem:
I've got two real files to this program right now. The .ino is the main file where setup() and loop() happen. I'm creating .cpp files for functions involving functions of my TFT screen and servo motors. Right now, I'm just working on the TFT portion, since I've worked with TFT stuff before.
It appears that I have to #include my Adafruit_GFX and Adafruit_ILI9340 libraries in the .ino file and in the .h file of the TFT functions. If don't include it in the .ino file, the CPP file can't find them. However, if I do include it, the complier throws this warning:
Quote:
TFT_Funcs.cpp.o:(.bss.tft+0x0): multiple definition of `tft
RoboArm.ino:(.bss.tft+0x0): first defined here
collect2.exe*:error: ld returned 1 exit status
Error creating .elf
On the other hand, if I roughly chunk all the code into a single .ino file, it works. I think I'm not understanding something here, and while I have your attention, I'd appreciate the help... so I'm going to attach the whole project and the .ino file for reference. Granted - some of the code in this is half-baked and not expected to be visually correct, but it should compile.
Here's the .ino Text:
// TFT_Functions.h
#ifndef _TFT_FUNCS_h
#define _TFT_FUNCS_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#endif
#include <SPI.h>
#include <Adafruit_ILI9340.h>
#include <Adafruit_GFX.h>
#include <FastLED.h>
#include <Metro.h>
#include <FastLED.h>
//Pins
#define SCLK 13
#define MISO 12
#define MOSI 11
#define SCRN_SEL 10
#define DC 9
#define RESET 8
Adafruit_ILI9340 tft = Adafruit_ILI9340(SCRN_SEL, DC, RESET);
//Handy Screen Definitions
#define XCENTER (ILI9340_TFTWIDTH/2)
#define YCENTER (ILI9340_TFTHEIGHT/2)
// X&Y Coords for Various Screen Items
#define EXX 5
#define EXY 5
#define GRPX 10
#define GRPY 5
#define DIALRADIUS 100
//My Colors
#define BLACK 0x000
#define BROWN 0x8200
#define RED 0xF800
#define ORANGE 0xFCA0
#define YELLOW 0xFFE0
#define GREEN 0x07E0
#define BLUE 0x001F
#define VIOLET 0x9199
#define GRAY 0x7BEF
#define WHITE 0xFFFF
void startSplash(),
plotExtension(),
plotGrip(),
plotYaw(),
drawElements();
void startSplash() {
tft.begin();
tft.fillScreen(ILI9340_BLACK);
tft.setTextColor(ILI9340_WHITE);
tft.setTextSize(8);
tft.setCursor(10, 10);
tft.print("Servo Arm Beta Test");
tft.drawCircle(XCENTER, YCENTER, 30, RED);
}
void cycleSplash(bool isLoading) {
}
void drawElements() {
tft.fillScreen(ILI9340_BLACK);
//Draw bar for Extension Meter
tft.fillRect(EXX, EXY, 3, 210, GRAY);
//Draw bar for Grip Bar
tft.fillRect(GRPX, GRPY, 310, 3, GRAY);
//Draw Dial Area for Yaw
tft.fillCircle(XCENTER, ILI9340_TFTHEIGHT, DIALRADIUS, GRAY);
}
void plotExtension(int extension) {
static int pExtension;
//First Easy Concept: Plot the extension on a vertical bar on the left hand side of the screen.
if (pExtension != extension) {
//erase the old lines
int pExtPos = map(pExtension, 0, 180, 7, 208);
tft.fillRect(EXX, pExtPos - 1, 3, 3, GRAY);
//Draw new ones
int extPos = map(extension, 0, 180, 7, 208);
tft.fillRect(EXX, extPos - 1, 3, 3, ORANGE);
}
//store value for next loop
pExtension = extension;
}
void plotGrip(int grip) {
//Show the grip bar as two lines that grow from the edges of the bar to meet in the center.
static int pGrip;
if (grip > pGrip) {
//uint8_t barDisplace = map(grip, 0, 180, 0, 105);
}
//Store that forthe next round
pGrip = grip;
}
void plotYaw(int yaw) {
//Harder Concept: Plot the Yaw on a half-Dial.Pythagoras!
//TODO: Having division of 0 or 1 could be a problem.... we'll just see how that shakes out I guess.
static int pYaw;
static int pYawPosX;
static int pYawPosY;
if (pYaw != yaw) {
//erase the old line
tft.drawLine(XCENTER, ILI9340_TFTHEIGHT, pYawPosX, pYawPosY, GRAY);
//First, find the X coordinate of the dial position. All servos are given as a 0-180 value.
int yawPosX = map(yaw, 0, 180, XCENTER - DIALRADIUS, XCENTER + DIALRADIUS);
//Calcualte Y value by making a right triangle.
int ySquared = sq(pYawPosX / 2) - sq(DIALRADIUS);
int yawPosY = sqrt16(ySquared);
tft.drawLine(XCENTER, ILI9340_TFTHEIGHT, yawPosX, yawPosY, ORANGE);
//store some of these as static variables for the next go around
pYaw = yaw;
pYawPosX = yawPosX;
pYawPosY = yawPosY;
}
}
void setup()
{
startSplash();
drawElements();
/* add setup code here */
}
void loop()
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
}