Library for drawing screens

Hello, I’m trying to make a library to draw 4 different screens for a GUI in Arduino. I wrote a base sketch that draws each of the screens, and I’ve tested this by commenting out all but one at a time. to verify they display what I want. I’m making functions for these and storing them in a library, so that my main sketch will be cleaner. Currently, my main sketch is just to display each screen for 3 seconds, so that I can verify the functions work. I’m getting many errors. Here’s my current main sketch, header file, library file (had to include only one screen drawing to avoid the posting limit), and the errors I’m getting. I’m sure I’m making some rookie mistakes, as this is my first attempt at a library, so any help is greatly appreciated. Thanks.

Touch_Screen_Test_V3

#include <ScreenDraw.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <MCUFRIEND_kbv.h>


void setup() {
  // put your setup code here, to run once:


}

void loop() {
  // Display screens for 3 seconds, then display the next screen
//ScreenDraw.DrawHomeScreen(); 
//DrawHomeScreen(); 
delay(3000);
//ScreenDraw.DrawPIDSettingsScreen();
delay(3000);
//ScreenDraw.DrawPumpMixerSettingsScreen();
delay(3000);
//ScreenDraw.DrawRecipeSettingsScreen();
delay(3000);

}

ScreenDraw.h

// ScreenDraw.h -Library for drawing screens for Bench Top Brewing System
// Header file includes function defintions for screen drawing


#ifndef ScreenDraw_H
#define ScreenDraw_H

#include <Arduino.h>
class ScreenDraw {
 public:
  void DrawHomeScreen();
  void DrawPIDSettingsScreen();
  void DrawPumpMixerSettingsScreen();
  void DrawRecipeSettingsScreen();
};


#endif

ScreenDraw.cpp

// ScreenDraw.cpp -Library for drawing screens for Bench Top Brewing System
// Header file includes function definitions for screen drawing


#include <Arduino.h>
#include <ScreenDraw.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <MCUFRIEND_kbv.h>

 //(int CS=A3, int RS=A2, int WR=A1, int RD=A0, int RST=A4)
  MCUFRIEND_kbv tft(A3, A2, A1, A0, A4);

  uint16_t ID = tft.readID();
  tft.begin(ID);

void ScreenDraw::DrawHomeScreen()
{
 tft.fillScreen(WHITE); //fillScreen(uint16_t t);
    tft.setRotation(2); //setRotation(uint8_t r) This code rotates the screen. 0=0 , 1=90, 2=180, 3=270
    tft.setCursor(100, 10); //setCursor(int16_t x, int16_t y)
    tft.setTextSize(1.75); //setTextSize(uint8_t s) =1-5
    tft.setTextColor(BLACK, WHITE); //setTextColor(uint16_t t, uint16_t b) t=text color, b=background color
    tft.print("DODGE BREWING SYSTEMS");
    tft.drawFastHLine(0, 30, 320, BLACK); //drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t t)
    tft.setCursor(140, 40); //setCursor(int16_t x, int16_t y)
    tft.setTextSize(2); //setTextSize(uint8_t s) =1-5
    tft.print("HOME");
    tft.drawFastHLine(0, 60, 320, BLACK); //drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t t)
    //drawRoundRect function draws a Rectangle with r radius round corners in x and y location and w width and h height and t color.
    tft.drawRoundRect(10, 440, 69, 30, 5, BLACK); //drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t R , uint16_t t)
    tft.drawRoundRect(80, 440, 69, 30, 5, BLACK); //drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t R , uint16_t t)
    tft.drawRoundRect(150, 440, 69, 30, 5, BLACK); //drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t R , uint16_t t)
    tft.drawRoundRect(220, 440, 69, 30, 5, BLACK); //drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t R , uint16_t t)
    tft.setCursor(15, 445); //setCursor(int16_t x, int16_t y)
    tft.setTextSize(1); //setTextSize(uint8_t s) =1-5
    tft.print("HOME");
    tft.setCursor(85, 445); //setCursor(int16_t x, int16_t y)
    tft.setTextSize(1); //setTextSize(uint8_t s) =1-5
    tft.println("Recipe");
    tft.setCursor(85, 455); //setCursor(int16_t x, int16_t y)
    tft.print("Settings");
    tft.setCursor(155, 445); //setCursor(int16_t x, int16_t y)
    tft.setTextSize(1); //setTextSize(uint8_t s) =1-5
    tft.println("Pump/Mixer");
    tft.setCursor(155, 455); //setCursor(int16_t x, int16_t y)
    tft.print("Settings");
    tft.setCursor(225, 445); //setCursor(int16_t x, int16_t y)
    tft.setTextSize(1); //setTextSize(uint8_t s) =1-5
    tft.println("PID");
    tft.setCursor(225, 455); //setCursor(int16_t x, int16_t y)
    tft.print("Settings");

}

