Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 10 months ago.
Buttons on Mbed control WMP
So i am trying to make buttons on the mbed control Windows media player. So one button on the breadboard would open WMP, another is the play/pause button, etc. My question is, how would i... 'implement" it in windows. For example, what would be the command to run wmp in the compiler? E.G in pseudo-code:
if (button1 = 1) if button 1 is pressed
run (C:\Program Files (x86)\Windows Media Player\wmpplayer.exe) THIS is the command i am struggling with.
else return 0;
what else would i need for this to be possible? Also, how would i get another stricltly press the play button? Any help is greatly appreciated to this learning student. cheers
3 Answers
10 years, 10 months ago.
Some keyboards have buttons that can control media players, your device could emulate a keyboard and use the same method.
http://mbed.org/handbook/USBKeyboard will help with the emulation. Look in particular at the media control section.
The advantage of this method is that it will work with a variety of media players.
Some keyboards have buttons that can launch specific programs, I don't know how they do that but I suspect they come with a driver that listens for a certain key press.
10 years, 10 months ago.
Thanks, that really helped, i have my code set up, but now, i ran into this error where i press my button, and nothing happens, and it seems that it resets my mbed and reconnects it to the computer. (so my Mbed (F:) will disconnect and reconnect each time i press the button). Do you know a reason?
Heres my code:
Windows Media Player Control Buttons
#include "mbed.h" #include "USBKeyboard.h" DigitalIn TestButton(p20); DigitalIn PlayButton(p21); DigitalIn NextButton(p22); DigitalIn PrevButton(p23); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); //USBKeyboard USBKeyboard keyboard; int main(void) { TestButton.mode(PullDown); PlayButton.mode(PullDown); NextButton.mode(PullDown); PrevButton.mode(PullDown); while (1) { if(TestButton){ wait_us(50); while(TestButton); keyboard.keyCode('b'); wait_us(50); led1=led2=led3=led4=1; wait(0.5); led1=led2=led3=led4=0; } else if (PlayButton) { wait_us(50); while(PlayButton); keyboard.keyCode('p', KEY_CTRL); wait_us(50); led1=led2=led3=led4=1; wait(0.5); led1=led2=led3=led4=0; } else if (NextButton) { wait_us(50); while(NextButton); keyboard.keyCode('b', KEY_CTRL); wait_us(50); led1=led2=led3=led4=1; wait(0.5); led1=led2=led3=led4=0; } else if (PrevButton) { wait_us(50); while(PrevButton); keyboard.keyCode('f', KEY_CTRL); wait_us(50); led1=led2=led3=led4=1; wait(0.5); led1=led2=led3=led4=0; } } }
Im only fiddling with TestButton right now as i cannot get it to output b on notepad.. etc. I hope i am using the correct library for USBKeyboard.h (i can post that if needed)
How have you connected the mbed to the computer's USB port? It sounds like you might be using the USB socket on the board that is for the mbed interface. You need to use the pins labelled USB on the pin out http://mbed.org/platforms/mbed-LPC11U24/ If you don't want to wire up a USB socket you could buy a base board for your platform. The mbed application board would work http://mbed.org/components/mbed-Application-Board/
posted by 20 Feb 201410 years, 10 months ago.
Does the mbed keyboard show up in the PCs devicelist, is it recognised as a keyboard? Can you get any keys to show on the PC when sending data directly to the PC before your code enters the endless loop waiting for keypresses. Can you actually detect keypresses by removing the usb keyboard code and just observing the LEDs. A complete reset of mbed may be caused when you short out the powersupply. How are the buttons wired. Could there be a short to ground when you press a button.