Mini Project 10: Displaying stuff from day 7

Dependencies:   DmTouch_UniGraphic UniGraphic mbed

Revision:
9:0f4c86e7218a
Parent:
8:bbe3e332fe94
Child:
10:ee5708e7a36a
--- a/main.cpp	Tue Jan 17 19:30:09 2017 +0000
+++ b/main.cpp	Tue Jan 17 20:14:51 2017 +0000
@@ -19,6 +19,7 @@
 I2C i2c_port(p9, p10);                             // configures pins 9,10 for I2C communication with external sensors
 float temp2;
 int avg;
+int choice = 0; //choice for the buttons on the touch screen
 //const int addr1 = 0x53<<1;
 DigitalOut led1(LED1);                             // configures mbed internal LED 1
 DigitalOut led2(LED2);                             // configures mbed internal LED 2 
@@ -27,20 +28,13 @@
 DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9);    
 PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23};
 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
-                  
-int main() {
-         myLCD.set_orientation(orient);
-        //char sensorData[1];
-        led1 = 0;
-        led2 = 0;
-        //avg = compass_config();
-        //temperature_config();
-        //configure_acceleration();
-        while(1){
-            myLCD.set_font((unsigned char*) Arial24x23);
-            //myLCD.foreground(Black);
-             //myLCD.background(White);
-             touch.readTouchData(tx, ty, down);
+bool down, lastDown;
+uint16_t tx, ty;
+Timer t;
+
+void UI()
+{
+                myLCD.set_font((unsigned char*) Arial24x23);
                 myLCD.locate(60, 100);
                 myLCD.printf("A");
                 myLCD.circle(60,100,30,Blue);
@@ -50,7 +44,98 @@
                 myLCD.locate(260, 100);
                 myLCD.printf("T");
                 myLCD.circle(260,100,30,Red);
-                getacceleration();
+}
+  
+int main() {
+         myLCD.set_orientation(orient);
+         myLCD.set_font((unsigned char*) Arial24x23);
+        touch.setOrientation(orient);
+        down = false;
+        lastDown = false;
+        tx = (uint16_t)0;
+        ty = (uint16_t)0;
+        //char sensorData[1];
+        led1 = 0;
+        led2 = 0;
+        UI();
+        touch.init();
+        t.start();
+        //avg = compass_config();
+        //temperature_config();
+        //configure_acceleration();
+        while(1){
+            //myLCD.foreground(Black);
+             //myLCD.background(White);
+             t.reset();
+             while (t.read()<10)
+             {
+                touch.readTouchData(tx, ty, down);
+                if (down)
+                {
+                    if(tx >= 30 && tx <= 90 && ty >= 70 && ty <= 130)
+                    {
+                            if (choice == 2 || choice == 3)
+                            {
+                                myLCD.cls();
+                                UI();
+                            }
+                            myLCD.fillcircle(60,100,30,Blue);
+                            myLCD.locate(60, 100);
+                            myLCD.printf("A");
+                            choice = 1;
+                    }
+                    if(tx >= 130 && tx <= 190 && ty >= 70 && ty <= 130)
+                    {
+                            if (choice == 1 || choice == 3)
+                            {
+                                myLCD.cls();
+                                UI();
+                            }
+                            myLCD.fillcircle(160,100,30,Green);
+                            myLCD.locate(160, 100);
+                            myLCD.printf("C");
+                            choice = 2;
+                            
+                    }
+                    if(tx >= 230 && tx <= 290 && ty >= 70 && ty <= 130)
+                    {
+                            if (choice == 1 || choice == 2)
+                            {
+                                myLCD.cls();
+                                UI();
+                            }
+                            myLCD.fillcircle(260,100,30,Red);
+                            myLCD.locate(260, 100);
+                            myLCD.printf("T");
+                            choice = 3;
+                    }
+                }
+                else if (lastDown)
+                {
+                    if (choice == 1)
+                    {
+                            myLCD.locate(60, 100);
+                            myLCD.printf("A");
+                            myLCD.fillcircle(60,100,30,Blue);
+                        }
+                    if (choice == 2)
+                    {
+                            myLCD.locate(160, 100);
+                            myLCD.printf("C");
+                            myLCD.fillcircle(160,100,30,Green);
+                        }
+                    if (choice == 3)
+                    {
+                            myLCD.locate(260, 100);
+                            myLCD.printf("T");
+                            myLCD.fillcircle(260,100,30,Red);
+                        }
+                }
+            wait(0.040);
+            lastDown = down;
+            }
+            }
+                //getacceleration();
             /*wait(1);
             i2c_port.start();                        // forces start condition
             if (interupt == 1){
@@ -70,4 +155,3 @@
                     compass_n(avg);
                  }*/
                 }
-        }