Is there any way to get another "set" of button functions?

Second Edit :: The irony of my stating that I can’t even ““code”” this post in English [Next Paragraph], while lamenting that I can’t Code in C … did escape me.

The problem with a majority of my questions here, either are, or definitely will be on the order of things that I so clearly see in my head, and utterly fail to put words to. Like, the act of trying to find the exact words, makes the entire ordeal even harder than before I started.

My current project already has Single Double Multi and Longpress button functions in use.

I am after a way to get another batch of button functions.

I had the idea that I could declare a global Variable X, and then enter a Do While Loop from a button function. Within that loop, I was of the assumption that I would have a “fresh batch” of button functions. Those newer functions would do what I needed the newer functions to do, and at the end of that, change the variable so that the Do While becomes false. In theory exiting back out to the main Loop. That there was … that the program would idle until further input.

EDIT : I would then, at the bottom of the main Loop, reset X back so that you could, if you needed to, re-enter the loop.

And… as for most of my attempts thus far, I know the theory here works. I know there HAS to be a way to do this… but undertaking C++, on Arduino, on Blinks, all at once moves the entire project beyond the counterintuitive. I have no idea where to know where to begin to work, and looking to sample programs does no real good, because while I can copy the code, I can’t translate it.

Hopefully that makes sense.

Button presses are “detected” every loop() iteration. If you have another loop (say, a for loop) inside loop() and you check button state there, you will always get the same values back so do not do that. You need to return from loop() and check again in another iteration

You can actually use multi-click and check the click count to do different things based on the number of button clicks detected, but if your UX requires lots of different types of button clicks, you most likely want to change it.

  1. Short of ticking on to multi click, and counting, the answer here is no? … There was a general “feel” that the button functions, as a set, were bedrock and global.

  2. I need to revise the UX to be sure, I can optimize what I have, and balance that out with the game rules proper. It’s just a matter of knowing when I am done tinkering.

  3. Is Switch / Case not relevant here?

I am sorry, but I am not sure I understand what you mean. A Blink has a single button. It keeps track of button state (to detect single/multiple clicks) and reports on that. But this reporting only happens just before a loop() iteration starts so inside loop() the result from calling any of the button functions will always be the same.

I wonder if what you mean is that you want to handle button clicks differently at different parts of your program? If that is the case then yes, you can do this. There is no secret really, just a matter of checking for the button state you want at the point you want and then running the specific logic you need.

If what you mean is what I mentioned above then yes, it could be. You could use a variable to indicate state and depending on the state you are in, you do something different.

Thanks.

I’m going to release what I have soon. Ultimately I think that will help everyone.

1 Like

On a related note, this example that I created for my class at NYU this past semester walks through creating a single Blink game (i.e. no use of communication) but introduces the concept of being in different states inside of a single Blink. This could be thought of like each state has its own loop that it will reside in until its state is changed.

Code here

and a YouTube video here that walks through the making of this sketch.

There are a number of sketches that I created in the resources folder for this class that can be handy, some far simpler and some more complex. I would like to surface these as we update our examples and documentation based on feedback.

best,
jb

2 Likes