![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Early commits of my project
Dependencies: mbed Gamepad N5110
main.cpp@4:e7215819c9bc, 2019-03-12 (annotated)
- Committer:
- el17arm
- Date:
- Tue Mar 12 09:45:03 2019 +0000
- Revision:
- 4:e7215819c9bc
- Parent:
- 3:140cad440684
- Child:
- 5:f09602591ad3
tried to incorporate gamepad joystick get direction not working, reverting to previous revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17arm | 0:9e5f9e1c8ef9 | 1 | #include "main.h" |
el17arm | 0:9e5f9e1c8ef9 | 2 | #include "N5110.h" |
el17arm | 3:140cad440684 | 3 | #include "Gamepad.h" |
el17arm | 0:9e5f9e1c8ef9 | 4 | |
el17arm | 3:140cad440684 | 5 | Gamepad pad; |
el17arm | 0:9e5f9e1c8ef9 | 6 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17arm | 1:c80162894831 | 7 | AnalogIn pot0(PTB2); |
el17arm | 2:ba653520a140 | 8 | |
el17arm | 2:ba653520a140 | 9 | int x = 0; |
el17arm | 2:ba653520a140 | 10 | int y = 0; |
el17arm | 2:ba653520a140 | 11 | |
el17arm | 0:9e5f9e1c8ef9 | 12 | |
el17arm | 0:9e5f9e1c8ef9 | 13 | int main() |
el17arm | 0:9e5f9e1c8ef9 | 14 | { |
el17arm | 0:9e5f9e1c8ef9 | 15 | init(); |
el17arm | 3:140cad440684 | 16 | |
el17arm | 0:9e5f9e1c8ef9 | 17 | while (1) { |
el17arm | 4:e7215819c9bc | 18 | |
el17arm | 2:ba653520a140 | 19 | contrast(); |
el17arm | 2:ba653520a140 | 20 | minerbitmap(); |
el17arm | 0:9e5f9e1c8ef9 | 21 | } |
el17arm | 0:9e5f9e1c8ef9 | 22 | |
el17arm | 0:9e5f9e1c8ef9 | 23 | } |
el17arm | 0:9e5f9e1c8ef9 | 24 | |
el17arm | 0:9e5f9e1c8ef9 | 25 | void init() |
el17arm | 0:9e5f9e1c8ef9 | 26 | { |
el17arm | 0:9e5f9e1c8ef9 | 27 | lcd.init(); |
el17arm | 1:c80162894831 | 28 | lcd.normalMode(); // normal colour mode |
el17arm | 1:c80162894831 | 29 | lcd.setBrightness(0.5); // put LED backlight on 50% |
el17arm | 1:c80162894831 | 30 | lcd.refresh(); |
el17arm | 4:e7215819c9bc | 31 | Gamepad gamepad; |
el17arm | 4:e7215819c9bc | 32 | gamepad.leds_off(); |
el17arm | 1:c80162894831 | 33 | } |
el17arm | 1:c80162894831 | 34 | |
el17arm | 1:c80162894831 | 35 | void contrast() |
el17arm | 1:c80162894831 | 36 | { |
el17arm | 1:c80162894831 | 37 | lcd.refresh(); |
el17arm | 1:c80162894831 | 38 | float con = pot0.read(); |
el17arm | 1:c80162894831 | 39 | lcd.setContrast(con); |
el17arm | 1:c80162894831 | 40 | |
el17arm | 4:e7215819c9bc | 41 | |
el17arm | 2:ba653520a140 | 42 | } |
el17arm | 2:ba653520a140 | 43 | |
el17arm | 2:ba653520a140 | 44 | void minerbitmap() |
el17arm | 2:ba653520a140 | 45 | { |
el17arm | 2:ba653520a140 | 46 | const int miner[13][5] = { |
el17arm | 2:ba653520a140 | 47 | 0,0,0,1,1, |
el17arm | 2:ba653520a140 | 48 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 49 | 0,1,0,1,0, |
el17arm | 2:ba653520a140 | 50 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 51 | 0,1,1,1,0, |
el17arm | 2:ba653520a140 | 52 | 0,0,1,0,0, |
el17arm | 2:ba653520a140 | 53 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 54 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 55 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 56 | 0,1,1,1,0, |
el17arm | 2:ba653520a140 | 57 | 0,1,0,1,0, |
el17arm | 2:ba653520a140 | 58 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 59 | }; |
el17arm | 2:ba653520a140 | 60 | |
el17arm | 2:ba653520a140 | 61 | lcd.clear(); |
el17arm | 2:ba653520a140 | 62 | |
el17arm | 3:140cad440684 | 63 | Gamepad gamepad; |
el17arm | 3:140cad440684 | 64 | Direction d = gamepad.get_direction(); |
el17arm | 3:140cad440684 | 65 | printf("Direction = %i\n",d); |
el17arm | 3:140cad440684 | 66 | |
el17arm | 2:ba653520a140 | 67 | |
el17arm | 3:140cad440684 | 68 | |
el17arm | 2:ba653520a140 | 69 | |
el17arm | 3:140cad440684 | 70 | if (d==1){ |
el17arm | 2:ba653520a140 | 71 | lcd.clear(); |
el17arm | 2:ba653520a140 | 72 | x = x+1; |
el17arm | 2:ba653520a140 | 73 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 2:ba653520a140 | 74 | lcd.refresh(); |
el17arm | 2:ba653520a140 | 75 | wait(0.25); |
el17arm | 2:ba653520a140 | 76 | |
el17arm | 2:ba653520a140 | 77 | } |
el17arm | 2:ba653520a140 | 78 | |
el17arm | 2:ba653520a140 | 79 | if (d == 7){ |
el17arm | 2:ba653520a140 | 80 | |
el17arm | 2:ba653520a140 | 81 | lcd.clear(); |
el17arm | 2:ba653520a140 | 82 | x = x-1; |
el17arm | 2:ba653520a140 | 83 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 2:ba653520a140 | 84 | lcd.refresh(); |
el17arm | 2:ba653520a140 | 85 | wait(0.25); |
el17arm | 2:ba653520a140 | 86 | } |
el17arm | 2:ba653520a140 | 87 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 2:ba653520a140 | 88 | lcd.refresh(); |
el17arm | 2:ba653520a140 | 89 | } |