ilk oyun kodu, bu çöp oldu artık ama iççinde joystick için main.h dosyası var o çekilebili
Dependencies: mbed Joystick Nokia5110_KL25Z Nokia_5110
Revision 1:6497e159052d, committed 2019-05-27
- Comitter:
- bengisuakyurek
- Date:
- Mon May 27 14:58:20 2019 +0000
- Parent:
- 0:083b72141582
- Commit message:
- cx
Changed in this revision
diff -r 083b72141582 -r 6497e159052d Joystick.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Joystick.lib Mon May 27 14:58:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/rwunderl/code/Joystick/#13d10cc6a822
diff -r 083b72141582 -r 6497e159052d NOKIA_5110.lib --- a/NOKIA_5110.lib Sun Mar 23 03:04:48 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/Fuzball/code/NOKIA_5110/#9cfce382e741
diff -r 083b72141582 -r 6497e159052d Nokia5110_KL25Z.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Nokia5110_KL25Z.lib Mon May 27 14:58:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/ThihaElectronics/code/Nokia5110_KL25Z/#083b72141582
diff -r 083b72141582 -r 6497e159052d Nokia_5110.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Nokia_5110.lib Mon May 27 14:58:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Team-Kombat/code/Nokia_5110/#73f226b84b70
diff -r 083b72141582 -r 6497e159052d main.cpp --- a/main.cpp Sun Mar 23 03:04:48 2014 +0000 +++ b/main.cpp Mon May 27 14:58:20 2019 +0000 @@ -1,8 +1,43 @@ #include "mbed.h" +#include "main.h" #include "NOKIA_5110.h" +#include "char_object.h" +#include "Joystick.h" + +// target is the KL25Z +#define PIN_JOYX PTB0 // A0 +#define PIN_JOYY PTB1 // A1 +#define PIN_JOYA PTB2 + +PwmOut led_R(LED1); +PwmOut led_G(LED2); +PwmOut led_B(LED3); + +Joystick j(PIN_JOYX, PIN_JOYY, PIN_JOYA); + +// 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: leds are off + led_R = 1.0f; + led_G = 1.0f; + led_B = 1.0f; + + joypos p; // joystick position + // attach joystick button interrupts + + j.rise(&jrise); + j.fall(&jfall); + float fade = 0.0f; /* PinName mosi; PinName miso; @@ -11,10 +46,41 @@ PinName sce; PinName rst;*/ - LcdPins myLcdPins = { PTC6, NC, PTC5, PTD2, PTD0, PTD3 }; - NokiaLcd myLcd( myLcdPins ); // SPI is started here (8-bits, mode 1) + LcdPins myLcdPins = { PTC6, NC, PTC5, PTD2, PTD0, PTD3}; + NokiaLcd myLcd( myLcdPins); // SPI is started here (8-bits, mode 1) myLcd.InitLcd(); // LCD is reset and DDRAM is cleared - myLcd.DrawString("Hello"); - while(1) - { }; + + +//const bng_Width = 14; actually 13, but in printing one column is somehow(?) lost +//const bng_Height = 32; multiple of 8 in order to adress lcd easier +//collision dimensions of bng: its x coordinate is (always topleft even with mirroring print) +// x coordinate with y coordinate + h_adjusted but before jumping and crounching, we can use only x + +char bng[] = { + 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xa0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x70, 0x88, 0xa4, 0xd7, 0x61, 0x04, 0xdb, 0xa0, 0x90, 0x68, 0x18, 0x00, 0x00, + 0x00, 0xf8, 0x07, 0x00, 0xe0, 0x20, 0x60, 0x87, 0x18, 0xe0, 0x00, 0x00, 0x00, 0x00, + 0x7c, 0xf3, 0x8c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x38, 0xc7, 0xf8, 0x80, 0x00 +}; + while(1) + { + myLcd.DrawBitmap(0,0,bng,14,32); //IMPORTANT: Y CAN BE [0-5] (6*8=48 PIXEL), also add one dummy column to compensate printing problem + + 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); + + + }; } +
diff -r 083b72141582 -r 6497e159052d main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Mon May 27 14:58:20 2019 +0000 @@ -0,0 +1,65 @@ +#ifndef MAIN_H +#define MAIN_H + +#include "mbed.h" + +class main { +public: + + main(); + /** Read the joystick position + * The position is returned as a joypos value with x and y in the range [-1.0, 1.0]. + * + * @returns Position structure of the joystick. + */ + joypos read(); + + /** Get the X position + * Read the joystick's horizontal position, represented as a double value in the range [-1.0, 1.0]. + * + * @returns Horizontal position of the joystick. + */ + double getX(); + + /** Get the Y position + * Read the joystick's vertical position, represented as a double value in the range [-1.0, 1.0]. + * + * @returns Vertical position of the joystick. + */ + double getY(); + + /** Get the raw X position + * Read the joystick's raw horizontal position, represented as a double value in the range [0.0, 1.0]. + * + * @returns Horizontal position of the joystick. + */ + double getRawX(); + + /** Get the raw Y position + * Read the joystick's raw vertical position, represented as a double value in the range [0.0, 1.0]. + * + * @returns Vertical position of the joystick. + */ + double getRawY(); + + /** Attach the rise interrupt + * Attach a function pointer to call when a rising edge occurs on the button input. + * + * @param fptr Pointer to a void function. Set to NULL or 0 for none. + */ + void rise(void (*fptr)(void)); + + /** Attach the fall interrupt + * Attach a function pointer to call when a falling edge occurs on the button input. + * + * @param fptr Pointer to a void function. Set to NULL or 0 for none. + */ + void fall(void (*fptr)(void)); + +protected: + AnalogIn _x; + AnalogIn _y; + InterruptIn _a; +}; + +#endif