It is the uLCD program demo that has to be worked on.

Dependencies:   4DGL-uLCD-SE mbed

Fork of uLCD144G2_demo by jim hamblen

Committer:
azndevil
Date:
Wed Sep 14 20:56:12 2016 +0000
Revision:
10:13fd546dfeaa
Parent:
8:31e63caf37e2
Hi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 8:31e63caf37e2 1 // uLCD-144-G2 demo program for uLCD-4GL LCD driver library
4180_1 0:cfcf73272647 2 //
4180_1 0:cfcf73272647 3 #include "mbed.h"
4180_1 2:75727e89a717 4 #include "uLCD_4DGL.h"
4180_1 0:cfcf73272647 5
azndevil 10:13fd546dfeaa 6 uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin;
4180_1 0:cfcf73272647 7
4180_1 2:75727e89a717 8 int main()
4180_1 2:75727e89a717 9 {
4180_1 3:454d1f4c8fd7 10 // basic printf demo = 16 by 18 characters on screen
azndevil 10:13fd546dfeaa 11 uLCD.baudrate(1152000);
4180_1 3:454d1f4c8fd7 12 uLCD.printf("\nHello uLCD World\n"); //Default Green on black text
4180_1 3:454d1f4c8fd7 13 uLCD.printf("\n Starting Demo...");
4180_1 3:454d1f4c8fd7 14 uLCD.text_width(4); //4X size text
4180_1 3:454d1f4c8fd7 15 uLCD.text_height(4);
4180_1 3:454d1f4c8fd7 16 uLCD.color(RED);
4180_1 3:454d1f4c8fd7 17 for (int i=10; i>=0; --i) {
4180_1 3:454d1f4c8fd7 18 uLCD.locate(1,2);
4180_1 3:454d1f4c8fd7 19 uLCD.printf("%2D",i);
4180_1 3:454d1f4c8fd7 20 wait(.5);
4180_1 3:454d1f4c8fd7 21 }
4180_1 3:454d1f4c8fd7 22 uLCD.cls();
4180_1 8:31e63caf37e2 23 uLCD.printf("Change baudrate......");
4180_1 8:31e63caf37e2 24 uLCD.baudrate(3000000); //jack up baud rate to max for fast display
4180_1 6:f752accd632c 25 //if demo hangs here - try lower baud rates
4180_1 8:31e63caf37e2 26 //
4180_1 7:7bd7397ab89f 27 // printf text only full screen mode demo
4180_1 7:7bd7397ab89f 28 uLCD.background_color(BLUE);
4180_1 7:7bd7397ab89f 29 uLCD.cls();
4180_1 7:7bd7397ab89f 30 uLCD.locate(0,0);
4180_1 7:7bd7397ab89f 31 uLCD.color(WHITE);
4180_1 7:7bd7397ab89f 32 uLCD.textbackground_color(BLUE);
4180_1 7:7bd7397ab89f 33 uLCD.set_font(FONT_7X8);
4180_1 7:7bd7397ab89f 34 uLCD.text_mode(OPAQUE);
4180_1 7:7bd7397ab89f 35 int i=0;
4180_1 7:7bd7397ab89f 36 while(i<64) {
4180_1 7:7bd7397ab89f 37 if(i%16==0) uLCD.cls();
4180_1 7:7bd7397ab89f 38 uLCD.printf("TxtLine %2D Page %D\n",i%16,i/16 );
4180_1 7:7bd7397ab89f 39 i++; //16 lines with 18 charaters per line
4180_1 7:7bd7397ab89f 40 }
4180_1 7:7bd7397ab89f 41 wait(0.5);
4180_1 6:f752accd632c 42 //demo graphics commands
4180_1 7:7bd7397ab89f 43 uLCD.background_color(BLACK);
4180_1 7:7bd7397ab89f 44 uLCD.cls();
4180_1 2:75727e89a717 45 uLCD.background_color(DGREY);
4180_1 8:31e63caf37e2 46 uLCD.filled_circle(60, 50, 30, 0xFF00FF);
4180_1 2:75727e89a717 47 uLCD.triangle(120, 100, 40, 40, 10, 100, 0x0000FF);
4180_1 2:75727e89a717 48 uLCD.line(0, 0, 80, 60, 0xFF0000);
4180_1 8:31e63caf37e2 49 uLCD.filled_rectangle(50, 50, 100, 90, 0x00FF00);
4180_1 2:75727e89a717 50 uLCD.pixel(60, 60, BLACK);
4180_1 2:75727e89a717 51 uLCD.read_pixel(120, 70);
4180_1 2:75727e89a717 52 uLCD.circle(120, 60, 10, BLACK);
4180_1 3:454d1f4c8fd7 53 uLCD.set_font(FONT_7X8);
4180_1 2:75727e89a717 54 uLCD.text_mode(TRANSPARENT);
4180_1 6:f752accd632c 55 uLCD.text_bold(ON);
4180_1 2:75727e89a717 56 uLCD.text_char('B', 9, 8, BLACK);
4180_1 2:75727e89a717 57 uLCD.text_char('I',10, 8, BLACK);
4180_1 2:75727e89a717 58 uLCD.text_char('G',11, 8, BLACK);
4180_1 6:f752accd632c 59 uLCD.text_italic(ON);
4180_1 3:454d1f4c8fd7 60 uLCD.text_string("This is a test of string", 1, 4, FONT_7X8, WHITE);
4180_1 3:454d1f4c8fd7 61 wait(2);
4180_1 7:7bd7397ab89f 62
4180_1 6:f752accd632c 63 //Bouncing Ball Demo
4180_1 7:7bd7397ab89f 64 float fx=50.0,fy=21.0,vx=1.0,vy=0.4;
4180_1 7:7bd7397ab89f 65 int x=50,y=21,radius=4;
4180_1 4:25a266a74a4c 66 uLCD.background_color(BLACK);
4180_1 4:25a266a74a4c 67 uLCD.cls();
4180_1 6:f752accd632c 68 //draw walls
4180_1 6:f752accd632c 69 uLCD.line(0, 0, 127, 0, WHITE);
4180_1 6:f752accd632c 70 uLCD.line(127, 0, 127, 127, WHITE);
4180_1 6:f752accd632c 71 uLCD.line(127, 127, 0, 127, WHITE);
4180_1 6:f752accd632c 72 uLCD.line(0, 127, 0, 0, WHITE);
4180_1 7:7bd7397ab89f 73 for (int i=0; i<1500; i++) {
4180_1 6:f752accd632c 74 //draw ball
4180_1 8:31e63caf37e2 75 uLCD.filled_circle(x, y, radius, RED);
4180_1 7:7bd7397ab89f 76 //bounce off edge walls and slow down a bit?
4180_1 7:7bd7397ab89f 77 if ((x<=radius+1) || (x>=126-radius)) vx = -.90*vx;
4180_1 7:7bd7397ab89f 78 if ((y<=radius+1) || (y>=126-radius)) vy = -.90*vy;
4180_1 6:f752accd632c 79 //erase old ball location
4180_1 8:31e63caf37e2 80 uLCD.filled_circle(x, y, radius, BLACK);
4180_1 6:f752accd632c 81 //move ball
4180_1 7:7bd7397ab89f 82 fx=fx+vx;
4180_1 7:7bd7397ab89f 83 fy=fy+vy;
4180_1 7:7bd7397ab89f 84 x=(int)fx;
4180_1 7:7bd7397ab89f 85 y=(int)fy;
4180_1 4:25a266a74a4c 86 }
4180_1 7:7bd7397ab89f 87 wait(0.5);
4180_1 3:454d1f4c8fd7 88 //draw an image pixel by pixel
4180_1 6:f752accd632c 89 int pixelcolors[50][50];
4180_1 3:454d1f4c8fd7 90 uLCD.background_color(BLACK);
4180_1 3:454d1f4c8fd7 91 uLCD.cls();
4180_1 6:f752accd632c 92 //compute Mandelbrot set image for display
4180_1 8:31e63caf37e2 93 //image size in pixels
4180_1 3:454d1f4c8fd7 94 const unsigned ImageHeight=128;
4180_1 3:454d1f4c8fd7 95 const unsigned ImageWidth=128;
4180_1 8:31e63caf37e2 96 //"c" region to display
4180_1 3:454d1f4c8fd7 97 double MinRe = -0.75104;
4180_1 3:454d1f4c8fd7 98 double MaxRe = -0.7408;
4180_1 3:454d1f4c8fd7 99 double MinIm = 0.10511;
4180_1 3:454d1f4c8fd7 100 double MaxIm = MinIm+(MaxRe-MinRe)*ImageHeight/ImageWidth;
4180_1 3:454d1f4c8fd7 101 double Re_factor = (MaxRe-MinRe)/(ImageWidth-1);
4180_1 3:454d1f4c8fd7 102 double Im_factor = (MaxIm-MinIm)/(ImageHeight-1);
4180_1 7:7bd7397ab89f 103 unsigned MaxIterations = 2048;
4180_1 3:454d1f4c8fd7 104 for(unsigned y=0; y<ImageHeight; ++y) {
4180_1 3:454d1f4c8fd7 105 double c_im = MaxIm - y*Im_factor;
4180_1 3:454d1f4c8fd7 106 for(unsigned x=0; x<ImageWidth; ++x) {
4180_1 3:454d1f4c8fd7 107 double c_re = MinRe + x*Re_factor;
4180_1 3:454d1f4c8fd7 108 double Z_re = c_re, Z_im = c_im;
4180_1 3:454d1f4c8fd7 109 int niterations=0;
4180_1 3:454d1f4c8fd7 110 for(unsigned n=0; n<MaxIterations; ++n) {
4180_1 3:454d1f4c8fd7 111 double Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im;
4180_1 3:454d1f4c8fd7 112 if(Z_re2 + Z_im2 > 4) {
4180_1 3:454d1f4c8fd7 113 niterations = n;
4180_1 3:454d1f4c8fd7 114 break;
4180_1 3:454d1f4c8fd7 115 }
4180_1 3:454d1f4c8fd7 116 Z_im = 2*Z_re*Z_im + c_im;
4180_1 3:454d1f4c8fd7 117 Z_re = Z_re2 - Z_im2 + c_re;
4180_1 3:454d1f4c8fd7 118 }
4180_1 6:f752accd632c 119 if (niterations!=(MaxIterations-1))
4180_1 6:f752accd632c 120 uLCD.pixel(x,y,((niterations & 0xF00)<<12)+((niterations & 0xF0)<<8)+((niterations & 0x0F)<<4) );
4180_1 3:454d1f4c8fd7 121 }
4180_1 3:454d1f4c8fd7 122 }
4180_1 5:a1ef40ff0f78 123 wait(5);
4180_1 6:f752accd632c 124 // PLASMA wave BLIT animation
4180_1 6:f752accd632c 125 //draw an image using BLIT (Block Image Transfer) fastest way to transfer pixel data
4180_1 5:a1ef40ff0f78 126 uLCD.cls();
4180_1 6:f752accd632c 127 int num_cols=50;
4180_1 6:f752accd632c 128 int num_rows=50;
4180_1 7:7bd7397ab89f 129 int frame=0;
4180_1 5:a1ef40ff0f78 130 double a,b,c=0.0;
4180_1 8:31e63caf37e2 131 while(frame<75) {
4180_1 5:a1ef40ff0f78 132 for (int k=0; k<num_cols; k++) {
4180_1 5:a1ef40ff0f78 133 b= (1+sin(3.14159*k*0.75/(num_cols-1.0)+c))*0.5;
4180_1 5:a1ef40ff0f78 134 for (int i=0; i<num_rows; i++) {
4180_1 5:a1ef40ff0f78 135 a= (1+sin(3.14159*i*0.75/(num_rows-1.0)+c))*0.5;
4180_1 5:a1ef40ff0f78 136 // a and b will be a sine wave output between 0 and 1
4180_1 5:a1ef40ff0f78 137 // sine wave was scaled for nice effect across array
4180_1 5:a1ef40ff0f78 138 // uses a and b to compute pixel colors based on rol and col location in array
4180_1 5:a1ef40ff0f78 139 // also keeps colors at the same brightness level
4180_1 5:a1ef40ff0f78 140 if ((a+b) <.667)
4180_1 6:f752accd632c 141 pixelcolors[i][k] = (255-(int(254.0*((a+b)/0.667)))<<16) | (int(254.0*((a+b)/0.667))<<8) | 0;
4180_1 5:a1ef40ff0f78 142 else if ((a+b)<1.333)
4180_1 6:f752accd632c 143 pixelcolors[i][k] = (0 <<16) | (255-(int (254.0*((a+b-0.667)/0.667)))<<8) | int(254.0*((a+b-0.667)/0.667));
4180_1 5:a1ef40ff0f78 144 else
4180_1 6:f752accd632c 145 pixelcolors[i][k] = (int(255*((a+b-1.333)/0.667))<<16) | (0<<8) | (255-(int (254.0*((a+b-1.333)/0.667))));
4180_1 5:a1ef40ff0f78 146 }
4180_1 5:a1ef40ff0f78 147 }
4180_1 6:f752accd632c 148 uLCD.BLIT(39, 39, 50, 50, &pixelcolors[0][0]);
4180_1 5:a1ef40ff0f78 149 c = c + 0.0314159*3.0;
4180_1 5:a1ef40ff0f78 150 if (c > 6.2831) c = 0.0;
4180_1 7:7bd7397ab89f 151 frame++;
4180_1 7:7bd7397ab89f 152 }
4180_1 8:31e63caf37e2 153 //Load Image Demo
4180_1 7:7bd7397ab89f 154 uLCD.cls();
4180_1 7:7bd7397ab89f 155 //SD card needed with image and video files for last two demos
4180_1 7:7bd7397ab89f 156 uLCD.cls();
4180_1 7:7bd7397ab89f 157 uLCD.media_init();
4180_1 8:31e63caf37e2 158 uLCD.printf("\n\nAn SD card is needed for image and video data");
4180_1 7:7bd7397ab89f 159 uLCD.set_sector_address(0x001D, 0x4C01);
4180_1 7:7bd7397ab89f 160 uLCD.display_image(0,0);
4180_1 7:7bd7397ab89f 161 wait(10);
4180_1 8:31e63caf37e2 162 //Play video demo
4180_1 7:7bd7397ab89f 163 while(1) {
4180_1 7:7bd7397ab89f 164 uLCD.cls();
4180_1 7:7bd7397ab89f 165 uLCD.media_init();
4180_1 7:7bd7397ab89f 166 uLCD.set_sector_address(0x001D, 0x4C42);
4180_1 7:7bd7397ab89f 167 uLCD.display_video(0,0);
4180_1 5:a1ef40ff0f78 168 }
azndevil 10:13fd546dfeaa 169 }