Skip to main content
15 events
when toggle format what by license comment
S Nov 21, 2019 at 12:46 history suggested Mike CC BY-SA 4.0
I try to format the code
Nov 21, 2019 at 11:18 review Suggested edits
S Nov 21, 2019 at 12:46
Nov 21, 2019 at 11:08 vote accept DodZi
Nov 21, 2019 at 11:06 history edited DodZi CC BY-SA 4.0
Question solved.
Nov 21, 2019 at 10:20 comment added DodZi My switches are push buttons. When I press a button, the state of the led corresponding to that should toggle. The main problem is that the switches are not working independently. When the system starts, I am not able to use switch 2. Only switch 1 is working. Once switch 1 has been pressed once, then switch 1 stops working and only switch 2 is working. And again the cycle continues with only one switch working at a time.
Nov 21, 2019 at 9:30 comment added Russell McMahon While switch is on, sit in this loop and do not allow any code outside the loop to be executed.
Nov 21, 2019 at 8:56 comment added Jasen Слава Україні look again. the code is correct there.
Nov 21, 2019 at 8:53 comment added jonk @Jason I wasn't writing code. Just trying to tell the OP how to get a clue.
Nov 21, 2019 at 8:52 comment added Jasen Слава Україні @jonk, I think you missed the semicolon after the while.
Nov 21, 2019 at 8:23 comment added TonyM You need to debounce your switch inputs. But you should understand that idea and rewrite your software yourself, there's plenty of existing text on the interweb covering that.
Nov 21, 2019 at 8:20 comment added Bruce Abbott The way your code is written it looks like you want the LED to toggle on or off alternately each time its switch is turned on and off again - is that what you want? Or do you want the LED state to follow the switch state? Are they toggle switches or push buttons?
Nov 21, 2019 at 7:53 comment added jonk Your XORs will execute too fast to see. I suspect you want the LEDs to reflect the PB state, not toggle it. But only you know, since you've not explained it here (except through code that you say doesn't do what you want.) Just set up two variables (or two bits in a variable) to represent the current state of the LED. Clear it and turn off the LEDs. Then use your while(1) but inside just capture a snapshot of the port (both PBs) and see if either LED state differs from the PB state you just read. Adjust where different with PB1, update your internal state, same for PB2 then, and loop.
Nov 21, 2019 at 7:23 answer added Justme timeline score: 5
Nov 21, 2019 at 7:19 history edited Bruce Abbott CC BY-SA 4.0
added 82 characters in body
Nov 21, 2019 at 7:10 history asked DodZi CC BY-SA 4.0