Contains the main execution of the clock uses headers to import functions

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor

Fork of TFT_Mikroelectronika_IL9341_sketchpad by Oxford CWM Team

Files at this revision

API Documentation at this revision

Comitter:
Owenmatthewmcgowan
Date:
Fri May 26 08:36:54 2017 +0000
Parent:
42:5d9ccb16c8ef
Parent:
39:4b70d28cb273
Child:
44:1c516642c34e
Commit message:
comments;

Changed in this revision

--- a/clocklogic.h	Fri May 26 08:34:48 2017 +0000
+++ b/clocklogic.h	Fri May 26 08:36:54 2017 +0000
@@ -1,6 +1,6 @@
 int digital_clock_press(){
-    int x = readX();
-    int y = readY();
+    int x = readX(); // read x location 
+    int y = readY(); // read y location
     if (touching == 1) {
        
         if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state)
@@ -31,7 +31,7 @@
         {
             //set desired state to 5
             f_alarm = !(f_alarm);
-            f_alarm_sound = false;
+            f_alarm_sound = false;  // flag for the alarm sound
             return -1;
         }
     }
@@ -41,26 +41,27 @@
     
 
 
-void runclock()
+void runclock() // getting time from the clock
 {
-    DigitalOut gnd(PTA4) ;
+    DigitalOut gnd(PTA4) ; // initiating buzzer
     PwmOut buzzer(PTA5);
     float frequency[]={758, 758, 758, 955, 758, 638, 1276, 955, 1276, 1517, 1136, 1012, 1073, 1136, 1276, 758, 638, 568, 716, 638, 758, 955, 851, 1012, 955};
     //frequency array
     float beat[]={0.2, 0.4, 0.4, 0.2, 0.4, 0.8, 0.8, 0.6, 0.6, 0.6, 0.4, 0.4, 0.2, 0.4, 0.26, 0.26, 0.26, 0.4, 0.2, 0.4, 0.4, 0.2, 0.2, 0.2, 0.4};
+    //time intervals
     int i =0;
     int last = 0;
     draw_state(1);
     while (f_state == 1){
         read_time();
         TFT.set_font((unsigned char*) Arial24x23); //coverup
-        if (tm_c.sec == 0){
+        if (tm_c.sec == 0){      //getting seconds and printing
             TFT.locate(250,40);
             TFT.printf("  ");
-            if (tm_c.min == 0){
+            if (tm_c.min == 0){  //getting minutes and printing
                 TFT.locate(160,40);
                 printf("  ");
-                if (tm_c.hour == 0)
+                if (tm_c.hour == 0)  //getting hours and printing
                 {
                     TFT.locate(70,40);
                     printf("  ");
@@ -69,11 +70,11 @@
         }
             
                 if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){
-                    f_alarm_sound = true;
+                    f_alarm_sound = true; //alarm buzzes
                 }
                 
       
-                if (f_alarm_sound)
+                if (f_alarm_sound) 
                 {
                     i = i % 26;
                     i++ ;
--- a/drawStates.h	Fri May 26 08:34:48 2017 +0000
+++ b/drawStates.h	Fri May 26 08:36:54 2017 +0000
@@ -2,31 +2,31 @@
 
 void draw_state(int i)
 {
-    TFT.cls();
+    TFT.cls(); // clear screen
     switch (i) {
-        case (1):
+        case (1): // interface 1 : digital clock 
             //buttons
-            TFT.fillrect(0, 0, 50, 50, Red);
+            TFT.fillrect(0, 0, 50, 50, Red);  //first button for digital to analog interface change
             TFT.background(Red);
             TFT.locate(2,5);
             TFT.set_font((unsigned char*) Arial12x12);
             TFT.printf("Dig/\n\rALog");
-            TFT.fillrect(0, 50, 50, 100, Green);
+            TFT.fillrect(0, 50, 50, 100, Green); //second button for settings page
             TFT.background(Green);
             TFT.locate(2, 55);
             TFT.printf("Set\n\rTime");
-            TFT.fillrect(0, 100, 50, 150, Blue);
+            TFT.fillrect(0, 100, 50, 150, Blue); //third button for whiteboard
             TFT.background(Blue);
             TFT.locate(2, 105);
             TFT.printf("Draw");
             TFT.background(White);
-            TFT.fillrect(0, 150, 50, 200, White);
+            TFT.fillrect(0, 150, 50, 200, White); //last button for pong game
             TFT.foreground(Black);
             TFT.locate(2,155);
             TFT.printf("Pong");
             TFT.background(Black);
             TFT.foreground(White);
-            TFT.fillrect(0, 200, 50, 240, Black);
+            TFT.fillrect(0, 200, 50, 240, Black); //home button to reset
             TFT.locate(2, 205);
             TFT.printf("Home");
 
@@ -56,8 +56,8 @@
             TFT.fillcircle(tx, ty - 10, 2, White);
             TFT.fillcircle(tx, ty + 10, 2, White);
             break;
-        case (2):
-            //buttons
+        case (2): // analog clock interface
+            //same button configuration as the first interface
             TFT.fillrect(0, 0, 50, 50, Red);
             TFT.background(Red);
             TFT.locate(2,5);
@@ -100,7 +100,7 @@
             TFT.fillcircle(tx - 10, 100, 2, White);
             TFT.fillcircle(tx + 10, 100, 2, White);
             break;
-        case (4):
+        case (4): // whiteboard
             whiteboard();
             break;
 
--- a/drawhands.h	Fri May 26 08:34:48 2017 +0000
+++ b/drawhands.h	Fri May 26 08:36:54 2017 +0000
@@ -1,18 +1,19 @@
 
+//early version of the analog clock draw function
 void draw_hands ( int x0 , int y0 , int r , float minutes , int hours , int color) 
    {
           int x1,y1,x2,y2;
           int rs = 0.6 * r ; // shorter moving hand
-          int m = minutes ;        
-          int k = hours % 12; 
-          double angle2 = k * M_PI / 6 ;
+          int m = minutes ;  // minutes      
+          int k = hours % 12;  // hours
+          double angle2 = k * M_PI / 6 ; // scaling 
           double angle = m * M_PI / 30 ;
-          x1 = rs * sin(angle) + x0;
+          x1 = rs * sin(angle) + x0; // trigonometric functions to get values
           y1 = rs * cos(angle) + y0;
           x2 = r * sin(angle2) + x0;
           y2 = r * cos(angle2) + y0;
-          TFT.line(x0, y0, x2, y2, color);
-          TFT.line(x0, y0, x1, y1, color); 
+          TFT.line(x0, y0, x2, y2, color); //draw line
+          TFT.line(x0, y0, x1, y1, color); //draw line
   }
           
           
--- a/render.h	Fri May 26 08:34:48 2017 +0000
+++ b/render.h	Fri May 26 08:36:54 2017 +0000
@@ -5,9 +5,9 @@
 #include "Arial28x28.h"
 #include "font_big.h"
 
-
+//the functions to draw buttons , the analog clock and whiteboard
 
-void drawbuttons()
+void drawbuttons()  //draw buttons
 {
     TFT.fillrect(0, 0, 50, 50, Red);
     TFT.fillrect(0, 50, 50, 100, Green);
@@ -21,8 +21,8 @@
     TFT.rect(0, 150, 50, 200, White);
     TFT.rect(0, 200, 50, 250, White);
 }
-void draw_clockface(int x0, int y0, int r, int markerlength, int color)
-{
+void draw_clockface(int x0, int y0, int r, int markerlength, int color) // final version for analog clock
+{ 
     TFT.circle(x0, y0, r, White);
     for ( int n = 0; n < 13; n++) {
       int x1, y1, x2, y2= 0;
@@ -34,7 +34,7 @@
       TFT.line(x1, y1, x2, y2, color);
     }
 }
-void whiteboard()
+void whiteboard() //white board fuction
 {   
     TFT.cls();
     int color = 0;
@@ -55,7 +55,7 @@
         if(xp > 5 && yp > 50 && touching == 1) TFT.fillcircle(xp,yp, 2, color);
         if(xp < 50) { // color buttons
             sw = (int)yp / 50;
-            switch(sw) {
+            switch(sw) { // changing colors
                 case 0:
                     color = 0xf800;
                     break;