| Reference | Downloads | Github

Cedrus Box interact with Slider

Description of the problem: Our MRI experiment requires the use of the blue and yellow buttons of the cedrus button box (LS-PAIR) to have a slider component move up and down. This is done in order to continuously rate pain over the experiment.

We are not able to have the buttons move the slider, and want to see if anyone has a solution.

Currently this is the code we are using for this (but it doesn’t work):

            # check for key presses
            while len(buttonBox.response_queue):
                evt = buttonBox.get_next_response()
                if evt['key'] not in [0, 1]:
                    continue  # we don't care about this key
                if evt['pressed']:
                    #TODO# Update VAS display:
                    # if button 0, move left on slider
                    # if button 1, move right on slider
                    if evt['key'] == 0:
                        slider_2.markerPos -= 1
                    elif evt['key'] == 1:
                        slider_2.markerPos += 1

We also used a version with rating rather than markerPos, which also didn’t work.

We’d love you big time if anyone had some tips!

You might be interested in seeing whether your code works with my interactive slider demo (see PsychoPy Online Demos).

Also, I would change continue to pass (because I don’t know what continue does – maybe it’s the same) and replace the next line with elif so you don’t evaluate it if the key is passed.

                if evt['key'] not in [0, 1]:
                    pass  # we don't care about this key
                elif evt['pressed']: #only check pressed if 0 or 1

Can you update a text box with the number of frames a key has been held down for, or does it only register the keydown action?

Hi wakecarter!

Thank you so much for the help, it means a lot.

We discovered another issue with our button box, so we can’t tell if your solution works!

We’ve created a new discussion for it, if you have any input we’d be glad to hear it: Unable to optain response from cedrus button box

Thanks again!

  • R & J