Start working on basic hardware support

This commit is contained in:
KemoNine 2020-09-07 22:11:59 -04:00
parent ce63d33a57
commit c9cd379e2d
1 changed files with 31 additions and 0 deletions

View File

@ -3,6 +3,8 @@
// Various library includes
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// 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 <Fonts/FreeMono9pt7b.h>
#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));
}