Joshua Miller / Mbed 2 deprecated LCDTouchingCircles

Dependencies:   DmTouch_UniGraphic UniGraphic mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "stdio.h"
00002 #include "mbed.h"
00003 #include "string"
00004 #include "ILI932x.h"
00005 #include "DmTouch.h"
00006 #include "Arial24x23.h"
00007 
00008 /* Configure the DisplayModule ILI9325 2.4" display for 8-bit bus communication
00009 
00010     mbed pin    display pin
00011     --------    -----------
00012     p15         CS (L15)
00013     p17         RST (L17)
00014     p16         RS (L4)
00015     p14         WR (L5)
00016     p20         RD (L6)
00017     
00018     p30         DB8 (L7)
00019     p29         DB9 (L8)
00020     p28         DB10 (L9)
00021     p27         DB11 (L10)
00022     p26         DB12 (L11)
00023     p25         DB13 (L12)
00024     p24         DB14 (L13)
00025     p23         DB15 (L14)
00026     
00027     p1          GND (L1)
00028     p40         Vin (L2)
00029     p40         LED Backlight (L19)
00030     
00031     Additional connections to add touch response
00032 
00033     mbed pin    display pin
00034     --------    -----------
00035     p5          T_MOSI (R11)
00036     p6          T_MISO (R13)
00037     p7          T_CLK (R9)
00038     p8          T_CS (R10)
00039     p9          T_IRQ (R14)
00040 */  
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 DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9);
00045 char orient=3;              // orient horizontal is long axis
00046 bool down, lastDown;        // keeps track of whether or not the screen is/was pressed
00047 Timer t;
00048 DigitalOut led1(LED1);
00049 DigitalOut led2(LED2);
00050 DigitalOut led3(LED3);
00051 DigitalOut led4(LED4);
00052 uint16_t tx,ty;         // coordinates for touch screen
00053 
00054 int main(){
00055     
00056     touch.init();
00057     t.start();
00058     myLCD.set_orientation(orient);
00059     myLCD.background(Black);    // set background to Black
00060     myLCD.foreground(White);    // set chars to White
00061     myLCD.fillcircle(80,60,30,Blue);    //creating circles
00062     myLCD.fillcircle(240,60,30,Red);
00063     myLCD.fillcircle(80,180,30,Green);
00064     myLCD.fillcircle(240,180,30,Yellow);
00065     
00066    myLCD.set_font((unsigned char*) Arial24x23);
00067     myLCD.locate(70,50);
00068     myLCD.printf("1\t");
00069     myLCD.locate(230,50);
00070     myLCD.printf("2\t");
00071     myLCD.locate(70,170);
00072     myLCD.printf("3\t");
00073     myLCD.locate(230,170);
00074     myLCD.printf("4\t");
00075     
00076     // Touch screen demo
00077 
00078         touch.setOrientation(orient);       // orient LCD screen
00079         down = false;
00080         bool justDown = false;
00081 
00082         t.reset();                          // reset timer
00083         while (1) {
00084             
00085             touch.readTouchData(tx, ty, down);          // read if touch screen is pressed and where
00086             if (down){
00087                 if(t.read_ms()>200){                    // "debounce
00088                     if ((110>tx) && (tx>50) && (90>ty) && (ty>30))  // if touch screen is pressed in circle 1
00089                         led1 = !led1;                               //toggle LED 1
00090                     if ((270>tx) && (tx>210) && (90>ty) && (ty>30)) // if touch screen is pressed in circle 2
00091                         led2 = !led2;                               //toggle LED 2
00092                     if ((110>tx) && (tx>50) && (210>ty) && (ty>150)) // if touch screen is pressed in circle 3
00093                         led3 = !led3;                               //toggle LED 3
00094                     if ((270>tx) && (tx>210) && (210>ty) && (ty>150)) // if touch screen is pressed in circle 4
00095                         led4 = !led4;                               //toggle LED 4
00096                     
00097                 t.reset();                              // reset timer
00098                 wait(0.04);
00099                 
00100                 }   
00101                 else if (justDown) {                        // if it was just pressed but is no longer pressed
00102                     
00103                 // necessary to prevent leds from blinking
00104                 myLCD.locate(40, 20);
00105                 myLCD.printf("     ");
00106                 }
00107                 justDown = down;                
00108             }
00109         }
00110                 
00111 }