I am afraid it will be more confusing:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//LiquidCrystal_I2C lcd(0x38, BACKLIGHT_PIN, POSITIVE); // Set the LCD I2C address
String stringOne, stringTwo, stringThree;
// Creat a set of new characters
const uint8_t charBitmap[][8] = {
{
0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 }
,
{
0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 }
,
{
0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 }
,
{
0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 }
,
{
0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 }
,
{
0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 }
,
{
0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 }
,
{
0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
};
#include "SevSeg.h"
//Create an instance of the object.
SevSeg sevseg;
//Create global variables
unsigned long timer;
int CentSec=0;
int digit=1;
unsigned long timeupstart=0;
unsigned long timeup=0;
unsigned long burstup=0;
float leakrate=100;
int j=1;
void setup() {
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
// Switch on the backlight
pinMode ( BACKLIGHT_PIN, OUTPUT );
digitalWrite ( BACKLIGHT_PIN, HIGH );
stringOne = String("Hello ");
stringTwo = String("world!");
// stringThree = String ();
stringThree = stringOne + stringTwo;
lcd.begin(16,2); // initialize the lcd
for ( int i = 0; i < charBitmapSize; i++ )
{
lcd.createChar ( i, (uint8_t *)charBitmap[i] );
}
lcd.home (); // go home
lcd.print(stringThree);
lcd.setCursor ( 0, 1 ); // go to the next line
lcd.print ("Wow what a rockt");
delay ( 200 );
pinMode(A4, OUTPUT);
digitalWrite(A4, LOW);
pinMode(A5, OUTPUT);
digitalWrite(A5, LOW);
//I am using a common cathode display 0, with the digit pins connected
//from 2-5 and the segment pins connected from 6-13
sevseg.Begin(0,4,3,2,1,12,11,10,9,8,7,6,5); //11+10 6 5ok 7 9 8
timer=millis();
}
void loop() {
//Produce an output on the display
sevseg.PrintOutput();
//Check if 10ms has elapsed
unsigned long mils=millis();
float refreshrate=1000;
if (mils-timer>=refreshrate) { //was 10
timer=mils;
// CentSec++; //was 0.01s counter
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
float voltage = sensorValue * 0.004888; //(5.0 / 1023.0);
float milivolt = voltage * 1000;
// VOUT = VS (P x 0.009 + 0.04)-0.4
float pressure = (voltage * 24 )+ 10+ (4.066 * (-1.78)); //typical 100kpa -1.78=22.22-24
float negative = (pressure * 10)-1000;
//negative = 81.;
sevseg.NewNum((negative),(byte) 2);
//negative = 81;
leakrate = ((1000 * timeup) / timer);
sevseg.NewNum((negative),(byte) 4);
lcd.clear ();
lcd.home (); // go home
//negative=-99.5; //test value
if (negative >= 99.5) {
lcd.setCursor ( 1, 0 );
lcd.print(negative,0);
}
else {
if (negative>= 9.5) {
lcd.setCursor (2, 0);
lcd.print(negative,0);
}
else {
if (negative>=0) {
lcd.setCursor (3, 0 );
lcd.print(negative,0);
}
else {
if( negative>-9.5){
lcd.setCursor (2, 0);
lcd.print(negative,0);
}
else {
if( negative>-99.5){
lcd.setCursor (1, 0);
lcd.print(negative,0);
}
else {
lcd.setCursor (0, 0);
lcd.print(negative,0);
}
}
}
}
}
digitalWrite(A1, HIGH); //debug only
digitalWrite(A2, LOW); //debug only
digitalWrite(A3, LOW); //debug only
for (int i=0 ; i<4 ; i++ ) {
lcd.setCursor ((4+3*i),2);
lcd.print(digitalRead((15+i)));
//lcd.print(HIGH);
}
lcd.setCursor ( 8,1);
//lcd.print(digit,1);
lcd.setCursor ( 8, 0 );
lcd.print(milivolt,0);
lcd.setCursor ( 0, 1 ); // go to the next line
lcd.print (leakrate,0);
// sevseg.NewNum((negative),(byte) 4);
if (pressure>52) { //30kpa depression -0.3bar
digitalWrite(A1, HIGH);
digitalWrite(A2, HIGH);
digitalWrite(A3, HIGH);
timeup=timeup+refreshrate;
burstup=burstup+refreshrate;
}
else {
if (pressure>=47) { //hysterisis
if (j>0) {
timeup=0;
j=0;
}
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
digitalWrite(A3, LOW);
burstup=0;
}
}
}
}
I am trying to show on a lcd a 1 for a working motor, switched by A1 A2 or A3 or a 0 if it is not working.
The main stuff consist of a vacuum sensor, 3 fridges motor units as pumps(activated through switchtail (ssr in a case)) a 2x16 lcd reading and a 4digit reading that will soon disappear (I started with that, now moving on to i2c). Currently I did not code all the features. I plan to switch between pumps and ramp up if needed or if one pump is failing. These fridge motors are not made to work 24h in a row, so alternating, and ventilating, will keep them cooler.