Behrooz Abdi
/
Tiger_LCD
Landtiger (LPC1768) graphics LCD demo.
main.cpp@5:0cfedc57cb06, 2021-06-03 (annotated)
- Committer:
- behrooz1980
- Date:
- Thu Jun 03 23:15:37 2021 +0000
- Revision:
- 5:0cfedc57cb06
- Parent:
- 4:cdeea87f25d8
cant export to keil
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:a8090b59eb05 | 1 | #include "mbed.h" |
wim | 0:a8090b59eb05 | 2 | #include "GLCD.h" |
wim | 0:a8090b59eb05 | 3 | |
wim | 0:a8090b59eb05 | 4 | //Host PC Baudrate (Virtual Com Port on USB) |
wim | 0:a8090b59eb05 | 5 | #define D_BAUDRATE 9600 |
wim | 0:a8090b59eb05 | 6 | //#define D_BAUDRATE 57600 |
wim | 0:a8090b59eb05 | 7 | |
wim | 4:cdeea87f25d8 | 8 | // Variables for Heartbeat and Status monitoring |
wim | 4:cdeea87f25d8 | 9 | //Note Port2 is used for the LCD |
wim | 4:cdeea87f25d8 | 10 | //DigitalOut myled1(P2_0); |
wim | 4:cdeea87f25d8 | 11 | //DigitalOut myled2(P2_1); |
wim | 4:cdeea87f25d8 | 12 | //DigitalOut myled3(P2_2); |
wim | 4:cdeea87f25d8 | 13 | //DigitalOut myled4(P2_3); |
wim | 4:cdeea87f25d8 | 14 | //DigitalOut myled5(P2_4); |
wim | 4:cdeea87f25d8 | 15 | //DigitalOut myled6(P2_5); |
wim | 4:cdeea87f25d8 | 16 | //DigitalOut myled7(P2_6); |
wim | 4:cdeea87f25d8 | 17 | //DigitalOut myled8(P2_7); |
wim | 0:a8090b59eb05 | 18 | |
wim | 4:cdeea87f25d8 | 19 | DigitalOut heartbeatLED(P3_26); //SD_PWR, LD3: active low |
wim | 4:cdeea87f25d8 | 20 | DigitalOut USB_Device_PU(P2_9); //USB Device Pull Up, LD14: active low (OK) |
wim | 4:cdeea87f25d8 | 21 | DigitalOut USB_Device_Up(P1_18); //USB Device Up, LD13: active low (OK) |
wim | 4:cdeea87f25d8 | 22 | //DigitalOut USB_Host_Power(P1_19); //USB Host Power, LD15: active low (does not seem to go high again? ?) |
wim | 4:cdeea87f25d8 | 23 | DigitalInOut USB_Host_Power(P1_19); //USB Host Power, LD15: active low (does not seem to go high again? ?) |
wim | 0:a8090b59eb05 | 24 | |
wim | 0:a8090b59eb05 | 25 | // Need this override function on non-mbed hardware to provide the MAC address. |
wim | 0:a8090b59eb05 | 26 | // |
wim | 0:a8090b59eb05 | 27 | // The mbed Ethernet library sets the MAC address by calling a weak function |
wim | 0:a8090b59eb05 | 28 | // extern "C" void mbed_mac_address(char * mac) to copy in a 6 Byte (12 character) MAC address. |
wim | 0:a8090b59eb05 | 29 | // This function performs a semihosting request to the mbed interface to get the serial number, |
wim | 0:a8090b59eb05 | 30 | // which contains a MAC address unique to every mbed device. |
wim | 0:a8090b59eb05 | 31 | // If you are using the eth library on your own board (i.e. not an mbed board), |
wim | 0:a8090b59eb05 | 32 | // you should implement your own extern "C" void mbed_mac_address(char * mac) function |
wim | 0:a8090b59eb05 | 33 | // to overwrite the existing one and avoid a call to the interface (which doesnt exist). |
wim | 0:a8090b59eb05 | 34 | |
wim | 0:a8090b59eb05 | 35 | extern "C" void mbed_mac_address(char * mac) { |
wim | 0:a8090b59eb05 | 36 | |
wim | 0:a8090b59eb05 | 37 | //mbed module clone |
wim | 0:a8090b59eb05 | 38 | mac[0] = 0x00; |
wim | 4:cdeea87f25d8 | 39 | mac[1] = 0x02; |
wim | 4:cdeea87f25d8 | 40 | mac[2] = 0xF7; |
wim | 4:cdeea87f25d8 | 41 | mac[3] = 0xF0; |
wim | 4:cdeea87f25d8 | 42 | mac[4] = 0x56; |
wim | 4:cdeea87f25d8 | 43 | mac[5] = 0x90; |
wim | 0:a8090b59eb05 | 44 | }; |
wim | 0:a8090b59eb05 | 45 | |
wim | 0:a8090b59eb05 | 46 | // Host PC Communication channels |
wim | 0:a8090b59eb05 | 47 | Serial pc(USBTX, USBRX); // tx, rx |
wim | 0:a8090b59eb05 | 48 | |
wim | 0:a8090b59eb05 | 49 | // Variables for Heartbeat and Status monitoring |
wim | 0:a8090b59eb05 | 50 | Ticker heartbeat; |
wim | 0:a8090b59eb05 | 51 | bool heartbeatflag=false; |
wim | 0:a8090b59eb05 | 52 | |
wim | 0:a8090b59eb05 | 53 | void clear_screen() { |
wim | 0:a8090b59eb05 | 54 | //ANSI Terminal Commands |
wim | 0:a8090b59eb05 | 55 | pc.printf("\x1B[2J"); |
wim | 0:a8090b59eb05 | 56 | pc.printf("\x1B[H"); |
wim | 0:a8090b59eb05 | 57 | } |
wim | 0:a8090b59eb05 | 58 | |
wim | 0:a8090b59eb05 | 59 | void init_interfaces() { |
wim | 0:a8090b59eb05 | 60 | // Init Host PC communication, default is 9600 |
wim | 0:a8090b59eb05 | 61 | pc.baud(D_BAUDRATE); |
wim | 0:a8090b59eb05 | 62 | } |
wim | 0:a8090b59eb05 | 63 | |
wim | 0:a8090b59eb05 | 64 | |
wim | 0:a8090b59eb05 | 65 | // Heartbeat monitor |
wim | 0:a8090b59eb05 | 66 | void pulse() { |
wim | 4:cdeea87f25d8 | 67 | heartbeatLED = !heartbeatLED; |
wim | 0:a8090b59eb05 | 68 | } |
wim | 0:a8090b59eb05 | 69 | |
wim | 0:a8090b59eb05 | 70 | void heartbeat_start() { |
wim | 4:cdeea87f25d8 | 71 | heartbeatLED = 0; |
wim | 0:a8090b59eb05 | 72 | heartbeat.attach(&pulse, 0.5); |
wim | 0:a8090b59eb05 | 73 | } |
wim | 0:a8090b59eb05 | 74 | |
wim | 0:a8090b59eb05 | 75 | void heartbeat_stop() { |
wim | 0:a8090b59eb05 | 76 | heartbeat.detach(); |
wim | 0:a8090b59eb05 | 77 | } |
wim | 0:a8090b59eb05 | 78 | |
wim | 4:cdeea87f25d8 | 79 | #if(1) |
wim | 4:cdeea87f25d8 | 80 | void flip_USB_Host_Power() { |
wim | 4:cdeea87f25d8 | 81 | static bool pin = false; |
wim | 4:cdeea87f25d8 | 82 | |
wim | 4:cdeea87f25d8 | 83 | //USB Host Power, LD15: active low (DigitalOut does not seem to go high enough to disable?) |
wim | 4:cdeea87f25d8 | 84 | if (pin) { |
wim | 4:cdeea87f25d8 | 85 | USB_Host_Power.input(); // input + pull up, power is Off |
wim | 4:cdeea87f25d8 | 86 | } |
wim | 4:cdeea87f25d8 | 87 | else { |
wim | 4:cdeea87f25d8 | 88 | USB_Host_Power.output(); // output + low, power is On |
wim | 4:cdeea87f25d8 | 89 | USB_Host_Power = 0; |
wim | 4:cdeea87f25d8 | 90 | } |
wim | 4:cdeea87f25d8 | 91 | pin = !pin; |
wim | 4:cdeea87f25d8 | 92 | } |
wim | 4:cdeea87f25d8 | 93 | |
wim | 4:cdeea87f25d8 | 94 | |
wim | 4:cdeea87f25d8 | 95 | void set_USB_Host_Power(bool pin) { |
wim | 4:cdeea87f25d8 | 96 | //USB Host Power, LD15: active low (DigitalOut does not seem to go high enough to disable?) |
wim | 4:cdeea87f25d8 | 97 | if (pin) { |
wim | 4:cdeea87f25d8 | 98 | USB_Host_Power.input(); // input + pull up, power is Off |
wim | 4:cdeea87f25d8 | 99 | } |
wim | 4:cdeea87f25d8 | 100 | else { |
wim | 4:cdeea87f25d8 | 101 | USB_Host_Power.output(); // output + low, power is On |
wim | 4:cdeea87f25d8 | 102 | USB_Host_Power = 0; |
wim | 4:cdeea87f25d8 | 103 | } |
wim | 4:cdeea87f25d8 | 104 | } |
wim | 4:cdeea87f25d8 | 105 | #endif |
wim | 0:a8090b59eb05 | 106 | |
wim | 2:43ede88fb5a3 | 107 | // GLCD |
wim | 2:43ede88fb5a3 | 108 | GLCD myGLCD; |
wim | 2:43ede88fb5a3 | 109 | |
wim | 2:43ede88fb5a3 | 110 | int random(int max) { |
wim | 2:43ede88fb5a3 | 111 | int rnd = rand() % max; |
wim | 2:43ede88fb5a3 | 112 | |
wim | 2:43ede88fb5a3 | 113 | return rnd; |
wim | 0:a8090b59eb05 | 114 | } |
wim | 0:a8090b59eb05 | 115 | |
wim | 4:cdeea87f25d8 | 116 | |
wim | 4:cdeea87f25d8 | 117 | #if(1) |
wim | 2:43ede88fb5a3 | 118 | void loop() |
wim | 2:43ede88fb5a3 | 119 | { |
wim | 2:43ede88fb5a3 | 120 | int buf[318]; |
wim | 2:43ede88fb5a3 | 121 | int x, x2; |
wim | 2:43ede88fb5a3 | 122 | int y, y2; |
wim | 2:43ede88fb5a3 | 123 | int r; |
wim | 2:43ede88fb5a3 | 124 | |
wim | 2:43ede88fb5a3 | 125 | // Clear the screen and draw the frame |
wim | 4:cdeea87f25d8 | 126 | myGLCD.cls(White); |
wim | 2:43ede88fb5a3 | 127 | |
wim | 2:43ede88fb5a3 | 128 | myGLCD.setColor(255, 0, 0); |
wim | 2:43ede88fb5a3 | 129 | myGLCD.fillRect(0, 0, 319, 13); |
wim | 2:43ede88fb5a3 | 130 | myGLCD.setColor(64, 64, 64); |
wim | 2:43ede88fb5a3 | 131 | myGLCD.fillRect(0, 226, 319, 239); |
wim | 2:43ede88fb5a3 | 132 | myGLCD.setColor(255, 255, 255); |
wim | 2:43ede88fb5a3 | 133 | myGLCD.setBackColor(255, 0, 0); |
wim | 2:43ede88fb5a3 | 134 | // myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1); |
wim | 2:43ede88fb5a3 | 135 | myGLCD.setBackColor(64, 64, 64); |
wim | 2:43ede88fb5a3 | 136 | myGLCD.setColor(255,255,0); |
wim | 2:43ede88fb5a3 | 137 | // myGLCD.print("<http://electronics.henningkarlsen.com>", CENTER, 227); |
wim | 2:43ede88fb5a3 | 138 | |
wim | 2:43ede88fb5a3 | 139 | myGLCD.setColor(0, 0, 255); |
wim | 2:43ede88fb5a3 | 140 | myGLCD.drawRect(0, 14, 319, 225); |
wim | 2:43ede88fb5a3 | 141 | |
wim | 2:43ede88fb5a3 | 142 | // Draw crosshairs |
wim | 2:43ede88fb5a3 | 143 | myGLCD.setColor(0, 0, 255); |
wim | 2:43ede88fb5a3 | 144 | myGLCD.setBackColor(0, 0, 0); |
wim | 2:43ede88fb5a3 | 145 | myGLCD.drawLine(159, 15, 159, 224); |
wim | 2:43ede88fb5a3 | 146 | myGLCD.drawLine(1, 119, 318, 119); |
wim | 2:43ede88fb5a3 | 147 | for (int i=9; i<310; i+=10) |
wim | 2:43ede88fb5a3 | 148 | myGLCD.drawLine(i, 117, i, 121); |
wim | 2:43ede88fb5a3 | 149 | for (int i=19; i<220; i+=10) |
wim | 2:43ede88fb5a3 | 150 | myGLCD.drawLine(157, i, 161, i); |
wim | 2:43ede88fb5a3 | 151 | |
wim | 2:43ede88fb5a3 | 152 | // Draw sin-, cos- and tan-lines |
wim | 2:43ede88fb5a3 | 153 | myGLCD.setColor(0,255,255); |
wim | 2:43ede88fb5a3 | 154 | // myGLCD.print("Sin", 5, 15); |
wim | 2:43ede88fb5a3 | 155 | for (int i=1; i<318; i++) |
wim | 2:43ede88fb5a3 | 156 | { |
wim | 2:43ede88fb5a3 | 157 | myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95)); |
wim | 2:43ede88fb5a3 | 158 | } |
wim | 2:43ede88fb5a3 | 159 | |
wim | 2:43ede88fb5a3 | 160 | myGLCD.setColor(255,0,0); |
wim | 2:43ede88fb5a3 | 161 | // myGLCD.print("Cos", 5, 27); |
wim | 2:43ede88fb5a3 | 162 | for (int i=1; i<318; i++) |
wim | 2:43ede88fb5a3 | 163 | { |
wim | 2:43ede88fb5a3 | 164 | myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95)); |
wim | 2:43ede88fb5a3 | 165 | } |
wim | 2:43ede88fb5a3 | 166 | |
wim | 3:2dccfa0121de | 167 | myGLCD.setColor(255,0,255); |
wim | 2:43ede88fb5a3 | 168 | // myGLCD.print("Tan", 5, 39); |
wim | 2:43ede88fb5a3 | 169 | for (int i=1; i<318; i++) |
wim | 2:43ede88fb5a3 | 170 | { |
wim | 2:43ede88fb5a3 | 171 | myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180))); |
wim | 2:43ede88fb5a3 | 172 | } |
wim | 2:43ede88fb5a3 | 173 | |
wim | 4:cdeea87f25d8 | 174 | wait(2); |
wim | 2:43ede88fb5a3 | 175 | |
wim | 2:43ede88fb5a3 | 176 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 177 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 178 | myGLCD.setColor(0, 0, 255); |
wim | 2:43ede88fb5a3 | 179 | myGLCD.setBackColor(0, 0, 0); |
wim | 2:43ede88fb5a3 | 180 | myGLCD.drawLine(159, 15, 159, 224); |
wim | 2:43ede88fb5a3 | 181 | myGLCD.drawLine(1, 119, 318, 119); |
wim | 2:43ede88fb5a3 | 182 | |
wim | 2:43ede88fb5a3 | 183 | // Draw a moving sinewave |
wim | 2:43ede88fb5a3 | 184 | x=1; |
wim | 2:43ede88fb5a3 | 185 | for (int i=1; i<(318*20); i++) |
wim | 2:43ede88fb5a3 | 186 | { |
wim | 2:43ede88fb5a3 | 187 | x++; |
wim | 2:43ede88fb5a3 | 188 | if (x==319) |
wim | 2:43ede88fb5a3 | 189 | x=1; |
wim | 2:43ede88fb5a3 | 190 | if (i>319) |
wim | 2:43ede88fb5a3 | 191 | { |
wim | 2:43ede88fb5a3 | 192 | if ((x==159)||(buf[x-1]==119)) |
wim | 2:43ede88fb5a3 | 193 | myGLCD.setColor(0,0,255); |
wim | 2:43ede88fb5a3 | 194 | else |
wim | 2:43ede88fb5a3 | 195 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 196 | myGLCD.drawPixel(x,buf[x-1]); |
wim | 2:43ede88fb5a3 | 197 | } |
wim | 2:43ede88fb5a3 | 198 | myGLCD.setColor(0,255,255); |
wim | 2:43ede88fb5a3 | 199 | y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100))); |
wim | 2:43ede88fb5a3 | 200 | myGLCD.drawPixel(x,y); |
wim | 2:43ede88fb5a3 | 201 | buf[x-1]=y; |
wim | 2:43ede88fb5a3 | 202 | } |
wim | 2:43ede88fb5a3 | 203 | |
wim | 4:cdeea87f25d8 | 204 | wait(2); |
wim | 2:43ede88fb5a3 | 205 | |
wim | 2:43ede88fb5a3 | 206 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 207 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 208 | |
wim | 2:43ede88fb5a3 | 209 | // Draw some filled rectangles |
wim | 2:43ede88fb5a3 | 210 | for (int i=1; i<6; i++) |
wim | 2:43ede88fb5a3 | 211 | { |
wim | 2:43ede88fb5a3 | 212 | switch (i) |
wim | 2:43ede88fb5a3 | 213 | { |
wim | 2:43ede88fb5a3 | 214 | case 1: |
wim | 2:43ede88fb5a3 | 215 | myGLCD.setColor(255,0,255); |
wim | 2:43ede88fb5a3 | 216 | break; |
wim | 2:43ede88fb5a3 | 217 | case 2: |
wim | 2:43ede88fb5a3 | 218 | myGLCD.setColor(255,0,0); |
wim | 2:43ede88fb5a3 | 219 | break; |
wim | 2:43ede88fb5a3 | 220 | case 3: |
wim | 2:43ede88fb5a3 | 221 | myGLCD.setColor(0,255,0); |
wim | 2:43ede88fb5a3 | 222 | break; |
wim | 2:43ede88fb5a3 | 223 | case 4: |
wim | 2:43ede88fb5a3 | 224 | myGLCD.setColor(0,0,255); |
wim | 2:43ede88fb5a3 | 225 | break; |
wim | 2:43ede88fb5a3 | 226 | case 5: |
wim | 2:43ede88fb5a3 | 227 | myGLCD.setColor(255,255,0); |
wim | 2:43ede88fb5a3 | 228 | break; |
wim | 2:43ede88fb5a3 | 229 | } |
wim | 2:43ede88fb5a3 | 230 | myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20)); |
wim | 2:43ede88fb5a3 | 231 | } |
wim | 2:43ede88fb5a3 | 232 | |
wim | 4:cdeea87f25d8 | 233 | wait(2); |
wim | 2:43ede88fb5a3 | 234 | |
wim | 2:43ede88fb5a3 | 235 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 236 | myGLCD.fillRect(1,15,318,224); |
wim | 0:a8090b59eb05 | 237 | |
wim | 2:43ede88fb5a3 | 238 | // Draw some filled, rounded rectangles |
wim | 2:43ede88fb5a3 | 239 | for (int i=1; i<6; i++) |
wim | 2:43ede88fb5a3 | 240 | { |
wim | 2:43ede88fb5a3 | 241 | switch (i) |
wim | 2:43ede88fb5a3 | 242 | { |
wim | 2:43ede88fb5a3 | 243 | case 1: |
wim | 2:43ede88fb5a3 | 244 | myGLCD.setColor(255,0,255); |
wim | 2:43ede88fb5a3 | 245 | break; |
wim | 2:43ede88fb5a3 | 246 | case 2: |
wim | 2:43ede88fb5a3 | 247 | myGLCD.setColor(255,0,0); |
wim | 2:43ede88fb5a3 | 248 | break; |
wim | 2:43ede88fb5a3 | 249 | case 3: |
wim | 2:43ede88fb5a3 | 250 | myGLCD.setColor(0,255,0); |
wim | 2:43ede88fb5a3 | 251 | break; |
wim | 2:43ede88fb5a3 | 252 | case 4: |
wim | 2:43ede88fb5a3 | 253 | myGLCD.setColor(0,0,255); |
wim | 2:43ede88fb5a3 | 254 | break; |
wim | 2:43ede88fb5a3 | 255 | case 5: |
wim | 2:43ede88fb5a3 | 256 | myGLCD.setColor(255,255,0); |
wim | 2:43ede88fb5a3 | 257 | break; |
wim | 2:43ede88fb5a3 | 258 | } |
wim | 2:43ede88fb5a3 | 259 | myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20)); |
wim | 2:43ede88fb5a3 | 260 | } |
wim | 2:43ede88fb5a3 | 261 | |
wim | 4:cdeea87f25d8 | 262 | wait(2); |
wim | 2:43ede88fb5a3 | 263 | |
wim | 2:43ede88fb5a3 | 264 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 265 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 266 | |
wim | 2:43ede88fb5a3 | 267 | // Draw some filled circles |
wim | 2:43ede88fb5a3 | 268 | for (int i=1; i<6; i++) |
wim | 2:43ede88fb5a3 | 269 | { |
wim | 2:43ede88fb5a3 | 270 | switch (i) |
wim | 2:43ede88fb5a3 | 271 | { |
wim | 2:43ede88fb5a3 | 272 | case 1: |
wim | 2:43ede88fb5a3 | 273 | myGLCD.setColor(255,0,255); |
wim | 2:43ede88fb5a3 | 274 | break; |
wim | 2:43ede88fb5a3 | 275 | case 2: |
wim | 2:43ede88fb5a3 | 276 | myGLCD.setColor(255,0,0); |
wim | 2:43ede88fb5a3 | 277 | break; |
wim | 2:43ede88fb5a3 | 278 | case 3: |
wim | 2:43ede88fb5a3 | 279 | myGLCD.setColor(0,255,0); |
wim | 2:43ede88fb5a3 | 280 | break; |
wim | 2:43ede88fb5a3 | 281 | case 4: |
wim | 2:43ede88fb5a3 | 282 | myGLCD.setColor(0,0,255); |
wim | 2:43ede88fb5a3 | 283 | break; |
wim | 2:43ede88fb5a3 | 284 | case 5: |
wim | 2:43ede88fb5a3 | 285 | myGLCD.setColor(255,255,0); |
wim | 2:43ede88fb5a3 | 286 | break; |
wim | 2:43ede88fb5a3 | 287 | } |
wim | 2:43ede88fb5a3 | 288 | myGLCD.fillCircle(100+(i*20),60+(i*20), 30); |
wim | 2:43ede88fb5a3 | 289 | } |
wim | 2:43ede88fb5a3 | 290 | |
wim | 4:cdeea87f25d8 | 291 | wait(2); |
wim | 2:43ede88fb5a3 | 292 | |
wim | 2:43ede88fb5a3 | 293 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 294 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 295 | |
wim | 2:43ede88fb5a3 | 296 | // Draw some lines in a pattern |
wim | 2:43ede88fb5a3 | 297 | myGLCD.setColor (255,0,0); |
wim | 2:43ede88fb5a3 | 298 | for (int i=15; i<224; i+=5) |
wim | 2:43ede88fb5a3 | 299 | { |
wim | 2:43ede88fb5a3 | 300 | myGLCD.drawLine(1, i, (i*1.44)-10, 224); |
wim | 2:43ede88fb5a3 | 301 | } |
wim | 2:43ede88fb5a3 | 302 | myGLCD.setColor (255,0,0); |
wim | 2:43ede88fb5a3 | 303 | for (int i=224; i>15; i-=5) |
wim | 2:43ede88fb5a3 | 304 | { |
wim | 2:43ede88fb5a3 | 305 | myGLCD.drawLine(318, i, (i*1.44)-11, 15); |
wim | 2:43ede88fb5a3 | 306 | } |
wim | 2:43ede88fb5a3 | 307 | myGLCD.setColor (0,255,255); |
wim | 2:43ede88fb5a3 | 308 | for (int i=224; i>15; i-=5) |
wim | 2:43ede88fb5a3 | 309 | { |
wim | 2:43ede88fb5a3 | 310 | myGLCD.drawLine(1, i, 331-(i*1.44), 15); |
wim | 2:43ede88fb5a3 | 311 | } |
wim | 2:43ede88fb5a3 | 312 | myGLCD.setColor (0,255,255); |
wim | 2:43ede88fb5a3 | 313 | for (int i=15; i<224; i+=5) |
wim | 2:43ede88fb5a3 | 314 | { |
wim | 2:43ede88fb5a3 | 315 | myGLCD.drawLine(318, i, 330-(i*1.44), 224); |
wim | 2:43ede88fb5a3 | 316 | } |
wim | 2:43ede88fb5a3 | 317 | |
wim | 4:cdeea87f25d8 | 318 | wait(2); |
wim | 2:43ede88fb5a3 | 319 | |
wim | 2:43ede88fb5a3 | 320 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 321 | myGLCD.fillRect(1,15,318,225); |
wim | 2:43ede88fb5a3 | 322 | |
wim | 2:43ede88fb5a3 | 323 | // Draw some random circles |
wim | 2:43ede88fb5a3 | 324 | for (int i=0; i<100; i++) |
wim | 2:43ede88fb5a3 | 325 | { |
wim | 2:43ede88fb5a3 | 326 | myGLCD.setColor(random(255), random(255), random(255)); |
wim | 2:43ede88fb5a3 | 327 | x=32+random(256); |
wim | 2:43ede88fb5a3 | 328 | y=45+random(146); |
wim | 2:43ede88fb5a3 | 329 | r=random(30); |
wim | 2:43ede88fb5a3 | 330 | myGLCD.drawCircle(x, y, r); |
wim | 2:43ede88fb5a3 | 331 | } |
wim | 2:43ede88fb5a3 | 332 | |
wim | 4:cdeea87f25d8 | 333 | wait(2); |
wim | 2:43ede88fb5a3 | 334 | |
wim | 2:43ede88fb5a3 | 335 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 336 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 337 | |
wim | 2:43ede88fb5a3 | 338 | // Draw some random rectangles |
wim | 2:43ede88fb5a3 | 339 | for (int i=0; i<100; i++) |
wim | 2:43ede88fb5a3 | 340 | { |
wim | 2:43ede88fb5a3 | 341 | myGLCD.setColor(random(255), random(255), random(255)); |
wim | 2:43ede88fb5a3 | 342 | x=2+random(316); |
wim | 2:43ede88fb5a3 | 343 | y=16+random(207); |
wim | 2:43ede88fb5a3 | 344 | x2=2+random(316); |
wim | 2:43ede88fb5a3 | 345 | y2=16+random(207); |
wim | 2:43ede88fb5a3 | 346 | myGLCD.drawRect(x, y, x2, y2); |
wim | 2:43ede88fb5a3 | 347 | } |
wim | 2:43ede88fb5a3 | 348 | |
wim | 4:cdeea87f25d8 | 349 | wait(2); |
wim | 2:43ede88fb5a3 | 350 | |
wim | 2:43ede88fb5a3 | 351 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 352 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 353 | |
wim | 2:43ede88fb5a3 | 354 | // Draw some random rounded rectangles |
wim | 2:43ede88fb5a3 | 355 | for (int i=0; i<100; i++) |
wim | 2:43ede88fb5a3 | 356 | { |
wim | 2:43ede88fb5a3 | 357 | myGLCD.setColor(random(255), random(255), random(255)); |
wim | 2:43ede88fb5a3 | 358 | x=2+random(316); |
wim | 2:43ede88fb5a3 | 359 | y=16+random(207); |
wim | 2:43ede88fb5a3 | 360 | x2=2+random(316); |
wim | 2:43ede88fb5a3 | 361 | y2=16+random(207); |
wim | 2:43ede88fb5a3 | 362 | myGLCD.drawRoundRect(x, y, x2, y2); |
wim | 2:43ede88fb5a3 | 363 | } |
wim | 2:43ede88fb5a3 | 364 | |
wim | 4:cdeea87f25d8 | 365 | wait(2); |
wim | 2:43ede88fb5a3 | 366 | |
wim | 2:43ede88fb5a3 | 367 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 368 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 369 | |
wim | 2:43ede88fb5a3 | 370 | for (int i=0; i<100; i++) |
wim | 2:43ede88fb5a3 | 371 | { |
wim | 2:43ede88fb5a3 | 372 | myGLCD.setColor(random(255), random(255), random(255)); |
wim | 2:43ede88fb5a3 | 373 | x=2+random(316); |
wim | 2:43ede88fb5a3 | 374 | y=16+random(209); |
wim | 2:43ede88fb5a3 | 375 | x2=2+random(316); |
wim | 2:43ede88fb5a3 | 376 | y2=16+random(209); |
wim | 2:43ede88fb5a3 | 377 | myGLCD.drawLine(x, y, x2, y2); |
wim | 2:43ede88fb5a3 | 378 | } |
wim | 2:43ede88fb5a3 | 379 | |
wim | 4:cdeea87f25d8 | 380 | wait(2); |
wim | 2:43ede88fb5a3 | 381 | |
wim | 2:43ede88fb5a3 | 382 | myGLCD.setColor(0,0,0); |
wim | 2:43ede88fb5a3 | 383 | myGLCD.fillRect(1,15,318,224); |
wim | 2:43ede88fb5a3 | 384 | |
wim | 2:43ede88fb5a3 | 385 | for (int i=0; i<10000; i++) |
wim | 2:43ede88fb5a3 | 386 | { |
wim | 2:43ede88fb5a3 | 387 | myGLCD.setColor(random(255), random(255), random(255)); |
wim | 2:43ede88fb5a3 | 388 | myGLCD.drawPixel(2+random(316), 16+random(209)); |
wim | 2:43ede88fb5a3 | 389 | } |
wim | 2:43ede88fb5a3 | 390 | |
wim | 4:cdeea87f25d8 | 391 | wait(2); |
wim | 2:43ede88fb5a3 | 392 | |
wim | 4:cdeea87f25d8 | 393 | myGLCD.cls(Blue); |
wim | 2:43ede88fb5a3 | 394 | |
wim | 2:43ede88fb5a3 | 395 | myGLCD.setColor(255, 0, 0); |
wim | 2:43ede88fb5a3 | 396 | myGLCD.fillRoundRect(80, 70, 239, 169); |
wim | 2:43ede88fb5a3 | 397 | |
wim | 2:43ede88fb5a3 | 398 | myGLCD.setColor(255, 255, 255); |
wim | 2:43ede88fb5a3 | 399 | myGLCD.setBackColor(255, 0, 0); |
wim | 2:43ede88fb5a3 | 400 | // myGLCD.print("That's it!", CENTER, 93); |
wim | 2:43ede88fb5a3 | 401 | // myGLCD.print("Restarting in a", CENTER, 119); |
wim | 2:43ede88fb5a3 | 402 | // myGLCD.print("few seconds...", CENTER, 132); |
wim | 2:43ede88fb5a3 | 403 | |
wim | 2:43ede88fb5a3 | 404 | myGLCD.setColor(0, 255, 0); |
wim | 2:43ede88fb5a3 | 405 | myGLCD.setBackColor(0, 0, 255); |
wim | 2:43ede88fb5a3 | 406 | // myGLCD.print("Runtime: (msecs)", CENTER, 210); |
wim | 2:43ede88fb5a3 | 407 | // myGLCD.printNumI(millis(), CENTER, 225); |
wim | 2:43ede88fb5a3 | 408 | |
wim | 4:cdeea87f25d8 | 409 | wait(2); |
wim | 0:a8090b59eb05 | 410 | } |
wim | 4:cdeea87f25d8 | 411 | #endif |
wim | 0:a8090b59eb05 | 412 | |
wim | 0:a8090b59eb05 | 413 | |
wim | 0:a8090b59eb05 | 414 | int main() { |
wim | 0:a8090b59eb05 | 415 | init_interfaces(); |
wim | 0:a8090b59eb05 | 416 | |
wim | 0:a8090b59eb05 | 417 | clear_screen(); |
wim | 4:cdeea87f25d8 | 418 | |
wim | 4:cdeea87f25d8 | 419 | heartbeat_start(); |
wim | 0:a8090b59eb05 | 420 | |
wim | 0:a8090b59eb05 | 421 | pc.printf("Hello World!\n\r"); |
wim | 4:cdeea87f25d8 | 422 | pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
wim | 4:cdeea87f25d8 | 423 | |
wim | 4:cdeea87f25d8 | 424 | #if(1) |
wim | 4:cdeea87f25d8 | 425 | myGLCD.cls(White); |
wim | 4:cdeea87f25d8 | 426 | myGLCD.setColor(Red); |
wim | 4:cdeea87f25d8 | 427 | myGLCD.setBackColor(White); |
wim | 4:cdeea87f25d8 | 428 | myGLCD.printf ("Hi Willem\n"); |
wim | 4:cdeea87f25d8 | 429 | myGLCD.printf("CPU SystemCoreClock is %d Hz\n", SystemCoreClock); |
wim | 4:cdeea87f25d8 | 430 | |
wim | 4:cdeea87f25d8 | 431 | wait(0.5); |
wim | 4:cdeea87f25d8 | 432 | |
wim | 4:cdeea87f25d8 | 433 | myGLCD.drawRect (100, 100, 150, 150); |
wim | 0:a8090b59eb05 | 434 | |
wim | 2:43ede88fb5a3 | 435 | myGLCD.setColor (Green); |
wim | 4:cdeea87f25d8 | 436 | myGLCD.drawHLine (120, 160, 80); |
wim | 4:cdeea87f25d8 | 437 | myGLCD.drawVLine (160, 120, 80); |
wim | 2:43ede88fb5a3 | 438 | |
wim | 2:43ede88fb5a3 | 439 | myGLCD.setColor (Blue); |
wim | 4:cdeea87f25d8 | 440 | myGLCD.fillRoundRect (100, 100, 130, 130); |
wim | 2:43ede88fb5a3 | 441 | myGLCD.setColor (Cyan); |
wim | 4:cdeea87f25d8 | 442 | myGLCD.drawCircle (160, 160, 40); |
wim | 4:cdeea87f25d8 | 443 | |
wim | 2:43ede88fb5a3 | 444 | pc.printf("LCD Controller ID = 0x%04X\n\r", myGLCD.getDriverCode()); |
wim | 4:cdeea87f25d8 | 445 | pc.printf("PixelsY= %d, PixelsX= %d\n\r", myGLCD.getDisplayYSize(), myGLCD.getDisplayXSize()); |
wim | 4:cdeea87f25d8 | 446 | pc.printf("Lines= %d, Cols= %d\n\r", myGLCD.getRows(), myGLCD.getCols()); |
wim | 0:a8090b59eb05 | 447 | |
wim | 4:cdeea87f25d8 | 448 | #if(1) |
wim | 4:cdeea87f25d8 | 449 | wait(2); |
wim | 3:2dccfa0121de | 450 | loop(); |
wim | 4:cdeea87f25d8 | 451 | #endif |
wim | 2:43ede88fb5a3 | 452 | |
wim | 4:cdeea87f25d8 | 453 | myGLCD.setColor(Black); |
wim | 4:cdeea87f25d8 | 454 | myGLCD.locate(9,0); |
wim | 4:cdeea87f25d8 | 455 | myGLCD.printf("Bye Willem"); |
wim | 4:cdeea87f25d8 | 456 | #endif |
wim | 4:cdeea87f25d8 | 457 | pc.printf("Bye World!\n\r"); |
wim | 3:2dccfa0121de | 458 | |
wim | 4:cdeea87f25d8 | 459 | USB_Device_PU = 1; //USB Device Pull Up, LD14: active low |
wim | 4:cdeea87f25d8 | 460 | USB_Device_Up = 1; //USB Device Up, LD13: active low |
wim | 4:cdeea87f25d8 | 461 | |
wim | 4:cdeea87f25d8 | 462 | while (1) { |
wim | 4:cdeea87f25d8 | 463 | //USB_Host_Power = !USB_Host_Power; //Does not switch off! |
wim | 4:cdeea87f25d8 | 464 | flip_USB_Host_Power(); |
wim | 4:cdeea87f25d8 | 465 | USB_Device_PU = !USB_Device_PU; |
wim | 4:cdeea87f25d8 | 466 | USB_Device_Up = !USB_Device_Up; |
wim | 3:2dccfa0121de | 467 | |
wim | 4:cdeea87f25d8 | 468 | pc.putc('*'); |
wim | 4:cdeea87f25d8 | 469 | wait(1.5); |
wim | 4:cdeea87f25d8 | 470 | } |
wim | 0:a8090b59eb05 | 471 | } |