if (used.item.getName() == "Sump Low.Level"){
lcd.clear();
lcd.setCursor(0,0);lcd.print("Sump Low.Level" ); // tekst dla użytkownika
lcd.setCursor(5,1);lcd.print(sumplowerlevel); // wyświetlamy akt. temperaturę
int Action1=-1;delay(1000);
while(Action1!=4)
{
zm=-1;
Action1=Read_1(0);//delay(300);
if(zm!=Action1)
{
if (Action1==1) {
sumplowerlevel=sumplowerlevel+20;
if(sumplowerlevel>110)sumplowerlevel=100;
lcd.clear(),lcd.setCursor(1,0);lcd.print("Sump Low.Level");
lcd.setCursor(5,1);lcd.print(sumplowerlevel);delay(300);
sumplowerlevel = sumplowerlevel + tankgap;
}
if(Action1==2) {
sumplowerlevel=sumplowerlevel-20;
if(sumplowerlevel<0)sumplowerlevel=0;
lcd.clear(),lcd.setCursor(1,0);lcd.print("Sump Low.Level");
lcd.setCursor(5,1);lcd.print(sumplowerlevel);delay(300);
sumplowerlevel = sumplowerlevel - tankgap;
}
if(Action1==4)
{
lcd.clear();lcd.setCursor(0,0);lcd.print("setLow.Level OK");delay(2000); // pokazujemy OK przez 2 sek.
lcd.setCursor(1,0);lcd.print(" "); // czyścimy linię
lcd.clear();lcd.setCursor(1,0);lcd.print(Line_1); // odtwarzamy poprzedni stan na LCD
}
}
} zm=Action1;
}
//Display
if (used.item.getName() == "Display"){ //i want to display water "tankvolume" here till press back button.tank level should be update.
//update button pressed
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Tank Volume ");
lcd.setCursor(12,0);
lcd.print(tankvolume);
}
// Pump Controlle
if (used.item.getName() == "Auto"){
}
// time display
if (used.item.getName() == "Display"){
}
}
// --- Response to pressing ----------------------------------------- ------------------------
void menuChangeEvent (MenuChangeEvent changed) // function class MenuBackend
{
/* So really it is only here that shortkey useful and is used primarily to enrich the menu
of arrow symbols, whichever is selected. Everything here is going on is displayed on the LCD.
*/
int c = changed.to.getShortkey (); // Fetch shortkey (1,2,3, LUB4)
lcd.clear (); // No comment
lcd.setCursor (0,0);
// i want to display water "tankvolume" here on first lcd row
//second row should display "time"
// then press ok button go to below main menu
if (c == 1) // if the menu Main contacts (shortkey = 1) are:
{
lcd.setCursor(14,0);lcd.write (3); // Left arrow
strcpy (Line_1, changed.to.getName ()); // Create a string in the first line
lcd.setCursor(0,0);lcd.print (Line_1); // Display it
lcd.setCursor (15,0); lcd.write (4); // Right arrow
lcd.setCursor (14,1); lcd.write (5); // Down arrow
lcd.setCursor (15,1); lcd.write (5); // Down arrow
}
if (c == 2) // if the submenu for the child - (shortkey = 2) are:
{
lcd.setCursor (0,0); // Draw a star
strcpy (Line_2, changed.to.getName ()); // Create a string in the first line
lcd.print (Line_1); // Display it
lcd.setCursor (0,1); // Second line and arrow return (arrowBack)
lcd.print (changed.to.getName ()); // Display name of "child"
lcd.setCursor (15,1); lcd.write (7); // Arrow up and down
}
if (c == 3) // if the child has a child - (shortkey = 3) are:
{
lcd.setCursor (0,0); // Star
strcpy (Line_2, changed.to.getName ()); // Copy the files. the name of the menu options to the variable line 2
lcd.print (Line_1); // And display the first line of
lcd.setCursor (0,1); // Second line and arrow arrowBack
lcd.print (changed.to.getName ()); // Display the grandson of the second line
lcd.setCursor (15,1); lcd.write (4); // Right arrow as they are the grandchildren
}
if (c == 4) // if this grandson (shortkey = 4) are:
{
lcd.setCursor (0,0);
lcd.print (Line_2); // Display the first line of the child (or parent grandchild)
lcd.setCursor (0,1); // Second line and arrow arrowBack
lcd.print (changed.to.getName ()); // Display grandson
lcd.setCursor (15,1); lcd.write (7); // Arrow up and down
}
}
/* --- Hereinbelow feature that senses the state of the keyboard ---------------------------------------- ---
I prepared three different versions:
1) for analog keypad with shield LCDanalogKey company DFRobot
2) for the joystick (2 analog inputs and 1 digital pin)
Note for this version option, you must add the function setup configuration for the pin, like this:
pinMode (1, INPUT); digitalWrite (1, HIGH);
3) for the 5-five individual buttons (need 5 digital pins)
Note for this version option, you must add the function setup configuration for the pins, like this:
pinMode (1, INPUT); digitalWrite (1, HIGH);
pinMode (2, INPUT); digitalWrite (2, HIGH);
pinMode (3, INPUT); digitalWrite (3, HIGH);
pinMode (11, INPUT); digitalWrite (11, HIGH);
pinMode (12, INPUT); digitalWrite (12, HIGH);
*/
// --- Version for keyboard 5-button mouse DFRobot ------------------------------------- -
volatile int Read_1(int analog)
{
int stan_Analog = analogRead (analog); delay (30) ;// Serial.println (stan_Analog);
if (stan_Analog> 1000) return -1; // For values outside the range
if (stan_Analog <50) return 0; // Right
if (stan_Analog <150) return 1; // To the top
if (stan_Analog <300) return 2; // Down
if (stan_Analog <500) return 3; // Left
if (stan_Analog <700) return 4; // OK
return -1; // Do not pressed
}
void setup ()
{
Line_1 = new char [16]; // Initialize a pointer to a dynamic text
Line_2 = new char [16]; // Is VERY IMPORTANT because dynamic indicator must indicate
// Pre-defined location in memory. If we did not do
// This sooner or later applet could jump in indefinite
// Close the memory area, which can result in irreversible consequences
// Including switching Fuse Bits!
// Please be careful at all dynamic indicators, SUCH GOOD ADVICE :-)
Serial.begin (9600); // Initialize serial, mainly for test
lcd.begin (16, 2); // Initialize the LCD
lcd.createChar (3, arrowLeft); // Create a memory of your LCD 5 characters for arrows
lcd.createChar (4, arrowRight);
lcd.createChar (5, arrowDown);
lcd.createChar (6, arrowBack);
lcd.createChar (7, arrowUpDown);
pinMode (10,OUTPUT);
pinMode (11,OUTPUT);
pinMode (12,OUTPUT);
pinMode (13,OUTPUT);
digitalWrite (10, HIGH);
/* Here exemplary digital pins for the 3 versions feature Read_3 (1,2,3,11,12)
pinMode (1, INPUT); digitalWrite (1, HIGH);
pinMode (2, INPUT); digitalWrite (2, HIGH);
pinMode (3, INPUT); digitalWrite (3, HIGH);
pinMode (11, INPUT); digitalWrite (11, HIGH);
pinMode (12, INPUT); digitalWrite (12, HIGH);
*/
menuSetup (); // Function MenuBackend class - there really are creating our menu
menu.moveDown (); // Go to the first option - FILE, moveDown because originally we were at the root
// It's like in the Avatar tree roots grow up :-)
}
// --- And it's time for neverending story :-) ------------------------------------ --------
void loop ()
{
x=Read_1(0);delay(30); // Read the state of the keyboard:
/*
I use Read_1 function () because I just Keyboard plugged into A0
If you have a different keypads that use the Read_2 or Read_3 - see description
In addition, you must remember that in the functions obsługo OK button - menuUseEvent (MenuUseEvent used)
Also you need to use the appropriate version of the function read!
*/
if(zm!=x) // if it was the change in the state are:
{
switch(x) // check to see what was pressed
{
case 0: menu.moveRight(); break; // If pressed, move it in the right menu to the right
case 1: menu.moveUp(); break; // Menu to top
case 2: menu.moveDown(); break; // Menu Down
case 3: menu.moveLeft(); break; // Menu to the left
case 4: menu.use(); break; // Pressed OK, so jump to the function menuUseEvent (MenuUseEvend used)
// This function is just serve our menu, check here
// Which option is selected, and here we create code to handle the event.
}
} zm = x; // Assign the value of x variable amended so that the long pressing the
// Same key did not result in the re-generation event.
// getting tank level use analog A1 pin
b = analogRead(A1);
if ((b != 1023) && (b != currx)){
//update screen and change currx
currx = b;
if (currx > 600 && currx < 800){
tankvolume="0 %";
} else if (currx > 300 && currx < 510){
tankvolume="20";
} else if (currx < 10){
tankvolume="40";
} else if (currx > 50 && currx < 150){
tankvolume="60";
} else if (currx > 200 && currx < 300){
tankvolume="80";
}
delay(10);
}
//// getting sump level use analog A2 pin
d = analogRead(A2);
if ((d != 1023) && (d != currx)){
//update screen and change currx
currx = d;
if (currx > 600 && currx < 800){
sumpvolume="0 %";
} else if (currx > 300 && currx < 510){
sumpvolume="20";
} else if (currx < 10){
sumpvolume="40";
} else if (currx > 50 && currx < 150){
sumpvolume="60";
} else if (currx > 200 && currx < 300){
sumpvolume="80";
}
delay(10);
}
autorun();
}
void autorun(){
if ((tanklowerlevel>=tankvolume) && (sumplowerlevel<=sumpvolume)&&(u==1)){
digitalWrite (11,HIGH); // motor on
digitalWrite (12,HIGH); // Buzzer on
digitalWrite (13,HIGH); // LED on
}
if (((tankupperlevel<=tankvolume) || (sumplowerlevel>=sumpvolume))&&(u==1)){
digitalWrite (11,LOW); // motor off
digitalWrite (12,LOW); // Buzzer off
digitalWrite (13,LOW); // LED off
}
}
// === END