Hi again
I'm currently working on a little project creating a smart watering irrigation probably like lots of other no nothing jabronis during these covid times. My first goal is to get my display screen to accurately update without flickering. To do that I initialized the format in setup (don't mind the "xyz" placeholders I intend to replace them with actual variables) and intend to overwrite the variables as they update in loop, apparently so the whole screen doesn't have to refresh, eliminating flicker, which works. My current problem:
Because the decimal places change I need to erase what's behind the new value. I'm pretty sure from what I read the solution is to draw a rectangle behind it. So my questions are: Is this the best way to fix this? How do I draw a rectangle and what is the most efficient way to do it? (Least amount of code and libraries)
Thanks in advance I'm sure I'm going to have some hall sensor questions next week
Harold
Arduino UNO
OLED 128x64 .92" generic 4 pin
float soilSensor1 = A0;
float VWC1; //Value returned from soil sensor
float sensorVoltage1;
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiAvrI2c oled;
void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL); // use AREF for reference voltage
pinMode(0, INPUT);
#if RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
// Call oled.setI2cClock(frequency) to change from the default frequency.
oled.setFont(Arial_bold_14);
oled.clear();
oled.print("12:00pm");
oled.print(" ");
oled.println("70F");
oled.print("VWC: ");
oled.print(VWC1);
oled.println("%");
oled.print("Last: ");
oled.print("12:52");
oled.println("hrs ago");
oled.print("Total H20: ");
oled.print("25556");
oled.print("g");
}
void loop()
{
float soilSensor1 = analogRead(0);
float sensorVoltage1 = soilSensor1*(3.0 / 1023);
if(sensorVoltage1 <= 1.1) { //Calculate Voltage and VWC of soil sensor on A0
VWC1 = 10*sensorVoltage1 - 1;
} else if(sensorVoltage1 > 1.1 && sensorVoltage1 <= 1.3) {
VWC1 = 25*sensorVoltage1 - 17.5;
} else if(sensorVoltage1 > 1.3 && sensorVoltage1 <= 1.82) {
VWC1 = 48.08*sensorVoltage1 - 47.5;
} else if(sensorVoltage1 > 1.82 && sensorVoltage1 <=2.2) {
VWC1 = 26.32*sensorVoltage1 - 7.89;
} else if(sensorVoltage1 > 2.2) {
VWC1= 62.5*sensorVoltage1 - 87.5;
}
Serial.print("Voltage = ");
Serial.print(sensorVoltage1);
Serial.print(" VWC = ");
Serial.println(VWC1);
oled.setCursor(36,2);
oled.print(VWC1);
oled.print("%");
delay(50);
}