![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Early commits of my project
Dependencies: mbed Gamepad N5110
main.cpp@2:ba653520a140, 2019-03-11 (annotated)
- Committer:
- el17arm
- Date:
- Mon Mar 11 22:46:54 2019 +0000
- Revision:
- 2:ba653520a140
- Parent:
- 1:c80162894831
- Child:
- 3:140cad440684
additions:; bitmap created in middle of screen; bitmap can move left and right; jump function included but not working properly.;
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 | 0:9e5f9e1c8ef9 | 3 | #include "Joystick.h" |
el17arm | 0:9e5f9e1c8ef9 | 4 | |
el17arm | 0:9e5f9e1c8ef9 | 5 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17arm | 0:9e5f9e1c8ef9 | 6 | Joystick joystick(PTB10,PTB11,PTC16); |
el17arm | 1:c80162894831 | 7 | AnalogIn pot0(PTB2); |
el17arm | 0:9e5f9e1c8ef9 | 8 | DigitalIn joy_button(PTC16); |
el17arm | 0:9e5f9e1c8ef9 | 9 | BusOut front_leds(PTA1,PTA2,PTC2,PTC3,PTC4, PTD3); |
el17arm | 2:ba653520a140 | 10 | DigitalIn jump(PTC16); |
el17arm | 2:ba653520a140 | 11 | DigitalIn jumpa(PTB9); |
el17arm | 2:ba653520a140 | 12 | |
el17arm | 2:ba653520a140 | 13 | int x = 0; |
el17arm | 2:ba653520a140 | 14 | int y = 0; |
el17arm | 2:ba653520a140 | 15 | |
el17arm | 0:9e5f9e1c8ef9 | 16 | |
el17arm | 0:9e5f9e1c8ef9 | 17 | int main() |
el17arm | 0:9e5f9e1c8ef9 | 18 | { |
el17arm | 0:9e5f9e1c8ef9 | 19 | init(); |
el17arm | 2:ba653520a140 | 20 | minerbitmap(); |
el17arm | 1:c80162894831 | 21 | |
el17arm | 1:c80162894831 | 22 | |
el17arm | 2:ba653520a140 | 23 | |
el17arm | 2:ba653520a140 | 24 | |
el17arm | 0:9e5f9e1c8ef9 | 25 | while (1) { |
el17arm | 2:ba653520a140 | 26 | contrast(); |
el17arm | 2:ba653520a140 | 27 | minerbitmap(); |
el17arm | 1:c80162894831 | 28 | |
el17arm | 0:9e5f9e1c8ef9 | 29 | } |
el17arm | 0:9e5f9e1c8ef9 | 30 | |
el17arm | 0:9e5f9e1c8ef9 | 31 | } |
el17arm | 0:9e5f9e1c8ef9 | 32 | |
el17arm | 0:9e5f9e1c8ef9 | 33 | void init() |
el17arm | 0:9e5f9e1c8ef9 | 34 | { |
el17arm | 0:9e5f9e1c8ef9 | 35 | lcd.init(); |
el17arm | 1:c80162894831 | 36 | lcd.normalMode(); // normal colour mode |
el17arm | 1:c80162894831 | 37 | lcd.setBrightness(0.5); // put LED backlight on 50% |
el17arm | 1:c80162894831 | 38 | lcd.refresh(); |
el17arm | 1:c80162894831 | 39 | |
el17arm | 1:c80162894831 | 40 | joystick.init(); |
el17arm | 0:9e5f9e1c8ef9 | 41 | front_leds = 0b111111; |
el17arm | 1:c80162894831 | 42 | } |
el17arm | 1:c80162894831 | 43 | |
el17arm | 1:c80162894831 | 44 | void contrast() |
el17arm | 1:c80162894831 | 45 | { |
el17arm | 1:c80162894831 | 46 | lcd.refresh(); |
el17arm | 1:c80162894831 | 47 | float con = pot0.read(); |
el17arm | 1:c80162894831 | 48 | lcd.setContrast(con); |
el17arm | 1:c80162894831 | 49 | |
el17arm | 2:ba653520a140 | 50 | } |
el17arm | 2:ba653520a140 | 51 | |
el17arm | 2:ba653520a140 | 52 | void minerbitmap() |
el17arm | 2:ba653520a140 | 53 | { |
el17arm | 2:ba653520a140 | 54 | const int miner[13][5] = { |
el17arm | 2:ba653520a140 | 55 | 0,0,0,1,1, |
el17arm | 2:ba653520a140 | 56 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 57 | 0,1,0,1,0, |
el17arm | 2:ba653520a140 | 58 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 59 | 0,1,1,1,0, |
el17arm | 2:ba653520a140 | 60 | 0,0,1,0,0, |
el17arm | 2:ba653520a140 | 61 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 62 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 63 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 64 | 0,1,1,1,0, |
el17arm | 2:ba653520a140 | 65 | 0,1,0,1,0, |
el17arm | 2:ba653520a140 | 66 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 67 | }; |
el17arm | 2:ba653520a140 | 68 | |
el17arm | 2:ba653520a140 | 69 | lcd.clear(); |
el17arm | 2:ba653520a140 | 70 | |
el17arm | 2:ba653520a140 | 71 | |
el17arm | 2:ba653520a140 | 72 | Direction d = joystick.get_direction(); |
el17arm | 2:ba653520a140 | 73 | printf("Direction = %i\n",d); |
el17arm | 2:ba653520a140 | 74 | |
el17arm | 2:ba653520a140 | 75 | if (d==3){ |
el17arm | 2:ba653520a140 | 76 | lcd.clear(); |
el17arm | 2:ba653520a140 | 77 | x = x+1; |
el17arm | 2:ba653520a140 | 78 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 2:ba653520a140 | 79 | lcd.refresh(); |
el17arm | 2:ba653520a140 | 80 | wait(0.25); |
el17arm | 2:ba653520a140 | 81 | |
el17arm | 2:ba653520a140 | 82 | } |
el17arm | 2:ba653520a140 | 83 | |
el17arm | 2:ba653520a140 | 84 | if (d == 7){ |
el17arm | 2:ba653520a140 | 85 | |
el17arm | 2:ba653520a140 | 86 | lcd.clear(); |
el17arm | 2:ba653520a140 | 87 | x = x-1; |
el17arm | 2:ba653520a140 | 88 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 2:ba653520a140 | 89 | lcd.refresh(); |
el17arm | 2:ba653520a140 | 90 | wait(0.25); |
el17arm | 2:ba653520a140 | 91 | } |
el17arm | 2:ba653520a140 | 92 | if (jump == 1) |
el17arm | 2:ba653520a140 | 93 | { |
el17arm | 2:ba653520a140 | 94 | lcd.clear(); |
el17arm | 2:ba653520a140 | 95 | |
el17arm | 2:ba653520a140 | 96 | printf("Button Pressed\n"); |
el17arm | 2:ba653520a140 | 97 | y = y -5; |
el17arm | 2:ba653520a140 | 98 | wait(0.1); |
el17arm | 2:ba653520a140 | 99 | lcd.refresh(); |
el17arm | 2:ba653520a140 | 100 | } |
el17arm | 2:ba653520a140 | 101 | else { |
el17arm | 2:ba653520a140 | 102 | y = 0; |
el17arm | 2:ba653520a140 | 103 | } |
el17arm | 2:ba653520a140 | 104 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 2:ba653520a140 | 105 | lcd.refresh(); |
el17arm | 2:ba653520a140 | 106 | } |