And the errors:

C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:16:3: error: ‘tft’ does not name a type
tft.begin(ID);
^~~
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp: In member function ‘void ScreenDraw::DrawHomeScreen()’:
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:20:17: error: ‘WHITE’ was not declared in this scope
tft.fillScreen(WHITE); //fillScreen(uint16_t t);
^~~~~
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:20:17: note: suggested alternative: ‘WDIE’
tft.fillScreen(WHITE); //fillScreen(uint16_t t);
^~~~~
WDIE
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:24:22: error: ‘BLACK’ was not declared in this scope
tft.setTextColor(BLACK, WHITE); //setTextColor(uint16_t t, uint16_t b) t=text color, b=background color
^~~~~
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp: In member function ‘void ScreenDraw::DrawPIDSettingsScreen()’:
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:59:17: error: ‘WHITE’ was not declared in this scope
tft.fillScreen(WHITE); //fillScreen(uint16_t t);
^~~~~
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:59:17: note: suggested alternative: ‘WDIE’
tft.fillScreen(WHITE); //fillScreen(uint16_t t);
^~~~~
WDIE
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:63:22: error: ‘BLACK’ was not declared in this scope
tft.setTextColor(BLACK, WHITE); //setTextColor(uint16_t t, uint16_t b) t=text color, b=background color
^~~~~
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp: In member function ‘void ScreenDraw::DrawPumpMixerSettingsScreen()’:
C:\Users\dedodge\Documents\Arduino\libraries\ScreenDraw\ScreenDraw.cpp:97:16: error: ‘WHITE’ was not declared in this scope
tft.fillScreen(WHITE); //fillScreen(uint16_t t);
^~~~~

It must be your first attempt at OO as well. There may be other problems, but the worst one I can see is that you have not instantiated any class (haven't made any objects using the class).

Yeah, I tried following the Library tutorial, which has the Morse code example. But I got confused when they have Morse as a class and a function, so that was a little hard to follow. My intent was to have ScreenDraw as a Class, and DrawHomeScreen, DrawPIDSettingsScreen, DrawPumpMixerSettingsScreen, and DrawRecipeSettingsScreen as functions within that class. Are there better examples for me to follow? Thanks.

I’d break it up into multiple processors. One for each screen. Makes life SO MUCH EASIER. And you can grab something like a teensy for <$20.

Then have a master processor that just sends messages to the screen processors. Easy peasy.

-jim lee

Looked at your videos.

What's your plan? Do you have something like a user manual that you're working towards here?

-jim lee

I'm building an arduino controlled home brewing system, for my home use. There are other commercially available controllers, so I'm just developing it for myself.

Yeah, I kinda' got that from the video. What I meant was; What are your plans for the software? Do you have the perfect brewing GUI in your mind? If so, whats it look like?

-jim lee

Not perfect, just good enough. The Gui will have a home screen to operate the system (turn things on and off, put things into standby, etc.) and display current state of system, like temperature of tanks. The other screens are for entering settings, so I don't want them visible all the time.

You could page them on the same display hardware? Home screen would be status and icons to editing pages.

That way you don't have to do all the wiring and keep track of what screen your talking to. Like a smart Phone. Different apps, same screen.

-jim lee