Hello
I have an Arduino GIGA with the GIGA display shield to capture an analog voltage of a capacitor in a bank of capacitors for an electromagnetic accelerator which is working perfectly. The issue I am having is I want the display on my GIGA Display shield to always show the voltage of the capacitor without having to blank out and redisplay the results every 3 seconds as per my delay. I would just like to have the voltage constantly updating in real time on the Giga Display shield for each capacitor bank. I have the code written for just one capacitor to test things out as shown by my provided code. Programming is not my expertise unfortunately.
Also there may be a bug in my code as it is written as after 40 to 50 refreshes of the GIGA dimply shield to show the voltage, the screen goes blank and the LED flashes until I reset the GIGA R1.
Here is my code for you to evaluate
// 460 Volt measuring program
#include "Arduino_GigaDisplay_GFX.h"
GigaDisplay_GFX display; // create the object
#define BLUE 0x00ff
const float arduinoVCC = 3.3; //Your Arduino voltage
unsigned long ValueR1 = 3000;
unsigned long ValueR2 = 449000;
double Voltage_Source = 450;
const int alanogPin = A0; //the pin connecting the voltage.
const int inputResolution = 1023; //works with most Arduino boards
const float average_of = 500; //Average of 500 readings
float voltage;
void setup() {
Serial.begin(115200);
display.setRotation(1); //Set GIGA Display orientation to landscape mode (Values are 0 - 3)
//delay(500);
}
void loop() {
readVoltage();
Serial.print("Voltage of Cap 1: ");
//Serial.print(voltage);
//Serial.print("V Avg: ");
Serial.print(getVoltageAverage());
Serial.println(" Volts");
//-------------------------------------------------
display.begin(); //init library for GIGA Display
display.fillScreen(BLUE);
display.setCursor(10, 10); //x,y
display.setTextSize(4); //adjust text size
display.print("Capacitor 1 is "); //print
display.print(getVoltageAverage()); //print
display.print(" volts"); //print
//------------------------------------------------
delay(3000); // delay for displaying voltage reading to make it easier to read
} //loop end
void readVoltage() {
int A0Value = analogRead(alanogPin);
float voltage_sensed = A0Value * (arduinoVCC / (float)inputResolution);
// Serial.print("voltage_sensed:");
// Serial.print(voltage_sensed);
voltage = voltage_sensed * (1 + ((float)ValueR2 / (float)ValueR1));
} //readVoltage()
float getVoltageAverage() {
float voltage_temp_average = 0;
for (int i = 0; i < average_of; i++) {
readVoltage();
voltage_temp_average += voltage;
}
return voltage_temp_average / average_of;
} //getVoltageAverage