Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DmTouch_UniGraphic UniGraphic mbed
Fork of DAY_8_miniproject by
main.cpp
00001 /* Do not publish changes to this program back to the remote repository. Fork your own copy, or else */ 00002 #include "stdio.h" 00003 #include "mbed.h" 00004 #include "string" 00005 #include "ILI932x.h" 00006 #include "DmTouch.h" 00007 00008 00009 #include "Arial12x12.h" 00010 #include "Arial24x23.h" 00011 #include "pavement_48x34.h" 00012 00013 Serial pc(USBTX, USBRX); 00014 DigitalIn x_up(p6); 00015 DigitalIn x_down(p5); 00016 AnalogIn Ain(p19); 00017 DigitalIn slide(p9); 00018 00019 /* Configure the DisplayModule ILI9325 2.4" display for 8-bit bus communication 00020 00021 mbed pin display pin 00022 -------- ----------- 00023 p15 CS (L15) 00024 p17 RST (L17) 00025 p16 RS (L4) 00026 p14 WR (L5) 00027 p20 RD (L6) 00028 00029 p30 DB8 (L7) 00030 p29 DB9 (L8) 00031 p28 DB10 (L9) 00032 p27 DB11 (L10) 00033 p26 DB12 (L11) 00034 p25 DB13 (L12) 00035 p24 DB14 (L13) 00036 p23 DB15 (L14) 00037 00038 p1 GND (L1) 00039 p40 Vin (L2) 00040 p40 LED Backlight (L19) 00041 */ 00042 PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; 00043 ILI932x myLCD(BUS_8, dataBus, p15, p17, p16, p14, p20, "myLCD", 240, 320); // Bus 8 bit, bus pin array, CS, RST, DC, WR, RD, name, xpixels, ypixels 00044 00045 /* Additional connections to add touch response 00046 00047 mbed pin display pin 00048 -------- ----------- 00049 p5 T_MOSI (R11) 00050 p6 T_MISO (R13) 00051 p7 T_CLK (R9) 00052 p8 T_CS (R10) 00053 p9 T_IRQ (R14) 00054 */ 00055 DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9); 00056 00057 char orient=3; 00058 int x,y; 00059 uint16_t tx, ty; 00060 Timer t; 00061 DigitalOut led1(LED1); 00062 DigitalOut led2(LED2); 00063 SPI acc(p5,p6,p7); 00064 DigitalOut cs(p14); 00065 char buffer[6]; 00066 int16_t data[3]; 00067 float x1,y1,z1; 00068 int main() 00069 { 00070 00071 00072 00073 int main(){ 00074 cs=1; 00075 acc.format(8,3); 00076 acc.frequency(2000000); 00077 cs=0; 00078 acc.write(0x31); 00079 acc.write(0x0B); 00080 cs=1; 00081 cs=0; 00082 acc.write(0x2D); 00083 acc.write(0x08); 00084 cs=1; 00085 while(1){ 00086 wait(0.2); 00087 cs=0; 00088 acc.write(0x80|0x40|0x32); 00089 for(int i = 0; i <=5;i++){ 00090 buffer[i] = acc.write(0x00); 00091 } 00092 cs=1; 00093 data[0]= buffer[1]<<8 |buffer[0]; 00094 data[1] = buffer[3]<<8|buffer[2]; 00095 data[2]= buffer[5]<<8 |buffer[4]; 00096 x1=0.004*data[0]; 00097 y1 = 0.004*data[1]; 00098 z1 = 0.004*data[2]; 00099 pc.printf("x = %+1.2fg\t y = %+1.2fg\t z = %1.2fg\n\r", x1,y1,z1); 00100 } 00101 00102 00103 00104 //Day 8 Lab 2 00105 /*int y_pos = 120,x_pos = 160; //Just Variables for x-axis and y-axis 00106 while (1) { 00107 00108 if (!slide){ 00109 myLCD.cls(); 00110 } 00111 00112 y_pos = Ain*240; //converts to pixals 00113 00114 if (x_up == 1){ 00115 if (x_pos >= 320) 00116 x_pos = 314; 00117 wait(0.08); 00118 x_pos = x_pos + 1; 00119 led1 = 1; 00120 } 00121 if (x_down == 1){ 00122 if (x_pos <= 0) 00123 x_pos = 5; 00124 wait(0.08); 00125 x_pos = x_pos - 1; 00126 led2 = 1; 00127 } 00128 myLCD.locate(y_pos,x_pos); 00129 myLCD.pixel(y_pos,x_pos,White); 00130 }*/ 00131 /* 00132 00133 bool down, lastDown; 00134 touch.init(); 00135 t.start(); 00136 myLCD.set_orientation(orient); 00137 myLCD.set_font((unsigned char*) Arial24x23); 00138 myLCD.background(Blue); // set background to Blue 00139 myLCD.foreground(White); // set chars to White 00140 myLCD.cls(); // clear the screen 00141 myLCD.locate(10,30); 00142 myLCD.printf("UniGraphics Demo\r\n"); 00143 wait(2); 00144 00145 while(1) 00146 { 00147 myLCD.cls(); // clear the screen 00148 myLCD.set_font((unsigned char*) Arial24x23); 00149 myLCD.locate(0,30); 00150 myLCD.printf("Orientation mode: %x\r\n", orient%4); 00151 wait(2); 00152 myLCD.printf("Font is\r\n"); 00153 myLCD.printf("Arial24x23\r\n"); 00154 wait(2); 00155 00156 myLCD.background(Black); 00157 myLCD.foreground(White); 00158 myLCD.cls(); // clear the screen 00159 myLCD.set_font((unsigned char*) Arial12x12); 00160 myLCD.locate(0,10); 00161 myLCD.printf("Font changed to Arial12x_pos2\r\n"); 00162 myLCD.printf("Background and foreground color also changed.\n\r\n\r"); 00163 wait(2); 00164 myLCD.printf("Notice that if some text is too long to fit the width of the screen that it is automatically wrapped to the next line.\r\n\r\n"); 00165 wait(2); 00166 myLCD.set_font((unsigned char*) Terminal6x8); 00167 myLCD.printf("Font changed to Terminal6x8\r\n"); 00168 myLCD.printf("This is pretty small!\r\n"); 00169 wait(2); 00170 00171 myLCD.cls(); 00172 myLCD.set_font((unsigned char*) Arial24x23); 00173 myLCD.locate(10,10); 00174 myLCD.printf("Draw lines\n\r"); 00175 myLCD.line(0,50,myLCD.width()-1,50,Yellow); 00176 myLCD.line(myLCD.width()-50,51,myLCD.width()-50,myLCD.height()-1,Green); 00177 wait(2); 00178 00179 myLCD.cls(); 00180 myLCD.locate(10,10); 00181 myLCD.printf("Draw rectangles"); 00182 myLCD.rect(10,50,50,80,Red); 00183 myLCD.rect(15,55,45,75,Red); 00184 myLCD.rect(20,60,40,70,Red); 00185 myLCD.fillrect(160,130,200,240,Blue); 00186 wait(2); 00187 00188 myLCD.cls(); 00189 myLCD.locate(10,10); 00190 myLCD.printf("Draw circles"); 00191 myLCD.circle(150,132,30,Yellow); 00192 myLCD.fillcircle(140,70,25,Cyan); 00193 wait(2); 00194 00195 myLCD.cls(); 00196 myLCD.set_font((unsigned char*) Arial12x12); 00197 myLCD.locate(10,10); 00198 myLCD.printf("Draw function with pixels"); 00199 double s; 00200 for (unsigned short i=0; i<myLCD.width(); i++) 00201 { 00202 s =10 * sin((long double) i / 10 ); 00203 myLCD.pixel(i,80 + (int)s ,White); 00204 } 00205 wait(3); 00206 00207 // Touch screen demo 00208 myLCD.background(Blue); // set background to Blue 00209 myLCD.foreground(White); // set chars to White 00210 myLCD.cls(); // clear the screen 00211 myLCD.locate(10,30); 00212 myLCD.set_font((unsigned char*) Arial24x23); 00213 myLCD.printf("DmTouch Demo\r\n"); 00214 myLCD.set_font((unsigned char*) Arial12x12); 00215 myLCD.locate(10,70); 00216 myLCD.printf("Coming soon...\r\nTouch screen and coordinates will display\r\n"); 00217 myLCD.printf("Moves to next portion of demo after 30 seconds\r\n"); 00218 wait(2); 00219 myLCD.background(Black); // set background to Black 00220 myLCD.foreground(White); // set chars to White 00221 myLCD.cls(); // clear the screen 00222 00223 touch.setOrientation(orient); 00224 down = false; 00225 lastDown = false; 00226 tx = (uint16_t)0; 00227 ty = (uint16_t)0; 00228 myLCD.locate(20,20); 00229 myLCD.printf("x:"); 00230 myLCD.locate(100, 20); 00231 myLCD.printf("y:"); 00232 00233 t.reset(); 00234 while (t.read()<30) { 00235 touch.readTouchData(tx, ty, down); 00236 if (down) { 00237 myLCD.locate(40, 20); 00238 myLCD.printf("%5i", tx); 00239 myLCD.locate(120, 20); 00240 myLCD.printf("%5i", ty); 00241 myLCD.fillcircle(tx, ty, 2, Red); 00242 } else if (lastDown) { 00243 // no longer pressed, clean text 00244 myLCD.locate(40, 20); 00245 myLCD.printf(" ", tx); 00246 myLCD.locate(120, 20); 00247 myLCD.printf(" ", ty); 00248 } 00249 wait(0.040); 00250 lastDown = down; 00251 } 00252 00253 00254 // scroll test, only for TFT 00255 myLCD.cls(); 00256 myLCD.set_font((unsigned char*) Arial24x23); 00257 myLCD.locate(2,10); 00258 myLCD.printf("Scrolling"); 00259 myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); 00260 myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); 00261 myLCD.setscrollarea(0,myLCD.sizeY()); 00262 wait(1); 00263 myLCD.scroll(1); //up 1 00264 wait(1); 00265 myLCD.scroll(0); //center 00266 wait(1); 00267 myLCD.scroll(myLCD.sizeY()-1); //down 1 00268 wait(1); 00269 myLCD.scroll(myLCD.sizeY()); // same as 0, center 00270 wait(1); 00271 myLCD.scroll(myLCD.sizeY()>>1); // half screen 00272 wait(1); 00273 myLCD.scrollreset(); // center 00274 wait(1); 00275 for(unsigned short i=1; i<=myLCD.sizeY(); i++) 00276 { 00277 myLCD.scroll(i); 00278 wait_ms(2); 00279 } 00280 wait(2); 00281 // color inversion 00282 for(unsigned short i=0; i<=8; i++) 00283 { 00284 myLCD.invert(i&1); 00285 wait_ms(200); 00286 } 00287 wait(2); 00288 // bmp 16bit test 00289 myLCD.cls(); 00290 for(int y=0; y<myLCD.height(); y+=34) 00291 { 00292 for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); 00293 } 00294 wait(2); 00295 myLCD.set_orientation((++orient)%4); 00296 }*/ 00297 }
Generated on Fri Jul 15 2022 09:32:54 by
1.7.2
