u/Arduino Reddit Subscribers Monitor

Contents

Adding a TFT display - Simple version

In this section, we will add a display panel with a simple display layout. The TFT panel that I will used is this 240x320 LCD panel based upon a uc8230 driver chip. If you do not have one of these (they do not seem very common) then that is OK, you can substitute something similar. You may need to make some adjustments to the code - such as the library to include and some of the API calls, but it should port across to another display type relatively easily as I am only using fairly basic functions.

If you haven't already done so, it may be helpful to read the "Adding a new Display Type" section of the code page. This will provide you with a general overview of how the code is organised and how this new code will "connect up" to the existing code.

In reference to the following diagram, we will be defining a new class that fills in the "Other displays" box.

Arduino Program Class Diagram

Following is a preview of what this display will look like (the simulation is not that great, it looks much better in real life):

Subclassing the Stats class

The Subreddit Stats class is subclassed (or refined) in the SubredditStatsTFT_8230.h file. A subset of the source code is shown below:

#include "SubredditStats.h"

class SubredditStatsTFT : public SubredditStats {
  public:
    void updateDisplay(boolean newData);
    void output(const char * msg);
    void output(const char * msg, int line, int col);
    void initDisplay();

  private:
    unsigned long nextDisplayUpdateTime = 0;

// **** Other stuff omitted for brevity

    void drawBorder(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
    void drawBorder();
};

Note the three display methods declared in the public section: initDisplay(), two variants of output() and updateDisplay().

These are the methods that are "agreed" upon between the various parts of the program - specifically the main part of the program (the monitor) and the display driver (this code) via the Subreddit Stats class definition.

As the TFT display is a more sophisticated than the other displays, there are also a number of private variables and support functions declared to assist in the process of displaying data onto the screen.

The other file SubredditStatsTFT_8230.cpp provides the actual code that draws the display. In this example, the display is only refreshed when new data is received. This is because the TFT display panel can show all of the data on one page. As a result it doesn't need to cycle through the individual values like the "smaller" displays do. As such, if the call to updateDisplay() does not indicate that new data has been received.

Activating the code

To activate the code, all you need to do is place the two files (i.e. SubredditStatsTFT_8230.cpp and SubredditStatsTFT_8230.h) into the same directory as the rest of the project.

Once you have done that locate the declaration of the subredditStats variable in the main program (about line 35 of subredditStatsMonitor.ino) and replace it with the following line of code:

SubredditStatsTFT subredditStats = SubredditStatsTFT();

Code download

Following is the download of the two addon source files mentioned on this page. This is all you need if you already have setup the monitor project.
Simple TFT addon source code.
df597f174d7024f25e4fbd8d00193c1ad7851087665dca3e7ed16decbec43ace *SubredditStatsMonitor-SimpleTFTaddon-v1.00.00.00.zip
If you are just getting started with the monitor, you will need to download the full project source code from the code page.

Please support me if you can

Please help support these projects by: Buy me a coffee - gm310509 Patreon - gm310509