Mini Project 10: Displaying stuff from day 7

Dependencies:   DmTouch_UniGraphic UniGraphic mbed

Revision:
10:ee5708e7a36a
Parent:
9:0f4c86e7218a
Child:
11:482a9abbc448
--- a/main.cpp	Tue Jan 17 20:14:51 2017 +0000
+++ b/main.cpp	Tue Jan 17 20:22:49 2017 +0000
@@ -14,12 +14,12 @@
 #include "compass_sensor.h"
 #include "temp_sensor.h"
 #include "acceler_sensor.h"
-char orient=3;
+char orient=3; //orientation of the LCD and touch screen
 Serial pc(USBTX, USBRX);
 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
+int choice = 0; //choice for the buttons on the touch screen: 1 = acceleration, 2 = compass, 3 = temperature
 //const int addr1 = 0x53<<1;
 DigitalOut led1(LED1);                             // configures mbed internal LED 1
 DigitalOut led2(LED2);                             // configures mbed internal LED 2 
@@ -30,36 +30,36 @@
 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 t; //timer for the touch screen
 
-void UI()
+void UI() //the general UI code for the touch screen
 {
                 myLCD.set_font((unsigned char*) Arial24x23);
                 myLCD.locate(60, 100);
-                myLCD.printf("A");
-                myLCD.circle(60,100,30,Blue);
+                myLCD.printf("A"); //accleration label
+                myLCD.circle(60,100,30,Blue); //acceleration button
                 myLCD.locate(160, 100);
-                myLCD.printf("C");
-                myLCD.circle(160,100,30,Green);
+                myLCD.printf("C"); //compass label
+                myLCD.circle(160,100,30,Green); //compass button
                 myLCD.locate(260, 100);
-                myLCD.printf("T");
-                myLCD.circle(260,100,30,Red);
+                myLCD.printf("T"); //temp. label
+                myLCD.circle(260,100,30,Red); //temp. button
 }
   
 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;
+         myLCD.set_orientation(orient); //orientation of the screen
+         myLCD.set_font((unsigned char*) Arial24x23); //font
+        touch.setOrientation(orient); //orientation of the touch screen
+        down = false; //down portion of the touch screen
+        lastDown = false; //last down -- what down was last time
+        tx = (uint16_t)0; //x-coordinates of the touch screen
+        ty = (uint16_t)0; //y-coordinates of the touch screen
         //char sensorData[1];
         led1 = 0;
         led2 = 0;
-        UI();
-        touch.init();
-        t.start();
+        UI(); //sets the the UI
+        touch.init(); //initializes touch screen
+        t.start(); //starts timer
         //avg = compass_config();
         //temperature_config();
         //configure_acceleration();
@@ -69,42 +69,42 @@
              t.reset();
              while (t.read()<10)
              {
-                touch.readTouchData(tx, ty, down);
+                touch.readTouchData(tx, ty, down); //reads in touch screen coordinates
                 if (down)
                 {
-                    if(tx >= 30 && tx <= 90 && ty >= 70 && ty <= 130)
+                    if(tx >= 30 && tx <= 90 && ty >= 70 && ty <= 130) //if the acceleration button is pressed
                     {
-                            if (choice == 2 || choice == 3)
+                            if (choice == 2 || choice == 3) //if other buttons were pushed before
                             {
-                                myLCD.cls();
+                                myLCD.cls(); //reset
                                 UI();
                             }
-                            myLCD.fillcircle(60,100,30,Blue);
+                            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(tx >= 130 && tx <= 190 && ty >= 70 && ty <= 130) //if the compass button is pressed
                     {
-                            if (choice == 1 || choice == 3)
+                            if (choice == 1 || choice == 3) //if other buttons were pushed before
                             {
-                                myLCD.cls();
+                                myLCD.cls(); //reset
                                 UI();
                             }
-                            myLCD.fillcircle(160,100,30,Green);
+                            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(tx >= 230 && tx <= 290 && ty >= 70 && ty <= 130) //if the temperature button is pressed
                     {
-                            if (choice == 1 || choice == 2)
+                            if (choice == 1 || choice == 2) //if any other buttons were pushed before
                             {
-                                myLCD.cls();
+                                myLCD.cls(); //reset
                                 UI();
                             }
-                            myLCD.fillcircle(260,100,30,Red);
+                            myLCD.fillcircle(260,100,30,Red); //establish which button is pushed
                             myLCD.locate(260, 100);
                             myLCD.printf("T");
                             choice = 3;
@@ -112,23 +112,27 @@
                 }
                 else if (lastDown)
                 {
-                    if (choice == 1)
+                    if (choice == 1) //acceleration
                     {
                             myLCD.locate(60, 100);
                             myLCD.printf("A");
                             myLCD.fillcircle(60,100,30,Blue);
+                            //acceleration
                         }
-                    if (choice == 2)
+                    if (choice == 2) //compass
                     {
                             myLCD.locate(160, 100);
                             myLCD.printf("C");
                             myLCD.fillcircle(160,100,30,Green);
+                            
+                            //compass
                         }
-                    if (choice == 3)
+                    if (choice == 3) //temperature
                     {
                             myLCD.locate(260, 100);
                             myLCD.printf("T");
                             myLCD.fillcircle(260,100,30,Red);
+                            //temperature
                         }
                 }
             wait(0.040);