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:
Thu May 25 10:58:02 2017 +0000
Parent:
18:02667782b06f
Child:
20:e4572fc1b10d
Commit message:
working demo of clock

Changed in this revision

clocklogic.h Show annotated file Show diff for this revision Revisions of this file
libs.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
singlepong.cpp Show diff for this revision Revisions of this file
singlepong.h Show diff for this revision Revisions of this file
--- a/clocklogic.h	Thu May 25 10:17:45 2017 +0000
+++ b/clocklogic.h	Thu May 25 10:58:02 2017 +0000
@@ -1,4 +1,4 @@
-int digital_clock_button_press(){
+int digital_clock_press(){
     int x = readX();
     int y = readY();
     if (touching == 1) {
@@ -26,7 +26,7 @@
             //set desired state to 0
             return 0;
         }
-        else if (x > 140 && x < 230 && y >  100 && y < 200) // alarm button on or off
+        else if (x > 140 && x < 320 && y >  100 && y < 200) // alarm button on or off
         {
             //set desired state to 5
             f_alarm = !(f_alarm);
@@ -39,12 +39,28 @@
     
 
 
-void clock()
+void runclock()
 {
     draw_state(1);
     while (f_state == 1){
-        read_time()
+        read_time();
         TFT.set_font((unsigned char*) Arial24x23); //set alarm hour
+        if (tm_c.sec == 0){
+            TFT.locate(250,40);
+            TFT.printf("  ");
+            if (tm_c.min == 0){
+                TFT.locate(160,40);
+                printf("%d",tm_c.min);
+                if (tm_c.hour == 0)
+                {
+                    TFT.locate(70,40);
+                    printf("%d",tm_c.hour);
+                }
+            }
+        }
+            
+            
+            
         TFT.locate(70,40);
         TFT.printf("%d",tm_c.hour);
         TFT.locate(160,40);
@@ -56,25 +72,26 @@
         TFT.printf("%s",rtc.weekdayToString(tm_c.wday));
         TFT.set_font((unsigned char*) Arial24x23);
         if (f_alarm) {
-        TFT.locate(160,140);
-        TFT.printf("%d",tm_a_hr);
-        TFT.locate(250,40);    
-        TFT.printf("%d",tm_a_min);    
+            TFT.locate(160,140);
+            TFT.printf("%d",tm_a_hr);
+            TFT.locate(250,140);    
+            TFT.printf("%d",tm_a_min);    
         }
         else
         {
             TFT.locate(160,140);
             TFT.printf("   ");
-           TFT.locate(250,40);    
+           TFT.locate(250,140);    
            TFT.printf("   ");   
         }
-        TFT.locate(210,70);
-        TFT.printf("%s",tm_c.date);
-        TFT.locate(250,160);    
+        TFT.locate(70,210);
+        TFT.printf("%d / %d / %d", tm_c.date, tm_c.mon, tm_c.year);
+        wait(0.2);
+       /* TFT.locate(160,210);    
         TFT.printf("%d",tm_c.mon);    
-        TFT.locate(250,250);    
-        TFT.printf("%d",tm_c.year);    
-        }
+        TFT.locate(220,210);    
+        TFT.printf("%d",tm_c.year);     */
+        
         switch (digital_clock_press()){
             case (-1): break;
             case (0): f_state = 0; break;
--- a/libs.h	Thu May 25 10:17:45 2017 +0000
+++ b/libs.h	Thu May 25 10:58:02 2017 +0000
@@ -10,4 +10,5 @@
 #include "drawStates.h"
 #include "RTC.h"
 #include "slider.h"
+#include "clocklogic.h"
 
--- a/main.cpp	Thu May 25 10:17:45 2017 +0000
+++ b/main.cpp	Thu May 25 10:58:02 2017 +0000
@@ -1,26 +1,31 @@
+bool f_alarm = false, f_alarm_sound;
+int f_state;
 #include "libs.h"
 //DigitalOut led(LED1);
-bool f_alarm, f_alarm_sound;
-int f_state_no;
+
 //DigitalIn sw_w(SW3);
 
 void main()
 {
+    while(!rtc.startClock()){}
     TFT.claim(stdout);        // send stdout to the TFT display
     TFT.set_orientation(1);
     TFT.background(Black);    // set background to black
     TFT.foreground(White);    // set chars to white
     TFT.cls();
     // pc.baud(115200);
-    /*int i = 0;
+    f_state = 1;
+    f_alarm = false;
+    runclock();
+    int i = 0;
     while (true) {
         i = (i % 3) + 1;
         draw_state(i);
         wait(1);
-    }*/
+    }
     
     
-    draw_state(4);
+    //draw_state(4);
 
 
 
--- a/singlepong.cpp	Thu May 25 10:17:45 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-
-#include "libs.h"
-#include "singlepong.h"
-
-int main() {
-
-    float location_player = 120 - ( 120 * tsi_d() ); //reading analog inputs from the potentiometers
-    int SCREENH = 239 ; //screen height
-    int SCREENW = 319 ; //screen width
-    int PADDLEW  = 10 ; // paddle width
-    int PADDLEH  = 40 ; // paddle height
-    int PADDLEG =  10 ; // paddle gap from the touchscreen
-    int ABALL = 10 ;   // ball size
-    int PADDLE_A = 0 ; // location paddle A
-    int PADDLE_AF = 0 ; // final location paddle A   
-    float XBALL = 0 ; // ball's x location
-    float YBALL = 0 ; // ball's y location
-    
-    float VXball = 3 ; // velocity in x-direction 
-    float VYball = 2 ; // velocity in y-direction
-    
-    while(1) {
-        draw();
-        move();
-        wait(0.01) ;  
-    } 
-}   
-         
\ No newline at end of file
--- a/singlepong.h	Thu May 25 10:17:45 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-#include "libs.h"
-
-float map(float in, float inMin, float inMax, float outMin, float outMax) {
-      // check it's within the range
-        if (inMin<inMax) { 
-            if (in <= inMin) 
-              return outMin;
-            if (in >= inMax)
-              return outMax;
-            } 
-        else {  // cope with input range being backwards.
-            if (in >= inMin) 
-              return outMin;
-            if (in <= inMax)
-              return outMax;
-        }
-      // calculate how far into the range we are
-      float scale = (in-inMin)/(inMax-inMin);
-      // calculate the output.
-      return outMin + scale*(outMax-outMin);
-}
-
-
-void move() {
-    
-    int player = location_player ; ;
-    PADDLE_A = map(player , 0 , 1023 , 0 , SCREENH - PADDLEH) ;
-    int VPADDLE_A = PADDLE_AF - PADDLE_A ; // speed of paddle A
-
-    
-    XBALL += VXBALL ; //x location of the ball 
-    YBALL += VYBALL ; //y location of the ball 
-    
-    //bounce from the top and bottom
-    
-    if (YBALL >= SCREENH - ABALL || YBALL <=0) 
-    {
-    VYBALL *= -1 ; 
-    }
-    
-    //bounce from Paddle A
-    if (XBALL >= PADDLEG && XBALL <= PADDLEG + ABALL && VXBALL < 0) 
-    {
-        if (YBALL > PADDLE_A - ABALL && YBALL < PADDLE_A + PADDLEH)
-        {
-        VXBALL *= -1 ;
-        }
-    }
-    
-    //bounce from the opposite wall   
-    
-    if ( XBALL >= SCREENW )
-    { 
-      VXBALL *= -1 ;
-                }
-            
-            
-   // if the the wall scores
-   
-   if (XBALL <= 0 ) {
-        
-        // reset function //
-        
-        }           
-       
-       }
-       
- void draw() 
-{  
-   
-
-   fillcircle(XBALL , YBALL , ABALL , 1 ) ;  //draw ball 
-   
-   fillrect( PADDLEG , PADDLE_A , PADDLEW , PADDLEH , 1) ; //draw paddle A
-   
-   
-   }
-
-
-
-        
\ No newline at end of file