Skip to main content
16 events
when toggle format what by license comment
Mar 7, 2017 at 16:48 comment added Rizzo Let us continue this discussion in chat.
Mar 7, 2017 at 16:28 comment added Rizzo You are right it is working correctly. I may have worded my concerns incorrectly, but as per my original question, when I press the switch the SSD is displaying 01 only for an extremely short amount of time (when switch is pressed) and then returning back to 00. At first I thought that this was a debouncing issue, but it turned out that it's not. The problem surrounds my other part of my coding where I need to display 01 even after the switch has been released, and then displaying 02 if pressed again. Thanks for your help on this debouncing issue.
Mar 7, 2017 at 16:23 comment added Andrew Sounds like it's all working as expected then. You only wanted count to increase once per button press not rapidly count up all the time the button is down didn't you?
Mar 7, 2017 at 16:06 comment added Rizzo I have conducted simple tests using an LED. If I use int buttonPress(void) { return (IO0PIN & 0x00000200); } then the LED lights up for the whole duration that the switch is pressed. Good. If I use the code provided for software debouncing the LED only lights up for a split second (just enough for me to see) which I think is also working as it should. I will test further using count++;
Mar 7, 2017 at 16:00 comment added Andrew Also remember that if you hold the button you'll only get a single call to buttonPress() that returns true, it won't remain true the whole time the button is down.
Mar 7, 2017 at 15:59 comment added Andrew Did you try replacing the button press function with the one in the comment above with no debouncing to verify that the debouncing is the cause of the problem? There is a strong possibility that there is an error in the code, I've not run it, I've not even entered it into a compiler to syntax check it, but I can't see anything obviously wrong with it. Is your button active high or low? The code assumes high, if it's low then you need to change == 0x00000200 to == 0 but it should still have triggered when you let go of the button.
Mar 7, 2017 at 15:47 comment added Rizzo Hi, Andrew, sorry for bothering you on this one. I am having some small issues with the software debouncing. I am not managing to implement this code to increment a counter. For example: if (buttonPress()) count++; Such a simple code is not working. I must be overlooking something from my side, if the code you provided worked for you. EDIT: Switch, and 7 segment displays are working correctly (hardware)
Feb 22, 2017 at 9:21 history edited Andrew CC BY-SA 3.0
added 57 characters in body
Feb 22, 2017 at 9:17 comment added Andrew Did you define that function? It needs to return true when the button is pressed. This could be as simple as int buttonPress(void) { return (IO0PIN & 0x00000200); } if you have hardware button debouncing. I've added a longer version with software debouncing to the code above.
Feb 22, 2017 at 9:14 history edited Andrew CC BY-SA 3.0
added button press function
Feb 21, 2017 at 18:36 comment added Rizzo I am trying to implement this however I keep getting stuck on the error: called object type int is not a function or function pointer in the third line: if (buttonPress())
Feb 21, 2017 at 18:02 vote accept Rizzo
Feb 21, 2017 at 17:02 history edited Andrew CC BY-SA 3.0
added function examples
Feb 21, 2017 at 16:47 comment added Andrew You can always put the if statement to set the LEDs in place of the function call. If you were to do that I'd add int valueToDisplay; if (digitToDisplay == 0) valueToDisplay = bottomDigit; else valueToDisplay = topDigit; and then use if (valueToDisplay == 0) <set IO for 0> else ... to set the IO, that avoids the need to have the same code in there twice. And you really should use a switch rather than a stack of if's, it's a lot cleaner for this sort of thing.
Feb 21, 2017 at 15:45 comment added Rizzo Thanks for the good advice and suggestions. This method is far better than the one I am using and I will look to implement something of the sort. However is there any other method which can be implemented in this messy if else structure, to prevent the SSD from switching off once, after they have displayed the two digits once ? (without the use of functions in this case)
Feb 21, 2017 at 15:37 history answered Andrew CC BY-SA 3.0