Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBJoystick_HelloWorld by
Revision 1:61f0689edc0a, committed 2017-05-10
- Comitter:
- bouaziz
- Date:
- Wed May 10 20:54:51 2017 +0000
- Parent:
- 0:5037d4be5b6d
- Commit message:
- progrzmme essais clavier
Changed in this revision
USBDevice.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBDevice.lib Sat Jan 07 21:03:54 2012 +0000 +++ b/USBDevice.lib Wed May 10 20:54:51 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/samux/code/USBDevice/#5e24508aa46e +https://developer.mbed.org/teams/CRTI_Progs/code/USBDevice/#2544b20d1413
--- a/main.cpp Sat Jan 07 21:03:54 2012 +0000 +++ b/main.cpp Wed May 10 20:54:51 2017 +0000 @@ -1,9 +1,7 @@ #include "mbed.h" -#include "USBMouse.h" -#include "USBJoystick.h" +#include "USBKeyboard.h" -//USBMouse mouse; -USBJoystick joystick; +USBKeyboard keyboard; // Variables for Heartbeat and Status monitoring DigitalOut myled1(LED1); @@ -11,55 +9,28 @@ DigitalOut myled3(LED3); DigitalOut heartbeatLED(LED4); -Ticker heartbeat; -Serial pc(USBTX, USBRX); // tx, rx - -// Heartbeat monitor -void pulse() { - heartbeatLED = !heartbeatLED; -} +DigitalIn mic (p14); -void heartbeat_start() { - heartbeat.attach(&pulse, 0.5); -} - -void heartbeat_stop() { - heartbeat.detach(); -} +Serial pc(USBTX, USBRX); // tx, rx -int main() { - int16_t i = 0; - int16_t throttle = 0; - int16_t rudder = 0; - int16_t x = 0; - int16_t y = 0; - int32_t radius = 120; - int32_t angle = 0; - int8_t button = 0; - int8_t hat = 0; - - pc.printf("Hello World!\n\r"); - - heartbeat_start(); - +char state; +int main(){ + // pc.printf("%u\n\r",); while (1) { - // Basic Joystick - throttle = (i >> 8) & 0xFF; // value -127 .. 128 - rudder = (i >> 8) & 0xFF; // value -127 .. 128 - button = (i >> 8) & 0x0F; // value 0 .. 15, one bit per button -// hat = (i >> 8) & 0x03; // value 0, 1, 2, 3 or 4 for neutral - hat = (i >> 8) & 0x07; // value 0..7 or 8 for neutral - i++; - - x = cos((double)angle*3.14/180.0)*radius; // value -127 .. 128 - y = sin((double)angle*3.14/180.0)*radius; // value -127 .. 128 - angle += 3; - - joystick.update(throttle, rudder, x, y, button, hat); - - wait(0.001); + if((state==0)&(mic==1)){ + state=1; + // pc.printf("oui\n\r"); + keyboard.keyCode2(0x00,0x10,0); //sends touche CTRL through the keyboard + myled1=1; + }else{ + if(mic==0){ + state=0; + keyboard.key_release();// release + myled1=0; + } + } + wait(0.20); } - pc.printf("Bye World!\n\r"); } \ No newline at end of file