diff --git a/serial_debugger.ino b/serial_debugger.ino index 1ec0b14..b4c5aa8 100644 --- a/serial_debugger.ino +++ b/serial_debugger.ino @@ -3,6 +3,8 @@ // Various library includes #include +#include +#include // Debugging via serial monitor (don't turn this on unless you're hacking on the firmware code) #define DEBUG true @@ -12,10 +14,26 @@ float measuredVBat; float batteryPercent; +// TFT Setup +#define TFT_CS 9 +#define TFT_DC 10 +Adafruit_ILI9341 tft(TFT_CS, TFT_DC); +#include +#define CHARS_HORIZONTAL 28 +#define CHARS_ROWS 13 + // NeoPixels #define NUMPIXELS 1 Adafruit_NeoPixel pixels(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); +// UI screens +void screenClear(); + +// Color conversion (RGB888 -> RGB565 used by Adafruit GFX) +uint16_t RGB565(uint8_t r, uint8_t g, uint8_t b) { + return ((r & 0b11111000) << 8) | ((g & 0b11111100) << 3) | (b >> 3); +} + void setup() { // Setup red LED to indicate device is on (in case we disable NeoPixel battery level later) pinMode(3, OUTPUT); @@ -32,6 +50,13 @@ void setup() { // Red : pixels.Color(255, 0, 0) pixels.setPixelColor(0, pixels.Color(0, 0, 0)); pixels.show(); + + // Setup TFT + tft.begin(); + tft.setRotation(1); + screenClear(); + tft.println(""); + tft.setFont(&FreeMono9pt7b); } // Measure battery level and change NeoPixel accordingly @@ -66,4 +91,10 @@ void loop() { batteryLevel(); delay(250); +} + +// Clear the screen +void screenClear() { + tft.setCursor(0, 0); + tft.fillScreen(RGB565(0, 0, 0)); } \ No newline at end of file