The attached image shows a 5 button shield plugged into an UNO. When I press a button, the software shows the millivolt range that is tested for, and the actual millivolts read. The 5 buttons on the LCD form a voltage divider with an input to AN0.
In one version of the program, I enable the interrupt and disable the sub call. Compile and run. It only works on 3 right buttons. But if I disable the interrupt and do a sub call in main, compile and run, It works for all 5 buttons. I note that the 2 buttons
Button press interrupt
Moderator: Benj
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Button press interrupt
- Attachments
-
- WhichButton_With Interrupt.fcfx
- (21.64 KiB) Downloaded 184 times
-
- PuttonPress.jpg (106.67 KiB) Viewed 3530 times
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Button press interrupt
You shouldn't do the display and delays in the interrupt handler....
Interrupt handler needs to check which button is pressed - set a global with this value and then return.
Calling it as a macro - timing is much less critical.
Martin
Interrupt handler needs to check which button is pressed - set a global with this value and then return.
Calling it as a macro - timing is much less critical.
Martin
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Button press interrupt
I implemented the code to where the interrupt handler sets a global value. I have the same problem, in that 2 of the buttons do not set the MenuPosition (global value) and display text indicating so.
I note that the 2 buttons that do not respond have the highest analog voltage - 2.2 to 3.2 and 3.2 to 4.2.
I do not fully understand the properties / settings for the pushbutton. Conversion speed and aquisition cycles.
I note that the 2 buttons that do not respond have the highest analog voltage - 2.2 to 3.2 and 3.2 to 4.2.
I do not fully understand the properties / settings for the pushbutton. Conversion speed and aquisition cycles.
- Attachments
-
- WhichButton_With Interrupt_MenuPosition.fcfx
- (27.35 KiB) Downloaded 177 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Button press interrupt
You need to change your flowchart to the way martin has stated.
You have still got LCD components within the interrupt handler.
You must never add components that contain delays like LCD or delays themselves to interrupts.
Only use interrupts for inputs/outputs and setting flags (bool variable set to 1 then the variable is read outside the interrupt.
Interrupts should be kept as small as possible, and allowed to exit normally i,e no call macros.
You have still got LCD components within the interrupt handler.
You must never add components that contain delays like LCD or delays themselves to interrupts.
Only use interrupts for inputs/outputs and setting flags (bool variable set to 1 then the variable is read outside the interrupt.
Interrupts should be kept as small as possible, and allowed to exit normally i,e no call macros.
Martin
-
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Button press interrupt
The solution that I chose was to just check if a button press is sensed in Main. Since it detects any 1 of 5 buttons. Forget the interrupt.
I also found out that on the MEGA, that Analog Input 0 is on Port F and IOC PortF (interrupt on change - Port F) is not available.
Thanks for the suggestions.
I also found out that on the MEGA, that Analog Input 0 is on Port F and IOC PortF (interrupt on change - Port F) is not available.
Thanks for the suggestions.