Team Kombat
/
joystickdeneme
Joystick deneme modülü (internetteki kod)
Revision 0:1fa564d928a9, committed 2019-05-27
- Comitter:
- bengisuakyurek
- Date:
- Mon May 27 14:49:46 2019 +0000
- Commit message:
- deneme
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Joystick.lib Mon May 27 14:49:46 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/rwunderl/code/Joystick/#13d10cc6a822
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 27 14:49:46 2019 +0000 @@ -0,0 +1,52 @@ +// Joystick Library Example +// +// Reads the joystick x axis and fades green and red LEDs in response. +// The blue LED is turned on while the pushbutton is pressed. + +#include "mbed.h" +#include <Joystick.h> + +PwmOut led_R(LED1); +PwmOut led_G(LED2); +PwmOut led_B(LED3); + +Joystick j(PTB0, PTB1, PTB2); + +// call on joystick button release +void jrise(void) { + led_B = 1.0f; +} + +// call on joystick button press +void jfall(void) { + led_B = 0.0f; +} + +int main () { + // setup + led_R = 1.0f; + led_G = 1.0f; + led_B = 0.0f; + joypos p; // joystick position + // attach joystick button interrupts + j.rise(&jrise); + j.fall(&jfall); + float fade = 0.0f; + + // loop + while (1) { + p = j.read(); + fade = p.x; + if (fade > 0.0) { + led_R = 1.0f; + led_G = 1.0f - (float)fade; + } else if (fade < 0.0) { + led_R = 1.0f + (float)fade; + led_G = 1.0f; + } else { + led_R = 1.0f; + led_G = 1.0f; + } + wait(0.01); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon May 27 14:49:46 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file