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.
Dependencies: mbed Gamepad N5110
main.cpp@3:140cad440684, 2019-03-12 (annotated)
- Committer:
- el17arm
- Date:
- Tue Mar 12 00:21:58 2019 +0000
- Revision:
- 3:140cad440684
- Parent:
- 2:ba653520a140
- Child:
- 4:e7215819c9bc
replaced joystick library with gamepad library, not working as well. joystick displays wrong directions on coolterm then states 'operator out of memory and the board LED flashes red and the screen freezes
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 | 0:9e5f9e1c8ef9 | 8 | BusOut front_leds(PTA1,PTA2,PTC2,PTC3,PTC4, PTD3); |
| el17arm | 2:ba653520a140 | 9 | |
| el17arm | 2:ba653520a140 | 10 | int x = 0; |
| el17arm | 2:ba653520a140 | 11 | int y = 0; |
| el17arm | 2:ba653520a140 | 12 | |
| el17arm | 0:9e5f9e1c8ef9 | 13 | |
| el17arm | 0:9e5f9e1c8ef9 | 14 | int main() |
| el17arm | 0:9e5f9e1c8ef9 | 15 | { |
| el17arm | 0:9e5f9e1c8ef9 | 16 | init(); |
| el17arm | 3:140cad440684 | 17 | |
| el17arm | 0:9e5f9e1c8ef9 | 18 | while (1) { |
| el17arm | 2:ba653520a140 | 19 | contrast(); |
| el17arm | 2:ba653520a140 | 20 | minerbitmap(); |
| el17arm | 1:c80162894831 | 21 | |
| el17arm | 3:140cad440684 | 22 | |
| el17arm | 0:9e5f9e1c8ef9 | 23 | } |
| el17arm | 0:9e5f9e1c8ef9 | 24 | |
| el17arm | 0:9e5f9e1c8ef9 | 25 | } |
| el17arm | 0:9e5f9e1c8ef9 | 26 | |
| el17arm | 0:9e5f9e1c8ef9 | 27 | void init() |
| el17arm | 0:9e5f9e1c8ef9 | 28 | { |
| el17arm | 0:9e5f9e1c8ef9 | 29 | lcd.init(); |
| el17arm | 1:c80162894831 | 30 | lcd.normalMode(); // normal colour mode |
| el17arm | 1:c80162894831 | 31 | lcd.setBrightness(0.5); // put LED backlight on 50% |
| el17arm | 1:c80162894831 | 32 | lcd.refresh(); |
| el17arm | 1:c80162894831 | 33 | |
| el17arm | 0:9e5f9e1c8ef9 | 34 | front_leds = 0b111111; |
| el17arm | 1:c80162894831 | 35 | } |
| el17arm | 1:c80162894831 | 36 | |
| el17arm | 1:c80162894831 | 37 | void contrast() |
| el17arm | 1:c80162894831 | 38 | { |
| el17arm | 1:c80162894831 | 39 | lcd.refresh(); |
| el17arm | 1:c80162894831 | 40 | float con = pot0.read(); |
| el17arm | 1:c80162894831 | 41 | lcd.setContrast(con); |
| el17arm | 1:c80162894831 | 42 | |
| el17arm | 2:ba653520a140 | 43 | } |
| el17arm | 2:ba653520a140 | 44 | |
| el17arm | 2:ba653520a140 | 45 | void minerbitmap() |
| el17arm | 2:ba653520a140 | 46 | { |
| el17arm | 2:ba653520a140 | 47 | const int miner[13][5] = { |
| el17arm | 2:ba653520a140 | 48 | 0,0,0,1,1, |
| el17arm | 2:ba653520a140 | 49 | 0,1,1,1,1, |
| el17arm | 2:ba653520a140 | 50 | 0,1,0,1,0, |
| el17arm | 2:ba653520a140 | 51 | 0,1,1,1,1, |
| el17arm | 2:ba653520a140 | 52 | 0,1,1,1,0, |
| el17arm | 2:ba653520a140 | 53 | 0,0,1,0,0, |
| el17arm | 2:ba653520a140 | 54 | 1,1,1,1,1, |
| el17arm | 2:ba653520a140 | 55 | 1,1,1,1,1, |
| el17arm | 2:ba653520a140 | 56 | 1,1,1,1,1, |
| el17arm | 2:ba653520a140 | 57 | 0,1,1,1,0, |
| el17arm | 2:ba653520a140 | 58 | 0,1,0,1,0, |
| el17arm | 2:ba653520a140 | 59 | 0,1,1,1,1, |
| el17arm | 2:ba653520a140 | 60 | }; |
| el17arm | 2:ba653520a140 | 61 | |
| el17arm | 2:ba653520a140 | 62 | lcd.clear(); |
| el17arm | 2:ba653520a140 | 63 | |
| el17arm | 3:140cad440684 | 64 | Gamepad gamepad; |
| el17arm | 3:140cad440684 | 65 | Direction d = gamepad.get_direction(); |
| el17arm | 3:140cad440684 | 66 | printf("Direction = %i\n",d); |
| el17arm | 3:140cad440684 | 67 | |
| el17arm | 2:ba653520a140 | 68 | |
| el17arm | 3:140cad440684 | 69 | |
| el17arm | 2:ba653520a140 | 70 | |
| el17arm | 3:140cad440684 | 71 | if (d==1){ |
| el17arm | 2:ba653520a140 | 72 | lcd.clear(); |
| el17arm | 2:ba653520a140 | 73 | x = x+1; |
| el17arm | 2:ba653520a140 | 74 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
| el17arm | 2:ba653520a140 | 75 | lcd.refresh(); |
| el17arm | 2:ba653520a140 | 76 | wait(0.25); |
| el17arm | 2:ba653520a140 | 77 | |
| el17arm | 2:ba653520a140 | 78 | } |
| el17arm | 2:ba653520a140 | 79 | |
| el17arm | 2:ba653520a140 | 80 | if (d == 7){ |
| el17arm | 2:ba653520a140 | 81 | |
| el17arm | 2:ba653520a140 | 82 | lcd.clear(); |
| el17arm | 2:ba653520a140 | 83 | x = x-1; |
| el17arm | 2:ba653520a140 | 84 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
| el17arm | 2:ba653520a140 | 85 | lcd.refresh(); |
| el17arm | 2:ba653520a140 | 86 | wait(0.25); |
| el17arm | 2:ba653520a140 | 87 | } |
| 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 | } |