Mini Project 10: Displaying stuff from day 7

Dependencies:   DmTouch_UniGraphic UniGraphic mbed

Revision:
12:bd1d030d5c30
Parent:
11:482a9abbc448
Child:
13:b3637adeaa2a
diff -r 482a9abbc448 -r bd1d030d5c30 main.cpp
--- a/main.cpp	Tue Jan 17 20:34:32 2017 +0000
+++ b/main.cpp	Tue Jan 17 20:55:08 2017 +0000
@@ -25,12 +25,13 @@
 DigitalOut led2(LED2);                             // configures mbed internal LED 2 
 DigitalIn interupt(p20);     // sets accelerometer interupt as digital input at pin 20;
 Timer sensor_timer;
-DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9);    
+DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p11);    
 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
 bool down, lastDown;
 uint16_t tx, ty;
-Timer t; //timer for the touch screen
+Ticker inter_t; //Ticker for the touch screen
+Timer t;
 float compass_h; //compass heading
 
 void UI() //the general UI code for the touch screen
@@ -46,6 +47,12 @@
                 myLCD.printf("T"); //temp. label
                 myLCD.circle(260,100,30,Red); //temp. button
 }
+
+void button()
+{
+    myLCD.cls(); //reset
+    UI();
+}
   
 int main() {
          myLCD.set_orientation(orient); //orientation of the screen
@@ -58,91 +65,93 @@
         //char sensorData[1];
         led1 = 0;
         led2 = 0;
+        t.start();
         UI(); //sets the the UI
         touch.init(); //initializes touch screen
-        t.start(); //starts timer
         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); //reads in touch screen coordinates
-                if (down)
-                {
-                    if(tx >= 30 && tx <= 90 && ty >= 70 && ty <= 130) //if the acceleration button is pressed
-                    {
-                            if (choice == 2 || choice == 3) //if other buttons were pushed before
+             //myLCD.background(White);   
+
+            t.reset();
+            while(t.read()<10)
+            {
+            touch.readTouchData(tx, ty, down); //reads in touch screen coordinates
+                        if (down)
+                        {
+                            if(tx >= 30 && tx <= 90 && ty >= 70 && ty <= 130) //if the acceleration button is pressed
                             {
-                                myLCD.cls(); //reset
-                                UI();
+                                    if (choice == 2 || choice == 3) //if other buttons were pushed before
+                                    {
+                                        myLCD.cls(); //reset
+                                        UI();
+                                    }
+                                    myLCD.fillcircle(60,100,30,Blue); //establish which button is pushed -- "highlight it"
+                                    myLCD.locate(60, 100);
+                                    myLCD.printf("A");
+                                    choice = 1;
                             }
-                            myLCD.fillcircle(60,100,30,Blue); //establish which button is pushed -- "highlight it"
-                            myLCD.locate(60, 100);
-                            myLCD.printf("A");
-                            choice = 1;
-                    }
-                    if(tx >= 130 && tx <= 190 && ty >= 70 && ty <= 130) //if the compass button is pressed
-                    {
-                            if (choice == 1 || choice == 3) //if other buttons were pushed before
+                            if(tx >= 130 && tx <= 190 && ty >= 70 && ty <= 130) //if the compass button is pressed
                             {
-                                myLCD.cls(); //reset
-                                UI();
-                            }
-                            myLCD.fillcircle(160,100,30,Green); //establish which button is pushed
-                            myLCD.locate(160, 100);
-                            myLCD.printf("C");
-                            choice = 2;
-                            
-                    }
-                    if(tx >= 230 && tx <= 290 && ty >= 70 && ty <= 130) //if the temperature button is pressed
-                    {
-                            if (choice == 1 || choice == 2) //if any other buttons were pushed before
-                            {
-                                myLCD.cls(); //reset
-                                UI();
+                                    if (choice == 1 || choice == 3) //if other buttons were pushed before
+                                    {
+                                        myLCD.cls(); //reset
+                                        UI();
+                                    }
+                                    myLCD.fillcircle(160,100,30,Green); //establish which button is pushed
+                                    myLCD.locate(160, 100);
+                                    myLCD.printf("C");
+                                    choice = 2;
+                                    
                             }
-                            myLCD.fillcircle(260,100,30,Red); //establish which button is pushed
-                            myLCD.locate(260, 100);
-                            myLCD.printf("T");
-                            choice = 3;
-                    }
-                }
-                else if (lastDown)
-                {
-                    if (choice == 1) //acceleration
-                    {
-                            myLCD.locate(60, 100);
-                            myLCD.printf("A");
-                            myLCD.fillcircle(60,100,30,Blue);
-                            //acceleration
+                            if(tx >= 230 && tx <= 290 && ty >= 70 && ty <= 130) //if the temperature button is pressed
+                            {
+                                    if (choice == 1 || choice == 2) //if any other buttons were pushed before
+                                    {
+                                        myLCD.cls(); //reset
+                                        UI();
+                                    }
+                                    myLCD.fillcircle(260,100,30,Red); //establish which button is pushed
+                                    myLCD.locate(260, 100);
+                                    myLCD.printf("T");
+                                    choice = 3;
+                            }
                         }
-                    if (choice == 2) //compass
-                    {
-                            myLCD.locate(160, 100);
-                            myLCD.printf("C");
-                            myLCD.fillcircle(160,100,30,Green);
-                            compass_h = compass_n();
-                            myLCD.locate(80, 150);
-                            myLCD.printf("%f degrees N", compass_h);
-                            //compass
+                        else if (lastDown)
+                        {
+                            if (choice == 1) //acceleration
+                            {
+                                    myLCD.locate(60, 100);
+                                    myLCD.printf("A");
+                                    myLCD.fillcircle(60,100,30,Blue);
+                                    //acceleration
+                                }
+                            if (choice == 2) //compass
+                            {
+                                    myLCD.locate(160, 100);
+                                    myLCD.printf("C");
+                                    myLCD.fillcircle(160,100,30,Green);
+                                    compass_h = compass_n();
+                                    myLCD.locate(80, 150);
+                                    myLCD.printf("%f degrees N", compass_h);
+                                    //compass
+                                }
+                            if (choice == 3) //temperature
+                            {
+                                    myLCD.locate(260, 100);
+                                    myLCD.printf("T");
+                                    myLCD.fillcircle(260,100,30,Red);
+                                    temp2 = temperature();
+                                    myLCD.locate(80, 150);
+                                    myLCD.printf("%f C", temp2);
+                                }
                         }
-                    if (choice == 3) //temperature
-                    {
-                            myLCD.locate(260, 100);
-                            myLCD.printf("T");
-                            myLCD.fillcircle(260,100,30,Red);
-                            temp2 = temperature();
-                            myLCD.locate(80, 150);
-                            myLCD.printf("%f C", temp2);
-                        }
-                }
-            wait(0.040);
-            lastDown = down;
-            }
+                    wait(0.040);
+                    lastDown = down;
+                    }
+                     inter_t.attach(&button,10);
             }
                 //getacceleration();
             /*wait(1);