may aim to set/ delta time (4-15 sec)/temp. limit (100-120c)/load press.(4.0-6.0 Bar)/unload press(6.0 - 7.5 Bar)
it is apart of compressor module
my code here
#include <EEPROM.h>
#include <LiquidCrystal.h>
const int rs= 13 , en=12 , d4= 11 , d5= 10, d6=9 , d7= 8 ;
LiquidCrystal lcd(rs , en , d4 ,d5 ,d6 , d7);
// Creates up /down custom characters for the display
byte downArrow[8] = {
0b00100, // *
0b00100, // *
0b00100, // *
0b00100, // *
0b00100, // *
0b10101, // * * *
0b01110, // ***
0b00100 // *
};
byte upArrow[8] = {
0b00100, // *
0b01110, // ***
0b10101, // * * *
0b00100, // *
0b00100, // *
0b00100, // *
0b00100, // *
0b00100 // *
};
// this constant won't change:
const int buttonUp = 2; // up
const int buttonDown = 4; // down
const int buttonEnter = 3; // enter
const int buttonSave = 6; // save
// Variables will change:
int tempLimit = EEPROM.read(20); // temperature limit for alarm
float unLoad = EEPROM.read(10); // pressure limit to unload
float load = EEPROM.read(30); // pressure limit to load
int starTime = EEPROM.read(40); // star to delta time
int counter = 0 ;
int lastChangeMode=0;
int val;
void setup() {
// Creates the byte for the 2 custom characters
lcd.createChar(1, upArrow);
lcd.createChar(2, downArrow);
}
bool changeMode = false;
bool tempChangeMode = false;
bool unLoadChangeMode = false;
bool loadChangeMode = false;
bool starChangeMode = false;
void loop() {
setting();
getCounter();
}
int setting(){
int enterButton = digitalRead(buttonEnter); // enter
if(enterButton == HIGH) {
lastChangeMode = 1;
if(lastChangeMode != changeMode){
changeMode = true;
}
else(changeMode= false);
}
if(changeMode) {
int upButton = digitalRead(buttonUp); //up
int downButton = digitalRead(buttonDown); // down
if (upButton == HIGH) {
counter ++ ;
if (counter>4)counter=4;
delay(200);
}
if (downButton == HIGH) {
counter --;
if (counter<1)counter=1;
delay(200);
}
}
return counter;
}
void getCounter(){
val= counter;
switch(val){
case 0:
drawInstructions();
break;
case 1:
lcd.setCursor(0,1);
lcd.print("Unload prs "+String(unLoad));
delay(150);
drawInstructions();
getUnLoad();
break;
case 2:
lcd.setCursor(0,1);
lcd.print("Load prs "+String(load));
delay(150);
getLoad();
break;
case 3:
lcd.setCursor(0,1);
lcd.print("temp limit "+String(tempLimit));
delay(150);
getTempLimit();
break;
case 4:
lcd.setCursor(0,1);
lcd.print("Star time " + String(starTime));
delay(150);
getStarTime();
break;
}
}
void getLoad(){
loadChangeMode = true ;
int enterButton = digitalRead(buttonEnter); // enter
int upButton = digitalRead(buttonUp); //up
int downButton = digitalRead(buttonDown); // down
int saveButton = digitalRead(buttonSave); // save
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Load: " + String(load) + " Bar");
drawInstructions();
while(loadChangeMode){
float loadCounter = load ;
if(upButton == HIGH){
loadCounter = loadCounter + 0.1 ;
constrain(loadCounter , 4.0 , 6.0 );
}
if(downButton == HIGH){
loadCounter = loadCounter - 0.1 ;
constrain(loadCounter , 4 , 6 );
}
if (saveButton == HIGH){
EEPROM.update(30 , loadCounter);
delay(10);
loadChangeMode = false ;
lcd.setCursor(0,1);
lcd.print("**Data saved**");
delay(500);
lcd.clear();
}
if (enterButton == HIGH){
loadChangeMode = false ;
lcd.clear();
}
}
}
void getUnLoad(){
unLoadChangeMode = true;
int enterButton = digitalRead(buttonEnter); // enter
int upButton = digitalRead(buttonUp); //up
int downButton = digitalRead(buttonDown); // down
int saveButton = digitalRead(buttonSave); // save
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Unload: " + String(unLoad) + " Bar");
while(unLoadChangeMode){
float unLoadCounter = unLoad ;
if(upButton == HIGH){
unLoadCounter = unLoadCounter + 0.1 ;
constrain(unLoadCounter , load , 7.5 );
}
if(downButton == HIGH){
unLoadCounter = unLoadCounter - 0.1 ;
constrain(unLoadCounter , load , 7.5 );
}
if (saveButton == HIGH){
EEPROM.update(10 , unLoadCounter);
delay(10);
unLoadChangeMode = false ;
lcd.setCursor(0,1);
lcd.print("**Data saved**");
delay(500);
lcd.clear();
}
if (enterButton == HIGH){
unLoadChangeMode = false ;
lcd.clear();
}
}
}
void getTempLimit(){
tempChangeMode = true;
int enterButton = digitalRead(buttonEnter); // enter
int upButton = digitalRead(buttonUp); //up
int downButton = digitalRead(buttonDown); // down
int saveButton = digitalRead(buttonSave); // save
lcd.clear();
lcd.setCursor(0,0);
lcd.print("temp Limt: " + String(tempLimit) + " C");
while(tempChangeMode){
int tempCounter = tempLimit ;
if(upButton == HIGH){
tempCounter = tempCounter + 1 ;
constrain(tempCounter , 100 , 120 );
}
if(downButton == HIGH){
tempCounter = tempCounter - 1 ;
constrain(tempCounter , 100 , 120 );
}
if (saveButton == HIGH){
EEPROM.update(20 , tempCounter);
delay(10);
tempChangeMode = false ;
lcd.setCursor(0,1);
lcd.print("**Data saved**");
delay(500);
lcd.clear();
}
if (enterButton == HIGH){
tempChangeMode = false ;
lcd.clear();
}
}
}
void getStarTime(){
starChangeMode = true;
int enterButton = digitalRead(buttonEnter); // enter
int upButton = digitalRead(buttonUp); //up
int downButton = digitalRead(buttonDown); // down
int saveButton = digitalRead(buttonSave); // save
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Star time " + String(starTime) + " Sec");
while(starChangeMode){
int starCounter = starTime ;
if(upButton == HIGH){
starCounter = starCounter + 1 ;
constrain(starCounter , 3 , 15 );
}
if(downButton == HIGH){
starCounter = starCounter - 1 ;
constrain(starCounter , 3 , 15 );
}
if (saveButton == HIGH){
EEPROM.update( 5 , starCounter);
delay(10);
starChangeMode = false ;
lcd.setCursor(0,1);
lcd.print("**Data saved**");
delay(500);
lcd.clear();
}
if (enterButton == HIGH){
starChangeMode = false ;
lcd.clear();
}
}
}
void drawInstructions() {
lcd.setCursor(0, 1); // Set cursor to the bottom line
lcd.print("Use ");
lcd.write(byte(1)); // Up arrow
lcd.print(" / ");
lcd.write(byte(2)); // Down arrow
lcd.print(" buttons");
}
the counter work fine from 1 to 4 when setting function only on the loop
when i add getCounter function i had to press enterbutton with up or down to work
and when i release it i cant back to setting mode any more ..... excuse me for my bad english
Any advice would be greatly appreciated.