| Reference | Downloads | Github

Using a four-buttons button-box to code a number between 0 and 99

In my task (in the fMRI), participants are asked to enter a number between 0 and 99 in multiple trials.
I’d like to use a four-button button-box (1-4) to code for that number, such that two buttons control the 10s digit - one increases it and one decreases, and two buttons control the ones digit in a similar manner.
At the beginning of each trial, participants will see the number 55 and work their way from there, by increasing and decreasing each digit. This means that their actions would have to be displayed on the screen while they press the buttons. Ultimately, they may use a fifth button to confirm their selection.

Has anyone come across anything similar to that or has a clue on how to start?
I looked throughout the forum and couldn’t find a similar question.
Any advise would be highly appreciated!

Are you using Builder, or programming the experiment from scratch?

I’m programing it.

It’s currently ready, only the responses were thought to arrive form the corresponding numeric keys (meaning 0-9). I now realized this would not be possible in the scanner (MRI) and thus need to change only this part of the script.

So it’s not clear now: is the issue with controlling the numeric display (which will be straightforward), or is it some problem with actually receiving the keypresses from the response pad in the MRI?

But assuming you can detect keys in some fashion, some pseudo code would be something like this:

# at the beginning of the trial:
tens = 5
ones = 5
# on every screen refresh:

response = event.getKeys() # or however you are getting responses

if response: 
    # allowing for multiple responses per check:
    if '1' in response: # decrement the tens counter:
        tens = max(0, tens - 1)
    if '2' in response: # increment the tens counter:
        tens = min(9, tens + 1)
    if '3' in response:
        ones = max(0, ones - 1)
    if '4' in response:
        ones = min(9, ones + 1)
    some_text_stimulus.text = str(tens) + str(ones)


Thank you! I will try it soon and see how it works.
(there is no problem with receiving the input, only with numeric display and coding of digits going up or down)

it worked great! Thank you!