Accessing "s1" button in code on USB Prank?

Is it possible to use the S1 button as an IO ? If so, what is it’s designation?

I hear crickets… chirp … chirp… chirp. Looking at the schematic button S1 is mapped to P0_1. So the answer should be a yes. There are no external parts attached to that pin except for the switch. Keep in mind though that this button is also used on boot to trigger the USB loader I think. Schematic in a zip file here: USB Prank - | Mbed

To use the button in your code construct a DigitalIn c++ object like this

DigitalIn button(P0_1, PullUp);

Then you can read the pin state: button.read();

You can also use DigitalOut on it too since it is just an IO pin.

yeah I did that check too and thought it’d work, but haven’t had any joy in getting it to work. More testing required (using an actual button on a different IO) to prove my sampling isn’t flawed, but I think there must be some hardware specific thing that’s blocking me…

All of the outrageous circuits mbed platform stuff is based on the mbuino base circuit. P0_1 works on the Retro as it is one of the control buttons. It is hooked up in the same manner as on USB prank board. What value is it reading? 0 or 1 or is it fluctuating?

I’ve not dug into my code at all since I last posted, but the value never changed

I can confirm that
DigitalIn button(P0_1,PullUp);
works fine.

If you skip the pullup bit you always get a 0.

1 Like

hmm, any chance you can give me a minimal code example that you used to test it? (yes, I’m a n00b at this - really !).

2 Likes

actually, I have a test that works. Now to figure out how to incorporate it into my actual scenario.

My program was very simple, it set the keyboard caps lock light based on the button on the USB prank.
The code is here:

Generally for this board I’ve been using the keyboard LEDs as a method of doing IO.

A USB mouse or keyboard doesn’t know what the user is doing on their other (real) mouse or keyboard but windows very helpfully ensures that the keyboard mode LEDs are the same on all keyboards. Which means that by checking the LEDs you know if they have hit caps lock, num lock or scroll lock.

e.g. rather than moving the mouse all the time turn caps lock on and then only start doing something when they turn it off.

And by being a keyboard as well as a mouse you can do a lot more, on windows this includes running any command or loading any web site you want if you hit the magic key stroke of windows key and r

1 Like

awesome, thanks for that. Awesome way to assist debugging simple states!! I had not thought of that at all (I manually wired up a LED :slight_smile: )