Tool/software: Code Composer Studio
how do i use the button to turn on the led then turn it off when pressed again?
currently, my program only turns on my led if i hold the button and it turns off if i let go
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
how do i use the button to turn on the led then turn it off when pressed again?
currently, my program only turns on my led if i hold the button and it turns off if i let go
Germaine Tan said:How do i use the button to turn on the led ... then turn it off when pressed again?
That goal describes a, 'Toggle Function' - one in which 2 unique behaviors occur in sequence - following each button (switch, really) operation. Your current program appears to simply, 'Monitor' the switch (via the MCU's GPIO pin) which receives such switch input. That's much easier - yet not so valuable - just as you've noted.
That 'Live Switch Monitoring' is far simpler - and avoids a common 'gotcha' ... the known tendency of inexpensive switches to suffer, 'Contact Bounce.' (Bounce is the generation of multiple contact 'Makes/Breaks' (closures/opens) - which persist often for milliseconds. Also known as 'Contact Chatter' - these are produced when the switch's mechanical electrical contacts join (or separate.)
With that as (necessary) background - now to your requested programming requirements:
You must buy into (accept) the need for all four of those functions. Once agreed - how do 'you' propose to write code - which achieves each function? Such IS required - is it not?
Should you make such effort - and present it here - I'll return to offer (further) encouragement (perhaps guidance) - but your 'learning' is best assured by your 'dealing with these program issues' - now spelled out w/'reasonable' clarity - and brought to your attention...
How do 'you' answer (any) of the earlier - still outstanding - issues? Anyone here would feel 'little motivated' - after creating such focused detail - and then receiving an 'answering post' - which (clearly) - is 'Non-Responsive!' Beyond that - it is gracious to 'thank' your sole - and detailed responder - prior to 'loading on' - still more questions - is that not true?
In my (first) identification of such 'Switch BOUNCE' - and (then) description of 'bounce's' effect (and duration) - there are (several, solid clues.) You may recall - that such 'bounce' was noted - 'NOT - to persist forever!' (that almost makes your 'bounce resolving job' ... too easy - does it not?)
One way data-dump - while practiced here by (some) - does not maximize forum user 'learning' - which is my pursuit & purpose...