Final Project for ECE-4180 Fall 2022. Interface with ENS160 AQI sensor and display the readings on uLCD.
Dependencies: 4DGL-uLCD-SE ENS160_Library mbed PinDetect mbed-rtos
Revision 3:454d1f4c8fd7, committed 2013-11-17
- Comitter:
- 4180_1
- Date:
- Sun Nov 17 04:37:03 2013 +0000
- Parent:
- 2:75727e89a717
- Child:
- 4:25a266a74a4c
- Commit message:
- ver 1.01
Changed in this revision
| 4DGL-uLCD-SE.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/4DGL-uLCD-SE.lib Mon Nov 11 01:33:12 2013 +0000 +++ b/4DGL-uLCD-SE.lib Sun Nov 17 04:37:03 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#8b656995301f +http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#edae99e4abe7
--- a/main.cpp Mon Nov 11 01:33:12 2013 +0000
+++ b/main.cpp Sun Nov 17 04:37:03 2013 +0000
@@ -27,8 +27,20 @@
int main()
{
-
- uLCD.baudrate(115200);
+ // basic printf demo = 16 by 18 characters on screen
+ uLCD.printf("\nHello uLCD World\n"); //Default Green on black text
+ uLCD.printf("\n Starting Demo...");
+ uLCD.text_width(4); //4X size text
+ uLCD.text_height(4);
+ uLCD.color(RED);
+ for (int i=10; i>=0; --i) {
+ uLCD.locate(1,2);
+ uLCD.printf("%2D",i);
+ wait(.5);
+ }
+ uLCD.cls();
+ uLCD.baudrate(256000); //jack up baud rate to max
+ //demo graphics
uLCD.background_color(DGREY);
uLCD.circle(60, 50, 30, 0xFF00FF);
uLCD.triangle(120, 100, 40, 40, 10, 100, 0x0000FF);
@@ -37,11 +49,59 @@
uLCD.pixel(60, 60, BLACK);
uLCD.read_pixel(120, 70);
uLCD.circle(120, 60, 10, BLACK);
- uLCD.set_font(FONT_8X8);
+ uLCD.set_font(FONT_7X8);
uLCD.text_mode(TRANSPARENT);
uLCD.text_char('B', 9, 8, BLACK);
uLCD.text_char('I',10, 8, BLACK);
uLCD.text_char('G',11, 8, BLACK);
- uLCD.text_string("This is a test of string", 1, 14, FONT_5X7, WHITE);
-
+ uLCD.text_string("This is a test of string", 1, 4, FONT_7X8, WHITE);
+ wait(2);
+ // printf text only mode demo
+ uLCD.background_color(BLUE);
+ uLCD.cls();
+ uLCD.locate(0,0);
+ uLCD.color(WHITE);
+ uLCD.textbackground_color(BLUE);
+ uLCD.set_font(FONT_7X8);
+ uLCD.text_mode(OPAQUE);
+ int i=0;
+ while(i<64) {
+ if(i%16==0) uLCD.cls();
+ uLCD.printf("TxtLine %2D Page %D\n",i%16,i/16 );
+ i++; //16 lines with 18 charaters per line
+ }
+//draw an image pixel by pixel
+ uLCD.background_color(BLACK);
+ uLCD.cls();
+//compute Mandelbrot image for display
+//image size in pixels and setup
+ const unsigned ImageHeight=128;
+ const unsigned ImageWidth=128;
+ double MinRe = -0.75104;
+ double MaxRe = -0.7408;
+ double MinIm = 0.10511;
+ double MaxIm = MinIm+(MaxRe-MinRe)*ImageHeight/ImageWidth;
+ double Re_factor = (MaxRe-MinRe)/(ImageWidth-1);
+ double Im_factor = (MaxIm-MinIm)/(ImageHeight-1);
+ unsigned MaxIterations = 4096;
+ for(unsigned y=0; y<ImageHeight; ++y) {
+ double c_im = MaxIm - y*Im_factor;
+ for(unsigned x=0; x<ImageWidth; ++x) {
+ double c_re = MinRe + x*Re_factor;
+ double Z_re = c_re, Z_im = c_im;
+ bool isInside = true;
+ int niterations=0;
+ for(unsigned n=0; n<MaxIterations; ++n) {
+ double Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im;
+ if(Z_re2 + Z_im2 > 4) {
+ niterations = n;
+ isInside = false;
+ break;
+ }
+ Z_im = 2*Z_re*Z_im + c_im;
+ Z_re = Z_re2 - Z_im2 + c_re;
+ }
+ if(isInside==false) uLCD.pixel(x,y,((niterations & 0xFC0)<<14)+((niterations & 0x38)<<9)+((niterations & 0x07)<<5) );
+ }
+ }
}
