Andrew Lindsay
/
N3310LCD_Demo
N3310LCD library demo
Fork of N3310LCD by
main.cpp@1:740d0a3999a9, 2013-03-10 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Sun Mar 10 18:29:43 2013 +0000
- Revision:
- 1:740d0a3999a9
- Parent:
- 0:36fb749b83c7
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
snatch59 | 0:36fb749b83c7 | 1 | /* |
snatch59 | 0:36fb749b83c7 | 2 | * N3310LCD. A program to interface mbed with the nuelectronics |
snatch59 | 0:36fb749b83c7 | 3 | * Nokia 3310 LCD shield from www.nuelectronics.com. Ported from |
snatch59 | 0:36fb749b83c7 | 4 | * the nuelectronics Arduino code. |
snatch59 | 0:36fb749b83c7 | 5 | * |
snatch59 | 0:36fb749b83c7 | 6 | * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk> |
snatch59 | 0:36fb749b83c7 | 7 | * |
SomeRandomBloke | 1:740d0a3999a9 | 8 | * Converted to a mbed library by Andrew D. Lindsay |
SomeRandomBloke | 1:740d0a3999a9 | 9 | * |
snatch59 | 0:36fb749b83c7 | 10 | * This file is part of N3310LCD. |
snatch59 | 0:36fb749b83c7 | 11 | * |
snatch59 | 0:36fb749b83c7 | 12 | * N3310LCD is free software: you can redistribute it and/or modify |
snatch59 | 0:36fb749b83c7 | 13 | * it under the terms of the GNU General Public License as published by |
snatch59 | 0:36fb749b83c7 | 14 | * the Free Software Foundation, either version 3 of the License, or |
snatch59 | 0:36fb749b83c7 | 15 | * (at your option) any later version. |
SomeRandomBloke | 1:740d0a3999a9 | 16 | * |
snatch59 | 0:36fb749b83c7 | 17 | * N3310LCD is distributed in the hope that it will be useful, |
snatch59 | 0:36fb749b83c7 | 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
snatch59 | 0:36fb749b83c7 | 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
snatch59 | 0:36fb749b83c7 | 20 | * GNU General Public License for more details. |
snatch59 | 0:36fb749b83c7 | 21 | * |
snatch59 | 0:36fb749b83c7 | 22 | * You should have received a copy of the GNU General Public License |
snatch59 | 0:36fb749b83c7 | 23 | * along with N3310LCD. If not, see <http://www.gnu.org/licenses/>. |
snatch59 | 0:36fb749b83c7 | 24 | */ |
snatch59 | 0:36fb749b83c7 | 25 | |
snatch59 | 0:36fb749b83c7 | 26 | #include "N3310SPIConfig.h" |
snatch59 | 0:36fb749b83c7 | 27 | #include "N3310LCD.h" |
snatch59 | 0:36fb749b83c7 | 28 | #include "Joystick.h" |
snatch59 | 0:36fb749b83c7 | 29 | #include "mbed_bmp.h" |
SomeRandomBloke | 1:740d0a3999a9 | 30 | #include "pacman.h" |
SomeRandomBloke | 1:740d0a3999a9 | 31 | #include "bitmap.h" |
snatch59 | 0:36fb749b83c7 | 32 | |
snatch59 | 0:36fb749b83c7 | 33 | // demo for nuelectronics Nokia 3310 LCD shield (www.nuelectronics.com) |
SomeRandomBloke | 1:740d0a3999a9 | 34 | // |
snatch59 | 0:36fb749b83c7 | 35 | |
snatch59 | 0:36fb749b83c7 | 36 | // menu starting points |
snatch59 | 0:36fb749b83c7 | 37 | #define MENU_X 10 // 0-83 |
SomeRandomBloke | 1:740d0a3999a9 | 38 | #define MENU_Y 0 // 0-5 |
SomeRandomBloke | 1:740d0a3999a9 | 39 | |
SomeRandomBloke | 1:740d0a3999a9 | 40 | #define DEMO_ITEMS 5 |
snatch59 | 0:36fb749b83c7 | 41 | |
SomeRandomBloke | 1:740d0a3999a9 | 42 | void temperature(N3310LCD* lcd, Joystick* jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 43 | void charmap(N3310LCD* lcd, Joystick* jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 44 | void bitmap(N3310LCD* lcd, Joystick* jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 45 | void about(N3310LCD* lcd, Joystick* jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 46 | void graphics(N3310LCD* lcd, Joystick* jstick); |
snatch59 | 0:36fb749b83c7 | 47 | |
snatch59 | 0:36fb749b83c7 | 48 | // menu definition |
SomeRandomBloke | 1:740d0a3999a9 | 49 | char menu_items[DEMO_ITEMS][12] = { |
snatch59 | 0:36fb749b83c7 | 50 | "TEMPERATURE", |
snatch59 | 0:36fb749b83c7 | 51 | "CHAR MAP", |
snatch59 | 0:36fb749b83c7 | 52 | "BITMAP", |
SomeRandomBloke | 1:740d0a3999a9 | 53 | "GRAPHICS", |
SomeRandomBloke | 1:740d0a3999a9 | 54 | "ABOUT" |
snatch59 | 0:36fb749b83c7 | 55 | }; |
snatch59 | 0:36fb749b83c7 | 56 | |
SomeRandomBloke | 1:740d0a3999a9 | 57 | void (*menu_funcs[DEMO_ITEMS])(N3310LCD*,Joystick*) = { |
SomeRandomBloke | 1:740d0a3999a9 | 58 | temperature, |
SomeRandomBloke | 1:740d0a3999a9 | 59 | charmap, |
SomeRandomBloke | 1:740d0a3999a9 | 60 | bitmap, |
SomeRandomBloke | 1:740d0a3999a9 | 61 | graphics, |
SomeRandomBloke | 1:740d0a3999a9 | 62 | about |
SomeRandomBloke | 1:740d0a3999a9 | 63 | }; |
SomeRandomBloke | 1:740d0a3999a9 | 64 | |
SomeRandomBloke | 1:740d0a3999a9 | 65 | void temperature(N3310LCD* lcd, Joystick* jstick) |
snatch59 | 0:36fb749b83c7 | 66 | { |
snatch59 | 0:36fb749b83c7 | 67 | lcd->writeStringBig(5, 1, "+21.12", NORMAL); |
snatch59 | 0:36fb749b83c7 | 68 | lcd->writeString(73, 2, "C", NORMAL); |
snatch59 | 0:36fb749b83c7 | 69 | } |
snatch59 | 0:36fb749b83c7 | 70 | |
SomeRandomBloke | 1:740d0a3999a9 | 71 | void charmap(N3310LCD* lcd, Joystick* jstick) |
snatch59 | 0:36fb749b83c7 | 72 | { |
SomeRandomBloke | 1:740d0a3999a9 | 73 | for(int i = 0; i < 5; i++) { |
SomeRandomBloke | 1:740d0a3999a9 | 74 | for(int j = 0; j < 14; j++) { |
SomeRandomBloke | 1:740d0a3999a9 | 75 | lcd->locate(j*6, i); |
SomeRandomBloke | 1:740d0a3999a9 | 76 | lcd->writeChar(i*14 + j + 32, NORMAL); |
snatch59 | 0:36fb749b83c7 | 77 | } |
snatch59 | 0:36fb749b83c7 | 78 | } |
snatch59 | 0:36fb749b83c7 | 79 | } |
snatch59 | 0:36fb749b83c7 | 80 | |
SomeRandomBloke | 1:740d0a3999a9 | 81 | void bitmap(N3310LCD* lcd, Joystick* jstick) |
snatch59 | 0:36fb749b83c7 | 82 | { |
SomeRandomBloke | 1:740d0a3999a9 | 83 | for( int i=0; i<10; i++ ) { |
SomeRandomBloke | 1:740d0a3999a9 | 84 | lcd->drawBitmap(20, 1, mbed_bmp, 48, 24); |
SomeRandomBloke | 1:740d0a3999a9 | 85 | wait(1); |
SomeRandomBloke | 1:740d0a3999a9 | 86 | lcd->clearBitmap(20, 1, 48, 24); |
SomeRandomBloke | 1:740d0a3999a9 | 87 | lcd->drawBitmap(0, 0, fy1, 84, 48); |
SomeRandomBloke | 1:740d0a3999a9 | 88 | wait(1); |
SomeRandomBloke | 1:740d0a3999a9 | 89 | lcd->clearBitmap(0, 0, 84, 48); |
SomeRandomBloke | 1:740d0a3999a9 | 90 | } |
snatch59 | 0:36fb749b83c7 | 91 | lcd->drawBitmap(20, 1, mbed_bmp, 48, 24); |
snatch59 | 0:36fb749b83c7 | 92 | } |
snatch59 | 0:36fb749b83c7 | 93 | |
SomeRandomBloke | 1:740d0a3999a9 | 94 | void about(N3310LCD* lcd, Joystick* jstick) |
snatch59 | 0:36fb749b83c7 | 95 | { |
snatch59 | 0:36fb749b83c7 | 96 | lcd->writeString(0, 1, "Nokia 3310 LCD", NORMAL); |
snatch59 | 0:36fb749b83c7 | 97 | lcd->writeString(15, 2, "driven by", NORMAL); |
SomeRandomBloke | 1:740d0a3999a9 | 98 | lcd->writeString(10, 3, "KL25Z mbed", NORMAL); |
snatch59 | 0:36fb749b83c7 | 99 | } |
snatch59 | 0:36fb749b83c7 | 100 | |
SomeRandomBloke | 1:740d0a3999a9 | 101 | |
snatch59 | 0:36fb749b83c7 | 102 | |
snatch59 | 0:36fb749b83c7 | 103 | void initMenu(N3310LCD* lcd) |
snatch59 | 0:36fb749b83c7 | 104 | { |
snatch59 | 0:36fb749b83c7 | 105 | lcd->writeString(MENU_X, MENU_Y, menu_items[0], HIGHLIGHT ); |
SomeRandomBloke | 1:740d0a3999a9 | 106 | |
SomeRandomBloke | 1:740d0a3999a9 | 107 | for (int i = 1; i < DEMO_ITEMS; i++) { |
snatch59 | 0:36fb749b83c7 | 108 | lcd->writeString(MENU_X, MENU_Y + i, menu_items[i], NORMAL); |
snatch59 | 0:36fb749b83c7 | 109 | } |
snatch59 | 0:36fb749b83c7 | 110 | } |
snatch59 | 0:36fb749b83c7 | 111 | |
snatch59 | 0:36fb749b83c7 | 112 | void waitforOKKey(N3310LCD* lcd, Joystick* jstick) |
snatch59 | 0:36fb749b83c7 | 113 | { |
snatch59 | 0:36fb749b83c7 | 114 | lcd->writeString(38, 5, "OK", HIGHLIGHT ); |
snatch59 | 0:36fb749b83c7 | 115 | |
snatch59 | 0:36fb749b83c7 | 116 | int key = 0xFF; |
SomeRandomBloke | 1:740d0a3999a9 | 117 | while (key != CENTER_KEY) { |
SomeRandomBloke | 1:740d0a3999a9 | 118 | for (int i = 0; i < NUM_KEYS; i++) { |
SomeRandomBloke | 1:740d0a3999a9 | 119 | if (jstick->getKeyState(i) !=0) { |
snatch59 | 0:36fb749b83c7 | 120 | jstick->resetKeyState(i); // reset |
snatch59 | 0:36fb749b83c7 | 121 | if (CENTER_KEY == i) key = CENTER_KEY; |
snatch59 | 0:36fb749b83c7 | 122 | } |
snatch59 | 0:36fb749b83c7 | 123 | } |
snatch59 | 0:36fb749b83c7 | 124 | } |
snatch59 | 0:36fb749b83c7 | 125 | } |
snatch59 | 0:36fb749b83c7 | 126 | |
SomeRandomBloke | 1:740d0a3999a9 | 127 | // Check if joystick is moved or pressed |
SomeRandomBloke | 1:740d0a3999a9 | 128 | uint8_t checkKeypressed( Joystick* jstick) |
SomeRandomBloke | 1:740d0a3999a9 | 129 | { |
SomeRandomBloke | 1:740d0a3999a9 | 130 | uint8_t key = 0xFF; |
SomeRandomBloke | 1:740d0a3999a9 | 131 | |
SomeRandomBloke | 1:740d0a3999a9 | 132 | for(int i=0; i<NUM_KEYS; i++) { |
SomeRandomBloke | 1:740d0a3999a9 | 133 | if (jstick->getKeyState(i) !=0) { |
SomeRandomBloke | 1:740d0a3999a9 | 134 | jstick->resetKeyState(i); // reset |
SomeRandomBloke | 1:740d0a3999a9 | 135 | if (CENTER_KEY == i) key = CENTER_KEY; |
SomeRandomBloke | 1:740d0a3999a9 | 136 | } |
SomeRandomBloke | 1:740d0a3999a9 | 137 | } |
SomeRandomBloke | 1:740d0a3999a9 | 138 | return key; |
SomeRandomBloke | 1:740d0a3999a9 | 139 | } |
SomeRandomBloke | 1:740d0a3999a9 | 140 | |
SomeRandomBloke | 1:740d0a3999a9 | 141 | /* |
snatch59 | 0:36fb749b83c7 | 142 | void autoDemo(N3310LCD* lcd) |
snatch59 | 0:36fb749b83c7 | 143 | { |
snatch59 | 0:36fb749b83c7 | 144 | while (true) |
snatch59 | 0:36fb749b83c7 | 145 | { |
snatch59 | 0:36fb749b83c7 | 146 | for (int i = 0; i < DEMO_ITEMS; i++) |
snatch59 | 0:36fb749b83c7 | 147 | { |
snatch59 | 0:36fb749b83c7 | 148 | lcd->cls(); |
snatch59 | 0:36fb749b83c7 | 149 | lcd->backlight(ON); |
snatch59 | 0:36fb749b83c7 | 150 | wait(1); |
SomeRandomBloke | 1:740d0a3999a9 | 151 | |
snatch59 | 0:36fb749b83c7 | 152 | (*menu_funcs[i])(lcd); |
SomeRandomBloke | 1:740d0a3999a9 | 153 | |
snatch59 | 0:36fb749b83c7 | 154 | wait(3); |
SomeRandomBloke | 1:740d0a3999a9 | 155 | |
snatch59 | 0:36fb749b83c7 | 156 | lcd->backlight(OFF); |
snatch59 | 0:36fb749b83c7 | 157 | wait(3); |
snatch59 | 0:36fb749b83c7 | 158 | } |
snatch59 | 0:36fb749b83c7 | 159 | } |
snatch59 | 0:36fb749b83c7 | 160 | } |
SomeRandomBloke | 1:740d0a3999a9 | 161 | */ |
snatch59 | 0:36fb749b83c7 | 162 | |
SomeRandomBloke | 1:740d0a3999a9 | 163 | // Display the simple graphics demo |
SomeRandomBloke | 1:740d0a3999a9 | 164 | void graphics(N3310LCD* lcd, Joystick* jstick) |
SomeRandomBloke | 1:740d0a3999a9 | 165 | { |
SomeRandomBloke | 1:740d0a3999a9 | 166 | lcd->writeString( 0, 1, "Text Demo", NORMAL); |
SomeRandomBloke | 1:740d0a3999a9 | 167 | lcd->writeString(24, 5, "START", HIGHLIGHT ); |
SomeRandomBloke | 1:740d0a3999a9 | 168 | checkKeypressed(jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 169 | lcd->cls(); |
SomeRandomBloke | 1:740d0a3999a9 | 170 | |
SomeRandomBloke | 1:740d0a3999a9 | 171 | lcd->writeStringBig( 0, 0, "123456", NORMAL ); |
SomeRandomBloke | 1:740d0a3999a9 | 172 | lcd->writeStringBig( 0, 3, "7890+-.", NORMAL ); |
SomeRandomBloke | 1:740d0a3999a9 | 173 | wait(2); |
SomeRandomBloke | 1:740d0a3999a9 | 174 | |
SomeRandomBloke | 1:740d0a3999a9 | 175 | lcd->writeStringBig( 0, 0, "123456", HIGHLIGHT ); |
SomeRandomBloke | 1:740d0a3999a9 | 176 | lcd->writeStringBig( 0, 3, "7890+-.", HIGHLIGHT ); |
SomeRandomBloke | 1:740d0a3999a9 | 177 | wait(2); |
SomeRandomBloke | 1:740d0a3999a9 | 178 | |
SomeRandomBloke | 1:740d0a3999a9 | 179 | lcd->cls(); |
SomeRandomBloke | 1:740d0a3999a9 | 180 | |
SomeRandomBloke | 1:740d0a3999a9 | 181 | lcd->writeString( 0, 1, "Graphic Demo", NORMAL); |
SomeRandomBloke | 1:740d0a3999a9 | 182 | lcd->writeString(24, 5, "START", HIGHLIGHT ); |
SomeRandomBloke | 1:740d0a3999a9 | 183 | checkKeypressed(jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 184 | lcd->cls(); |
SomeRandomBloke | 1:740d0a3999a9 | 185 | // Draw some circles pulsing in and out |
SomeRandomBloke | 1:740d0a3999a9 | 186 | for(int a=0; a< 4; a++) { |
SomeRandomBloke | 1:740d0a3999a9 | 187 | for( int r = 1; r < 49; r+=1 ) { |
SomeRandomBloke | 1:740d0a3999a9 | 188 | lcd->drawCircle(42, 24, r, PIXEL_ON ); |
SomeRandomBloke | 1:740d0a3999a9 | 189 | wait(0.010); |
SomeRandomBloke | 1:740d0a3999a9 | 190 | } |
SomeRandomBloke | 1:740d0a3999a9 | 191 | wait(0.010); |
SomeRandomBloke | 1:740d0a3999a9 | 192 | for( int r = 48; r >0; r-=1 ) { |
SomeRandomBloke | 1:740d0a3999a9 | 193 | wait(0.010); |
SomeRandomBloke | 1:740d0a3999a9 | 194 | lcd->drawCircle(42, 24, r, PIXEL_OFF ); |
SomeRandomBloke | 1:740d0a3999a9 | 195 | } |
SomeRandomBloke | 1:740d0a3999a9 | 196 | } |
SomeRandomBloke | 1:740d0a3999a9 | 197 | |
SomeRandomBloke | 1:740d0a3999a9 | 198 | // More circles |
SomeRandomBloke | 1:740d0a3999a9 | 199 | for( int xc = 10; xc < 85; xc+=15 ) { |
SomeRandomBloke | 1:740d0a3999a9 | 200 | lcd->drawCircle(xc, 24, 20, PIXEL_ON ); |
SomeRandomBloke | 1:740d0a3999a9 | 201 | } |
SomeRandomBloke | 1:740d0a3999a9 | 202 | wait( 2 ); |
SomeRandomBloke | 1:740d0a3999a9 | 203 | |
SomeRandomBloke | 1:740d0a3999a9 | 204 | // Draw diagonal lines using XOR colour |
SomeRandomBloke | 1:740d0a3999a9 | 205 | lcd->drawLine(0,0,83,47, PIXEL_XOR); |
SomeRandomBloke | 1:740d0a3999a9 | 206 | lcd->drawLine(0,43,83,0, PIXEL_XOR); |
SomeRandomBloke | 1:740d0a3999a9 | 207 | |
SomeRandomBloke | 1:740d0a3999a9 | 208 | wait( 2 ); |
SomeRandomBloke | 1:740d0a3999a9 | 209 | |
SomeRandomBloke | 1:740d0a3999a9 | 210 | // Draw a rectangle |
SomeRandomBloke | 1:740d0a3999a9 | 211 | lcd->drawRectangle(5,5,78,42, PIXEL_ON); |
SomeRandomBloke | 1:740d0a3999a9 | 212 | |
SomeRandomBloke | 1:740d0a3999a9 | 213 | wait( 2 ); |
SomeRandomBloke | 1:740d0a3999a9 | 214 | |
SomeRandomBloke | 1:740d0a3999a9 | 215 | // Draw 2 filled rectangles |
SomeRandomBloke | 1:740d0a3999a9 | 216 | lcd->drawFilledRectangle(5,3,78,20, PIXEL_ON); |
SomeRandomBloke | 1:740d0a3999a9 | 217 | lcd->drawFilledRectangle(5,25,78,42, PIXEL_ON); |
SomeRandomBloke | 1:740d0a3999a9 | 218 | |
SomeRandomBloke | 1:740d0a3999a9 | 219 | wait( 2 ); |
SomeRandomBloke | 1:740d0a3999a9 | 220 | |
SomeRandomBloke | 1:740d0a3999a9 | 221 | // Draw bitmap image |
SomeRandomBloke | 1:740d0a3999a9 | 222 | lcd->drawBitmap( 0,0, fy1,84,48); |
SomeRandomBloke | 1:740d0a3999a9 | 223 | wait(5); |
SomeRandomBloke | 1:740d0a3999a9 | 224 | |
SomeRandomBloke | 1:740d0a3999a9 | 225 | // Pacman animation |
SomeRandomBloke | 1:740d0a3999a9 | 226 | lcd->cls(); |
SomeRandomBloke | 1:740d0a3999a9 | 227 | int px = 0; |
SomeRandomBloke | 1:740d0a3999a9 | 228 | int py = 1; |
SomeRandomBloke | 1:740d0a3999a9 | 229 | float pause=0.060; |
SomeRandomBloke | 1:740d0a3999a9 | 230 | for( int p=0; p <9; p++) { |
SomeRandomBloke | 1:740d0a3999a9 | 231 | lcd->drawBitmap( px,py, pacman1,32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 232 | wait( pause ); |
SomeRandomBloke | 1:740d0a3999a9 | 233 | lcd->clearBitmap( px++,py, 32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 234 | lcd->drawBitmap( px,py, pacman2,32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 235 | wait( pause ); |
SomeRandomBloke | 1:740d0a3999a9 | 236 | lcd->clearBitmap( px++,py, 32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 237 | lcd->drawBitmap( px,py, pacman3,32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 238 | wait( pause ); |
SomeRandomBloke | 1:740d0a3999a9 | 239 | lcd->clearBitmap( px++,py, 32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 240 | lcd->drawBitmap( px,py, pacman4,32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 241 | wait( pause ); |
SomeRandomBloke | 1:740d0a3999a9 | 242 | lcd->clearBitmap( px++,py, 32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 243 | lcd->drawBitmap( px,py, pacman3,32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 244 | wait( pause ); |
SomeRandomBloke | 1:740d0a3999a9 | 245 | lcd->clearBitmap( px++,py, 32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 246 | lcd->drawBitmap( px,py, pacman2,32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 247 | wait( pause ); |
SomeRandomBloke | 1:740d0a3999a9 | 248 | lcd->clearBitmap( px++,py, 32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 249 | } |
SomeRandomBloke | 1:740d0a3999a9 | 250 | lcd->drawBitmap( px,py, pacman1,32,32); |
SomeRandomBloke | 1:740d0a3999a9 | 251 | |
SomeRandomBloke | 1:740d0a3999a9 | 252 | wait( 5 ); |
SomeRandomBloke | 1:740d0a3999a9 | 253 | |
SomeRandomBloke | 1:740d0a3999a9 | 254 | lcd->cls(); |
SomeRandomBloke | 1:740d0a3999a9 | 255 | |
SomeRandomBloke | 1:740d0a3999a9 | 256 | lcd->writeString( 0, 1, "Graphic Demo", NORMAL); |
SomeRandomBloke | 1:740d0a3999a9 | 257 | lcd->writeString( 0, 3, "The End!!", NORMAL); |
SomeRandomBloke | 1:740d0a3999a9 | 258 | // lcd->writeString(38, 5, "OK", HIGHLIGHT ); |
SomeRandomBloke | 1:740d0a3999a9 | 259 | waitforOKKey(lcd,jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 260 | } |
SomeRandomBloke | 1:740d0a3999a9 | 261 | |
SomeRandomBloke | 1:740d0a3999a9 | 262 | |
SomeRandomBloke | 1:740d0a3999a9 | 263 | int main() |
snatch59 | 0:36fb749b83c7 | 264 | { |
snatch59 | 0:36fb749b83c7 | 265 | Joystick jstick(N3310SPIPort::AD0); |
snatch59 | 0:36fb749b83c7 | 266 | N3310LCD lcd(N3310SPIPort::MOSI, N3310SPIPort::MISO, N3310SPIPort::SCK, |
snatch59 | 0:36fb749b83c7 | 267 | N3310SPIPort::CE, N3310SPIPort::DAT_CMD, N3310SPIPort::LCD_RST, |
snatch59 | 0:36fb749b83c7 | 268 | N3310SPIPort::BL_ON); |
snatch59 | 0:36fb749b83c7 | 269 | lcd.init(); |
snatch59 | 0:36fb749b83c7 | 270 | lcd.cls(); |
snatch59 | 0:36fb749b83c7 | 271 | lcd.backlight(ON); |
SomeRandomBloke | 1:740d0a3999a9 | 272 | |
snatch59 | 0:36fb749b83c7 | 273 | // demo stuff |
snatch59 | 0:36fb749b83c7 | 274 | // autoDemo(&lcd); |
SomeRandomBloke | 1:740d0a3999a9 | 275 | |
snatch59 | 0:36fb749b83c7 | 276 | initMenu(&lcd); |
snatch59 | 0:36fb749b83c7 | 277 | int currentMenuItem = 0; |
snatch59 | 0:36fb749b83c7 | 278 | Ticker jstickPoll; |
snatch59 | 0:36fb749b83c7 | 279 | jstickPoll.attach(&jstick, &Joystick::updateADCKey, 0.01); // check ever 10ms |
SomeRandomBloke | 1:740d0a3999a9 | 280 | |
SomeRandomBloke | 1:740d0a3999a9 | 281 | |
SomeRandomBloke | 1:740d0a3999a9 | 282 | while (true) { |
SomeRandomBloke | 1:740d0a3999a9 | 283 | for (int i = 0; i < NUM_KEYS; i++) { |
SomeRandomBloke | 1:740d0a3999a9 | 284 | if (jstick.getKeyState(i) != 0) { |
SomeRandomBloke | 1:740d0a3999a9 | 285 | jstick.resetKeyState(i); // reset button flag |
SomeRandomBloke | 1:740d0a3999a9 | 286 | switch(i) { |
SomeRandomBloke | 1:740d0a3999a9 | 287 | case UP_KEY: |
SomeRandomBloke | 1:740d0a3999a9 | 288 | // current item to normal display |
SomeRandomBloke | 1:740d0a3999a9 | 289 | lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], NORMAL); |
SomeRandomBloke | 1:740d0a3999a9 | 290 | currentMenuItem -=1; |
SomeRandomBloke | 1:740d0a3999a9 | 291 | if (currentMenuItem <0) currentMenuItem = DEMO_ITEMS -1; |
SomeRandomBloke | 1:740d0a3999a9 | 292 | // next item to highlight display |
SomeRandomBloke | 1:740d0a3999a9 | 293 | lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], HIGHLIGHT); |
SomeRandomBloke | 1:740d0a3999a9 | 294 | break; |
SomeRandomBloke | 1:740d0a3999a9 | 295 | |
SomeRandomBloke | 1:740d0a3999a9 | 296 | case DOWN_KEY: |
SomeRandomBloke | 1:740d0a3999a9 | 297 | // current item to normal display |
SomeRandomBloke | 1:740d0a3999a9 | 298 | lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], NORMAL); |
SomeRandomBloke | 1:740d0a3999a9 | 299 | currentMenuItem +=1; |
SomeRandomBloke | 1:740d0a3999a9 | 300 | if(currentMenuItem >(DEMO_ITEMS - 1)) currentMenuItem = 0; |
SomeRandomBloke | 1:740d0a3999a9 | 301 | // next item to highlight display |
SomeRandomBloke | 1:740d0a3999a9 | 302 | lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], HIGHLIGHT); |
SomeRandomBloke | 1:740d0a3999a9 | 303 | break; |
SomeRandomBloke | 1:740d0a3999a9 | 304 | |
SomeRandomBloke | 1:740d0a3999a9 | 305 | case LEFT_KEY: |
SomeRandomBloke | 1:740d0a3999a9 | 306 | initMenu(&lcd); |
SomeRandomBloke | 1:740d0a3999a9 | 307 | currentMenuItem = 0; |
SomeRandomBloke | 1:740d0a3999a9 | 308 | break; |
SomeRandomBloke | 1:740d0a3999a9 | 309 | |
SomeRandomBloke | 1:740d0a3999a9 | 310 | case RIGHT_KEY: |
SomeRandomBloke | 1:740d0a3999a9 | 311 | lcd.cls(); |
SomeRandomBloke | 1:740d0a3999a9 | 312 | (*menu_funcs[currentMenuItem])(&lcd, &jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 313 | waitforOKKey(&lcd, &jstick); |
SomeRandomBloke | 1:740d0a3999a9 | 314 | lcd.cls(); |
SomeRandomBloke | 1:740d0a3999a9 | 315 | initMenu(&lcd); |
SomeRandomBloke | 1:740d0a3999a9 | 316 | currentMenuItem = 0; |
SomeRandomBloke | 1:740d0a3999a9 | 317 | break; |
SomeRandomBloke | 1:740d0a3999a9 | 318 | } |
SomeRandomBloke | 1:740d0a3999a9 | 319 | } |
snatch59 | 0:36fb749b83c7 | 320 | } |
snatch59 | 0:36fb749b83c7 | 321 | } |
SomeRandomBloke | 1:740d0a3999a9 | 322 | |
SomeRandomBloke | 1:740d0a3999a9 | 323 | |
snatch59 | 0:36fb749b83c7 | 324 | } |