Quick Piece of Code Advice - Toggling keyboard commands

Status
Not open for further replies.
Hello there!

I'm just finishing up a code for a piece of hardware I'm currently building and I've come across a situation I'd like to be able to implement, and I imagine it's a fairly simple piece of code away for working!

Essentially, I've got a push button which when pressed outputs a "[" keypress using keyboard.Write.

What I would like is for the button to toggle between outputting first a "[" then a "]".

The idea is this button is to Pause a piece of software, and then to use the same button to resume.

Is this at all possible? And what would the code I'm missing look like?

Thanks!

-Rory Maguire
 
if you had included your code snippet for detecting the button press and sending the '[' character I could have modified it to show you using the specific stuff you are using but...
Code:
volatile uint8_t toggler=1;

setup() { // do your set up bits }

loop() {
  if(button_detected) {
    toggler=1-toggler;
    if(toggler) send("]"); else send("[");
  }
}
Is one way it can be done.
 
Status
Not open for further replies.
Back
Top