Normally with a button you trigger the Arduino by pushing it and allowing electricity to flow. Is there any way to trigger it when it is RELEASED while still keeping regular function?
Take a look at the different modes for the interrupt function...
http://arduino.cc/en/Reference/AttachInterrupt
You could either use the rising mode or the change mode. When using the change mode, read the value of the pin to see if it is high or low.
Sorry, I should have been more specific. I have a GLCD with a sort of menu system set up. To change what is selected, you hold a "select" button and press an up or down key. Then just use those same up or down keys to change the value of what is selected.
This works fine, however I'd like to add additional menus which cycle by just pressing the select button. If I simply read the state of the select button, I can't use my press+hold method because it will trigger the menu cycle.
I hope this makes sense...
Maybe I'm just being dull, but I'm having a hard time understanding what you want to do. Tap "select" opens a menu..? Then you want to be able to scroll through that menu and and tap "select" when on the desired topic which opens yet another menu? Are you looking for a sort of "wasTapped" thing?
When I want to detect a "wasTapped" type of event I do something like(pseudo code):
if(digitalRead(selectPin) == HIGH) {
boolean buttonPressed = true; //says button was pressed
}
//in your menu stuff
if(digitalRead(selectPin) == HIGH && buttonPressed) { //if button is pressed and has been before, open next menu
open appropriate menu now
buttonPressed = false; //resets buttonPressed
}
I hope that's helpful.
[edit]My pseudo code assumes a button press results in an electrical HIGH on selectPin. So this may need to be changed depending on your circuit.[/edit]
Sort of. Lemme try to break this down...
I have three buttons. A select, an up, and a down.
If I press and hold select AND up, it moves up an option. The same is true with the down button.
If I just use the up or down button, it changes the value of the selected option.
Now, I want to add a WHOLE NEW MENU(S). A different screen with different options. To get to these, I want to be able to cycle through them by just pressing the select button.
This is the problem. If I just see if the select button is HIGH or LOW, I can't use the press+hold method because it'll cycle through the menus before you can press up or down button.
I'll make a video if this doesn't help.
Perhaps adding a simple function that decides if select is in "hold" state or just being tapped? Say.. if select is HIGH for > some threshold. Maybe 500mS or something. I am sure that there is some nice elegant solution to this problem. Can you post your code? I am familiar with glcd code..
Then I'm a little confused as to how I would do that. There is a 100ms delay at the end of the code as I am also taking information from a sensor and displaying it. The fact it would cycle by holding it down is a by-product of that and not at all necessary.
I would post the code, but it's spanned over three tabs at this point and very long...
EDIT: Oh, I'll also say the reason this is such a problem is because in general you press the select button BEFORE the up or down.
Just add a counter to the select button ( = keep track of which new menu item is selected). Then another variable (boolean) that is reset (false) when the select button is pressed, but which is set TRUE if both the select button and one of the up/down buttons are pressed. That way, if it is still false when the select button is released, jump to a new menu. If not, set the option as before with the up/down buttons.
Or something like that. Might be a bit clunky when it comes to displaying the right menu perhaps? (Not showing one of your "new" menues until select button is released).
That's what I'm doing now, the issue is that the selected value changes before you can jump to the next menu.
What selected value? The option selected from the combination of the select-button + up/down?
My suggestion above is just a rough draft of course. Also, if the boolean variable (the one used as a combination button flag) is true, then do not count nor display your new "select-button-only" menu item after all (or if false, do count it and display it).
Anyway, seems like Crowley above is right, time to extract the button handling and get that working by itself. Also, posting the relevant code might help.
I'm assuming you have debounced your buttons? If not maybe look into that as well.