Sub Process_Globals
Public Serial1 As Serial
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RunNative("tftInit", Null)
Do While True
Delay(1000)
RunNative("tftShowVoltage", Null)
Loop
End Sub
#if c
#include "TFT_eSPI.h"
//#define ADC_EN 14 //ADC_EN is the ADC detection enable port
#define ADC_PIN 34
//#define BUTTON_1 35
//#define BUTTON_2 0
TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke custom library
void tftInit(B4R::Object* unused)
{
// pinMode(ADC_EN, OUTPUT);
// digitalWrite(ADC_EN, HIGH);
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
tft.setTextColor(TFT_WHITE);
tft.setTextDatum(MC_DATUM); //centered string
tft.drawString("Hello, world.", tft.width() / 2, tft.height() / 4);
}
void tftShowVoltage(B4R::Object* unused)
{
int vref = 1100;
uint16_t v = analogRead(ADC_PIN);
float battery_voltage = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0);
String voltage = "Voltage :" + String(battery_voltage) + "V";
tft.fillRect(155,135/2-8,62,16,TFT_BLACK); // only erase the value portion of the bitmap
tft.setTextColor(TFT_GREEN);
tft.setCursor(50,60);
tft.print(voltage); // this gives less flashing than .drawString
// tft.fillRect(0,135/2-8,240,14,TFT_BLACK);
// tft.setTextDatum(MC_DATUM);
// tft.drawString(voltage, tft.width() / 2, tft.height() / 2 );
}
#End If