///< CONFIG: Must be configured for proper platform
///< CONFIG: Config 0=IDE MODE, Config 1=WOKII MODE
#define CONFIG 1
#if CONFIG == 0
#define CONFIG_TEXT "IDE"
#elif CONFIG == 1
#define CONFIG_TEXT "WOKII"
#endif
///< INCLUDE: This includes all variables, defintions, libraries & drivers required
///< INCLUDE:
#include "include.h"
void setup() {
Serial.begin(Serial_Baudrate);
Serial.println();
Serial.print("Configuration Mode: ");
Serial.println(CONFIG_TEXT);
Serial.println("Serial Comm is online");
randomSeed(analogRead(0));
tft.begin();
// tft.sendCommand(0xC6, &rtna, 1);
#if CONFIG == 0
tft.setRotation(2);
#else
tft.setRotation(0);
#endif
// tft.setFont(&digital_font); //
tft.setTextSize(digital_fontsize);
tft.setTextColor(digital_fontcolor);
BKGCOLOR = ANTIQUEWHITE;
tft.cp437(true);
tft.setSPISpeed(SPI_Speed); // 1,000,000 default & 4,000,000 MAX
tft.fillScreen(BKGCOLOR);
pivot_x = center_x; // Pivot Point X - Needle
pivot_y = center_y + Needle_TipPostion; // Pivot Point Y - Needle
p1_x_old = center_x;
p1_y_old = center_y + 30;
p2_x_old = center_x;
p2_y_old = center_y + 30;
p3_x_old = center_x;
p3_y_old = center_y + 30;
p4_x_old = center_x;
p4_y_old = center_y + 30;
p5_x_old = center_x;
p5_y_old = center_y + 30;
// create_dial();
needleAngle = (((needle_setter)*DEG2RAD * 1.8) - PI);
tft.setFont(&text_font); //
tft.setTextSize(text_fontsize);
tft.setTextColor(text_fontcolor);
calcMaxChSize(); // calculate number of pixels required for a character
// tempString = "BLACK";
// ww = (tempString.length() * (chMax / 2)) / 2;
// tft.setCursor(center_x - ww, center_y);
// tft.print("BLACK");
create_dial();
if (override_volt == 0) {
volt = random(min_value, max_value); // voltage simulator
averagedVoltage = movingAverage(volt);
} else {
volt = override_volt; // voltage simulator
averagedVoltage = movingAverage(volt);
}
needle(averagedVoltage);
}
void loop() {
iteration++;
if ((millis() - lastTouch) > threshold) { // millis() is compare to lastTouch & threshold to prevent DEBOUNCE
lastTouch = millis();
if (override_volt == 0) {
volt = random(min_value, max_value); // voltage simulator
averagedVoltage = movingAverage(volt);
} else {
volt = override_volt; // voltage simulator
averagedVoltage = movingAverage(volt);
}
needle(averagedVoltage);
displayNumerical();
// AC = true;
}
delay(1000);
// BusVoltage = ESP.getVcc();
}
double movingAverage(double val) {
const byte nvalues = 10; // rolling average window size
static double moving_values[nvalues];
static byte current = 0; // index for current value
static byte cvalues = 0; // count of values read (<= nvalues)
static double sum = 0; // rolling sum
sum += val;
if (cvalues == nvalues) // if the window is full, adjust the sum by deleting the oldest value
sum -= moving_values[current];
moving_values[current] = val; // replace the oldest with the latest
if (++current >= nvalues)
current = 0;
if (cvalues < nvalues)
cvalues += 1;
return sum / cvalues;
}