![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ECE 4180 Lab 2 Part 3 Extra Credit
Dependencies: 4DGL-uLCD-SE LSM9DS1_Library_cal mbed
Fork of uLCD144G2_demo by
main.cpp@3:454d1f4c8fd7, 2013-11-17 (annotated)
- Committer:
- 4180_1
- Date:
- Sun Nov 17 04:37:03 2013 +0000
- Revision:
- 3:454d1f4c8fd7
- Parent:
- 2:75727e89a717
- Child:
- 4:25a266a74a4c
ver 1.01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:cfcf73272647 | 1 | // |
4180_1 | 0:cfcf73272647 | 2 | // TFT_4DGL is a class to drive 4D Systems TFT touch screens |
4180_1 | 0:cfcf73272647 | 3 | // |
4180_1 | 0:cfcf73272647 | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
4180_1 | 0:cfcf73272647 | 5 | // |
4180_1 | 0:cfcf73272647 | 6 | // TFT_4DGL is free software: you can redistribute it and/or modify |
4180_1 | 0:cfcf73272647 | 7 | // it under the terms of the GNU General Public License as published by |
4180_1 | 0:cfcf73272647 | 8 | // the Free Software Foundation, either version 3 of the License, or |
4180_1 | 0:cfcf73272647 | 9 | // (at your option) any later version. |
4180_1 | 0:cfcf73272647 | 10 | // |
4180_1 | 0:cfcf73272647 | 11 | // TFT_4DGL is distributed in the hope that it will be useful, |
4180_1 | 0:cfcf73272647 | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
4180_1 | 0:cfcf73272647 | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4180_1 | 0:cfcf73272647 | 14 | // GNU General Public License for more details. |
4180_1 | 0:cfcf73272647 | 15 | // |
4180_1 | 0:cfcf73272647 | 16 | // You should have received a copy of the GNU General Public License |
4180_1 | 0:cfcf73272647 | 17 | // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. |
4180_1 | 0:cfcf73272647 | 18 | |
4180_1 | 0:cfcf73272647 | 19 | #include "mbed.h" |
4180_1 | 2:75727e89a717 | 20 | #include "uLCD_4DGL.h" |
4180_1 | 0:cfcf73272647 | 21 | |
4180_1 | 2:75727e89a717 | 22 | #define SIZE_X 128 |
4180_1 | 2:75727e89a717 | 23 | #define SIZE_Y 128 |
4180_1 | 1:38ef731c7bdf | 24 | // |
4180_1 | 1:38ef731c7bdf | 25 | |
4180_1 | 2:75727e89a717 | 26 | uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; |
4180_1 | 0:cfcf73272647 | 27 | |
4180_1 | 2:75727e89a717 | 28 | int main() |
4180_1 | 2:75727e89a717 | 29 | { |
4180_1 | 3:454d1f4c8fd7 | 30 | // basic printf demo = 16 by 18 characters on screen |
4180_1 | 3:454d1f4c8fd7 | 31 | uLCD.printf("\nHello uLCD World\n"); //Default Green on black text |
4180_1 | 3:454d1f4c8fd7 | 32 | uLCD.printf("\n Starting Demo..."); |
4180_1 | 3:454d1f4c8fd7 | 33 | uLCD.text_width(4); //4X size text |
4180_1 | 3:454d1f4c8fd7 | 34 | uLCD.text_height(4); |
4180_1 | 3:454d1f4c8fd7 | 35 | uLCD.color(RED); |
4180_1 | 3:454d1f4c8fd7 | 36 | for (int i=10; i>=0; --i) { |
4180_1 | 3:454d1f4c8fd7 | 37 | uLCD.locate(1,2); |
4180_1 | 3:454d1f4c8fd7 | 38 | uLCD.printf("%2D",i); |
4180_1 | 3:454d1f4c8fd7 | 39 | wait(.5); |
4180_1 | 3:454d1f4c8fd7 | 40 | } |
4180_1 | 3:454d1f4c8fd7 | 41 | uLCD.cls(); |
4180_1 | 3:454d1f4c8fd7 | 42 | uLCD.baudrate(256000); //jack up baud rate to max |
4180_1 | 3:454d1f4c8fd7 | 43 | //demo graphics |
4180_1 | 2:75727e89a717 | 44 | uLCD.background_color(DGREY); |
4180_1 | 2:75727e89a717 | 45 | uLCD.circle(60, 50, 30, 0xFF00FF); |
4180_1 | 2:75727e89a717 | 46 | uLCD.triangle(120, 100, 40, 40, 10, 100, 0x0000FF); |
4180_1 | 2:75727e89a717 | 47 | uLCD.line(0, 0, 80, 60, 0xFF0000); |
4180_1 | 2:75727e89a717 | 48 | uLCD.rectangle(50, 50, 100, 90, 0x00FF00); |
4180_1 | 2:75727e89a717 | 49 | uLCD.pixel(60, 60, BLACK); |
4180_1 | 2:75727e89a717 | 50 | uLCD.read_pixel(120, 70); |
4180_1 | 2:75727e89a717 | 51 | uLCD.circle(120, 60, 10, BLACK); |
4180_1 | 3:454d1f4c8fd7 | 52 | uLCD.set_font(FONT_7X8); |
4180_1 | 2:75727e89a717 | 53 | uLCD.text_mode(TRANSPARENT); |
4180_1 | 2:75727e89a717 | 54 | uLCD.text_char('B', 9, 8, BLACK); |
4180_1 | 2:75727e89a717 | 55 | uLCD.text_char('I',10, 8, BLACK); |
4180_1 | 2:75727e89a717 | 56 | uLCD.text_char('G',11, 8, BLACK); |
4180_1 | 3:454d1f4c8fd7 | 57 | uLCD.text_string("This is a test of string", 1, 4, FONT_7X8, WHITE); |
4180_1 | 3:454d1f4c8fd7 | 58 | wait(2); |
4180_1 | 3:454d1f4c8fd7 | 59 | // printf text only mode demo |
4180_1 | 3:454d1f4c8fd7 | 60 | uLCD.background_color(BLUE); |
4180_1 | 3:454d1f4c8fd7 | 61 | uLCD.cls(); |
4180_1 | 3:454d1f4c8fd7 | 62 | uLCD.locate(0,0); |
4180_1 | 3:454d1f4c8fd7 | 63 | uLCD.color(WHITE); |
4180_1 | 3:454d1f4c8fd7 | 64 | uLCD.textbackground_color(BLUE); |
4180_1 | 3:454d1f4c8fd7 | 65 | uLCD.set_font(FONT_7X8); |
4180_1 | 3:454d1f4c8fd7 | 66 | uLCD.text_mode(OPAQUE); |
4180_1 | 3:454d1f4c8fd7 | 67 | int i=0; |
4180_1 | 3:454d1f4c8fd7 | 68 | while(i<64) { |
4180_1 | 3:454d1f4c8fd7 | 69 | if(i%16==0) uLCD.cls(); |
4180_1 | 3:454d1f4c8fd7 | 70 | uLCD.printf("TxtLine %2D Page %D\n",i%16,i/16 ); |
4180_1 | 3:454d1f4c8fd7 | 71 | i++; //16 lines with 18 charaters per line |
4180_1 | 3:454d1f4c8fd7 | 72 | } |
4180_1 | 3:454d1f4c8fd7 | 73 | //draw an image pixel by pixel |
4180_1 | 3:454d1f4c8fd7 | 74 | uLCD.background_color(BLACK); |
4180_1 | 3:454d1f4c8fd7 | 75 | uLCD.cls(); |
4180_1 | 3:454d1f4c8fd7 | 76 | //compute Mandelbrot image for display |
4180_1 | 3:454d1f4c8fd7 | 77 | //image size in pixels and setup |
4180_1 | 3:454d1f4c8fd7 | 78 | const unsigned ImageHeight=128; |
4180_1 | 3:454d1f4c8fd7 | 79 | const unsigned ImageWidth=128; |
4180_1 | 3:454d1f4c8fd7 | 80 | double MinRe = -0.75104; |
4180_1 | 3:454d1f4c8fd7 | 81 | double MaxRe = -0.7408; |
4180_1 | 3:454d1f4c8fd7 | 82 | double MinIm = 0.10511; |
4180_1 | 3:454d1f4c8fd7 | 83 | double MaxIm = MinIm+(MaxRe-MinRe)*ImageHeight/ImageWidth; |
4180_1 | 3:454d1f4c8fd7 | 84 | double Re_factor = (MaxRe-MinRe)/(ImageWidth-1); |
4180_1 | 3:454d1f4c8fd7 | 85 | double Im_factor = (MaxIm-MinIm)/(ImageHeight-1); |
4180_1 | 3:454d1f4c8fd7 | 86 | unsigned MaxIterations = 4096; |
4180_1 | 3:454d1f4c8fd7 | 87 | for(unsigned y=0; y<ImageHeight; ++y) { |
4180_1 | 3:454d1f4c8fd7 | 88 | double c_im = MaxIm - y*Im_factor; |
4180_1 | 3:454d1f4c8fd7 | 89 | for(unsigned x=0; x<ImageWidth; ++x) { |
4180_1 | 3:454d1f4c8fd7 | 90 | double c_re = MinRe + x*Re_factor; |
4180_1 | 3:454d1f4c8fd7 | 91 | double Z_re = c_re, Z_im = c_im; |
4180_1 | 3:454d1f4c8fd7 | 92 | bool isInside = true; |
4180_1 | 3:454d1f4c8fd7 | 93 | int niterations=0; |
4180_1 | 3:454d1f4c8fd7 | 94 | for(unsigned n=0; n<MaxIterations; ++n) { |
4180_1 | 3:454d1f4c8fd7 | 95 | double Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im; |
4180_1 | 3:454d1f4c8fd7 | 96 | if(Z_re2 + Z_im2 > 4) { |
4180_1 | 3:454d1f4c8fd7 | 97 | niterations = n; |
4180_1 | 3:454d1f4c8fd7 | 98 | isInside = false; |
4180_1 | 3:454d1f4c8fd7 | 99 | break; |
4180_1 | 3:454d1f4c8fd7 | 100 | } |
4180_1 | 3:454d1f4c8fd7 | 101 | Z_im = 2*Z_re*Z_im + c_im; |
4180_1 | 3:454d1f4c8fd7 | 102 | Z_re = Z_re2 - Z_im2 + c_re; |
4180_1 | 3:454d1f4c8fd7 | 103 | } |
4180_1 | 3:454d1f4c8fd7 | 104 | if(isInside==false) uLCD.pixel(x,y,((niterations & 0xFC0)<<14)+((niterations & 0x38)<<9)+((niterations & 0x07)<<5) ); |
4180_1 | 3:454d1f4c8fd7 | 105 | } |
4180_1 | 3:454d1f4c8fd7 | 106 | } |
4180_1 | 2:75727e89a717 | 107 | } |