hi. hello everyone. i want to ask your help how i'm gonna modify this code so that the same push button can be use twice. the current code only allow me to use the same push button once. i want to modify it to so that it fulfill the condition as in the picture attached here.

Your sample uses 5 push button using on analog input and 5 different resistor values. What help do you exactly need with this?Excuse me if I'm wrong, but this sounds a bit like "let the forum do my school work for me". We help you do it but we don't do it for you.

i know. it maybe sound like that. but, this is not a homework actually. i'm juz graduated. i'm juz want to see the pattern. how the programming. perhaps, later maybe with the example, i can modify it to change the program from dual menu to triple menu. that's the way i learn the program. i only learned one semester subject programming. only the basic. and it is not enough. i'm not hoping u guys to do it. perhaps juz give a few hints how to modify the coding. that's all.

At the moment the code simply reads the buttons and prints a message to indicate which one has been pressed. The program has no way of knowing what level of the menu is currently on the screen and what action to take when a button is pressed. What you need to do is implement a state machine with a variable, lets call it state, whose value is changed when a button is pressed so that next time a button is pressed the appropriate action for the current state is taken.

So, in your example you could start with state set to 1 and display the top level menu. If button 1 is pressed you update state to 2 and display the Add Fingerprint menu and wait for a button press. When a button is pressed you check the current state and respond appropriately for that button in that state. For instance, suppose button 5 is designated to exit from the Add Fingerprint menu and it is pressed. You would update state to 1 and display the top level menu ready for another menu item to be selected.

Please do not send me PMs asking for help. Post in the forum then everyone will benefit from seeing the questions and answers.

No ! The number of times the button has been pressed is not relevant. buttonState simply tells the program whether a button is currently pressed or not. The state that I am talking about indicates which level of the menu you are in so that button presses can be interpreted and acted on appropriately . Button 1 will mean different things depending on the current state. To expand on my example, if you are at the top level of the menu and press button 2 this might take you to a menu allowing you to delete fingerprints. That might be state 3. You decide on the state numbers.

Please do not send me PMs asking for help. Post in the forum then everyone will benefit from seeing the questions and answers.

by the way, is this code correct in your opinion. i manage to scroll down to every operation. add fingerprint, delete fingerprint and so on. by when i want to go to second menu, it won't go to the second menu. need advice on that. perhaps maybe something wrong with my coding.

else { // if the current state is LOW then the button // wend from on to off: //lcd.setCursor(0,0); // set lcd.setCursor (column,row) //lcd.print("off"); } } // save the current state as the last state, //for next time through the loop adc_key_in_last = adc_key_in;}

int get_key(unsigned int input){ int k;

for (k = 0; k < NUM_KEYS; k++) { if (input < adc_key_val[k]) {

return k; } }

if (k >= NUM_KEYS) k = -1; // No valid key pressed

return k;}

void addFinger0(){ // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // Print a message to the LCD. lcd.print("Add Fingerprint1"); delay(1500);}

You are still not setting a variable to a value that would indicate which menu is on display so the program does not know what to do when a button is pressed. I see that you have experimented with variable called stateX where X is a number but what you need to do is to have a single variable, maybe call it currentState, whose value indicates which menu is on display.

As a start, list all of the screens to be displayed and allocate each of them a number. This number will be the value to be given to currentState. Now list each of the buttons that might be pressed when each screen is on display and the actions to be taken should the button be pressed.

Screen 1 on display. currentState = 1button 1 pressed. Set currentState to 2 and show screen 2button 2 pressed. Set currentState to 3 and show screen 3button 3 pressed. Set currentState to 4 and show screen 4

let me give a try first. Thank you by the way, correcting me. by the way, how to increase the currentstate so that it won't interpret it as button pressed? i almost got it. with the implementation of &&. thank you for that.

Your code is not updating the value of currentState when you change screens so it will always be the same value.

Look at this again

Screen 1 on display. currentState = 1button 1 pressed. Set currentState to 2 and show screen 2button 2 pressed. Set currentState to 3 and show screen 3button 3 pressed. Set currentState to 4 and show screen 4

NOTE - I deliberately referred to screens rather than menus because when updating a fingerprint, for example, there will not be a menu on the screen, rather a prompt asking for the user to put their finger on the device or press a button to exit. Equally, when a fingerprint has been read you probably need a screen asking for confirmation, but that is up to you.

Please do not send me PMs asking for help. Post in the forum then everyone will benefit from seeing the questions and answers.

Screen 1 on display. currentState = 1button 1 pressed. Set currentState to 2 and show screen 2button 2 pressed. Set currentState to 3 and show screen 3button 3 pressed. Set currentState to 4 and show screen 4