Good morning!
I'm working on an O2 analyzer. I've written some code which I've included below.
The code writes a floating point voltage to the SmartGPU screen and seems to work well with one exception, the "lcd.string" output of "Sensor 1,2, & 3" that displays on the screen does not update correctly. The only way to update the output is to reset the SmartGPU OR I have also found that including the following command "lcd.imageSD(0,0,"main7");" inside the "void loop()" function will update the output but it continues to flash repeatedly, can the code be changed to update Sensors 1,2 & 3 without resetting or using the "lcd.imageSD(0,0,"main7")" command?
I've pasted my code below, any help you can provide would be great!
Thank you so much!
Dave
#include <SMARTGPU.h>
#define MULTIPLIER 100
#define aref_voltage 3.0
SMARTGPU lcd;//create LCD object
//****************************O2 SENSOR INPUTS****************************
const int sensor1 = A0; // the analog pin 02 Sensor#1 Vout pin is connected to
int sensorValue1; //declare a variable
const int sensor2 = A1; // the analog pin 02 Sensor#2 Vout pin is connected to
int sensorValue2; // declare a variable
const int sensor3 = A2; // the analog pin 02 sensor#3 Vout pin is connected to
int sensorValue3; // declare a variable
void Display(){
//***************************O2 Sensor 1*********************************//
sensorValue1 = analogRead(sensor1);
float VoltageSensor1 = sensorValue1*aref_voltage;
VoltageSensor1 /= 1024.0;
long lWhole1 = 0;
unsigned long ulPart1 = 0;
lWhole1=(long)((float)VoltageSensor1);// whole part of the number to the left of the decimal point
ulPart1=(long)((float)VoltageSensor1*MULTIPLIER)-lWhole1*MULTIPLIER;// fractional part to the right of the decimal point
char PPO1[1]= "";
sprintf(PPO1, "%li.%02li", lWhole1,ulPart1);
lcd.string(9,70,100,50,GREEN,FONT7,TRANS,PPO1);
//**************************O2 Sensor 2**********************************//
sensorValue2 = analogRead(sensor2);
float VoltageSensor2 = sensorValue2*aref_voltage;
VoltageSensor2 /= 1024.0;
long lWhole2 = 0;
unsigned long ulPart2 = 0;
lWhole2=(long)((float)VoltageSensor2);// whole part of the number to the left of the decimal point
ulPart2=(long)((float)VoltageSensor2*MULTIPLIER)-lWhole2*MULTIPLIER;// fractional part to the right of the decimal point
char PPO2[2]= "";
sprintf(PPO2, "%li.%02li", lWhole2,ulPart2);
lcd.string(123,70,255,65,GREEN,FONT7,TRANS,PPO2);
//***************************O2 Sensor 3*********************************//
sensorValue3 = analogRead(sensor3);
float VoltageSensor3 = sensorValue3*aref_voltage;
VoltageSensor3 /= 1024.0;
long lWhole3 = 0;
unsigned long ulPart3 = 0;
lWhole3=(long)((float)VoltageSensor3);// whole part of the number to left of decimal point
ulPart3=(long)((float)VoltageSensor3*MULTIPLIER)-lWhole3*MULTIPLIER;// fractional part to the right of decimal point
char PPO3[3]= "";
sprintf(PPO3, "%li.%02li", lWhole3,ulPart3);
lcd.string(238,70,320,65,GREEN,FONT7,TRANS,PPO3);
}
void setup(){
lcd.init(); //configure serial and pinout on arduino for SMARTGPU
lcd.start(); //initialize SMARTGPU processor
analogReference(EXTERNAL); // set external analog Ref for PPO output
}
void loop(){
lcd.imageSD(0,0,"main7");
Display();
}