Dear friends and honorable helping Hands,
Currently working on a simple Menu for my Solar Tracker . I am using DIY 12 Keys Keypad that is controlled with only one Analoge Pin of Arduino using "AnalogButtons.h" library. I have mapped the Keypad and all the keys giving me correct results when pressed. Here is the sketch:
AnalogButtons analogButtons(ANALOG_PIN, 30, &handleButtons);
Button b1 = Button(1, 47,50); // Button "1" is pressed when the Analogue Value is between 47 and 50. Normally I am getting consistent 48.
Button b2 = Button(2, 84, 87);
Button b3 = Button(3, 127, 130);
Button b4 = Button(4, 194, 198);
Button b5 = Button(5, 303,309);
Button b6 = Button(6, 405, 410);
Button b7 = Button(7, 546, 549);
Button b8 = Button(8, 690, 695);
Button b9 = Button(9, 780,785);
Button b10 = Button(10, 864, 870);
Button b11 = Button(11, 925, 935);
Button b12= Button(12, 955, 965);
Initializing the values in the Setup:
void setup()
{
Serial.begin(9600);
//Serial.println("Testing your Analog buttons");
//INITIALIZING THE BUTTONS
analogButtons.addButton(b1);
analogButtons.addButton(b2);
analogButtons.addButton(b3);
analogButtons.addButton(b4);
analogButtons.addButton(b5);
analogButtons.addButton(b6);
analogButtons.addButton(b7);
analogButtons.addButton(b8);
analogButtons.addButton(b9);
analogButtons.addButton(b10);
analogButtons.addButton(b11);
analogButtons.addButton(b12);
The following function used to assigned the button values:
void handleButtons(int id, boolean held)
{
if (!held) { ///If the Button is not in contineously pressed or button is pressed and released
if (id==1)(ButtonPressed=1);
if (id==2)(ButtonPressed=2);
if (id==3)(ButtonPressed=3);
if (id==4)(ButtonPressed=4);
if (id==5)(ButtonPressed=5);
if (id==6)(ButtonPressed=6);
if (id==7)(ButtonPressed=7);
if (id==8)(ButtonPressed=8);
if (id==9)(ButtonPressed=9);
if (id==10)(ButtonPressed=11);
if (id==11)(ButtonPressed=0);
if (id==12)(ButtonPressed=12);
}
}
The following function is called inside the Void Loop()
void loop()
{ analogButtons.checkButtons(); // This fuction is required to track the Buttons. On the basis of this , "handleButtons" works.
}
I am also using 3-Wire LCD using Shiftregister. The library is <ShiftRegLCD.h>. I have checked a sample code by pressing any button on the keypad i am getting display of the pressed button on 16x2 LCD.
PROBLEM:
I have developed a Two tier menu that will be expanded more in future. But i am getting problem. Following is the Key map i am using to move within the menu system.
/*
2(^)
(<)4 5(*) 6(>)
8(v)
*/
the following code is compiled and uploaded into Arduino with following observations.
1- initially menuOption is set to 1. so The LCD display
1.SET LIGHTS *
2.VIEW PERAMS
2- When I press the Button 4. I go into idlemenu(). No problem here.
3- In the idlemenu() when i press button2 i go into menuOption=2.
1.SET LIGHTS
2.VIEW PERAMS *
Its again All right
4- Here when i press 2, I am getting
1.SET LIGHTS *
2.VIEW PERAMS *
You can see both '*' up and down. When i see the Serial Monitor I am getting alternate "I am Case 2" and "I am Case 1"
MY Question is Why? Due to Space restraint the complete sketch is being posted in Second Post.