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:
mlin
Date:
Thu May 25 15:32:20 2017 +0000
Parent:
30:af38c80391cb
Child:
32:56f59b79720c
Commit message:
.

Changed in this revision

RTC-DS1307.lib Show annotated file Show diff for this revision Revisions of this file
RTC.h Show annotated file Show diff for this revision Revisions of this file
clocklogic.h Show annotated file Show diff for this revision Revisions of this file
poll.h Show annotated file Show diff for this revision Revisions of this file
settings.h Show annotated file Show diff for this revision Revisions of this file
slider.h Show annotated file Show diff for this revision Revisions of this file
--- a/RTC-DS1307.lib	Thu May 25 13:24:26 2017 +0000
+++ b/RTC-DS1307.lib	Thu May 25 15:32:20 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/Iot-Ox/code/RTC-DS1307/#984b0ce5c236
+https://developer.mbed.org/teams/Iot-Ox/code/RTC-DS1307/#ccfd683953ae
--- a/RTC.h	Thu May 25 13:24:26 2017 +0000
+++ b/RTC.h	Thu May 25 15:32:20 2017 +0000
@@ -9,14 +9,11 @@
 void read_time()
 {
 //  perform read
-    pc.printf("Performing read operation\n\r");
     int n = 0;
     do   {
         n++;
     } while(!rtc.getTime(tm_c));
-    pc.printf("The current time is : %02d:%02d:%02d\n\r", tm_c.hour, tm_c.min, tm_c.sec);
-    pc.printf("The current date is : %s, %02d/%02d/%04d\n\r", rtc.weekdayToString(tm_c.wday), tm_c.mon, tm_c.date, tm_c.year);
-    pc.printf("Tried to read %d times\n\r",n);
+    
 }
 
 void write()
--- a/clocklogic.h	Thu May 25 13:24:26 2017 +0000
+++ b/clocklogic.h	Thu May 25 15:32:20 2017 +0000
@@ -2,6 +2,7 @@
     int x = readX();
     int y = readY();
     if (touching == 1) {
+       
         if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state)
         {
             //set desired state to 1 
@@ -69,7 +70,7 @@
         TFT.printf("%d",tm_c.sec);
         TFT.locate(60,140);
         TFT.set_font((unsigned char*) Arial12x12);
-        TFT.printf("%s",rtc.weekdayToString(tm_c.wday));
+        TFT.printf("%s",tm_c.wday);
         TFT.set_font((unsigned char*) Arial24x23);
         if (f_alarm) {
             TFT.locate(160,140);
--- a/poll.h	Thu May 25 13:24:26 2017 +0000
+++ b/poll.h	Thu May 25 15:32:20 2017 +0000
@@ -1,4 +1,8 @@
 #include "stdio.h"
+#define PinXm A1
+#define PinXp A0
+#define PinYm A3
+#define PinYp A2
 
 #include "SPI_TFT_ILI9341.h"
 
@@ -17,7 +21,7 @@
 
 // the TFT is connected to SPI pin 5-7
 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768
-SPI_TFT_ILI9341 TFT(PTD6, PTD7, PTD5, PTD2, PTD4, PTA13, "TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
+SPI_TFT_ILI9341 TFT(PTA16, PTA17, PTA15, PTD2, PTD4, PTA13, "TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
 //NB better combination to use a coherent 2x4 block for lcd
 //   SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
 //   DigitalOut LCD_LED(PTC17);
@@ -36,10 +40,10 @@
     int delta = 0, xv1 = 0, xv2 = 0, k = 0;
     int temp1 = 0, temp2 = 0;
 
-    AnalogIn yp(PTB3);
-    AnalogIn ym(PTB2);
-    DigitalOut xp(PTB0);
-    DigitalOut xm(PTB1);
+    AnalogIn yp(PinYp);
+    AnalogIn ym(PinYm);
+    DigitalOut xp(PinXp);
+    DigitalOut xm(PinXm);
 
     xp = 1; // set positive side of x high
     xm = 0;
@@ -69,10 +73,10 @@
 // subroutine to read y values - has different pin functions ..
 int readX()
 {
-    DigitalOut yp(PTB3);
-    DigitalOut ym(PTB2);
-    AnalogIn xp(PTB0);
-    AnalogIn xm(PTB1);
+    DigitalOut yp(PinYp);
+    DigitalOut ym(PinYm);
+    AnalogIn xp(PinXp);
+    AnalogIn xm(PinXm);
     int delta = 0, yv1 = 0, yv2 = 0, k = 0;
     int temp1 = 0, temp2 = 0;
     yp = 1; // set positive sdie of x high
@@ -93,7 +97,7 @@
     //pc.printf("yval=%d",yval);
     yp = 0;
     ym = 0;
-    return (320 - (320 * ((yv2) / 1 / 10 - 3000)) / 58300);   // returns Y
+    return ((320 * ((yv2) / 1 / 10 - 3000)) / 58300);   // returns X
 //    return(yval);
 
 }
--- a/settings.h	Thu May 25 13:24:26 2017 +0000
+++ b/settings.h	Thu May 25 15:32:20 2017 +0000
@@ -129,11 +129,15 @@
     int o_setting = 11;
     drawsettingback();
     int option = 0;
+    float tsi_current, tsi_last;
     while (true){
         drawsettinganimate(a_h, a_m,t_h,t_m,t_d,t_mo,t_y);
         option = setting_press();
         int newval = 0;
-        if (option == 0 || option == 2) break;
+        if (option == 0 || option == 2) {
+            pc.printf("exiting");
+            break;
+        }
         switch (option) {
             case (11):
                 o_setting = 11;
@@ -157,9 +161,19 @@
                 o_setting = 17;
                 break; //
         }
+        
+        tsi_current = tsi.readPercentage();
+        float change = 0;
+    
+        if (tsi_current != 0 && tsi_last != 0) {change = tsi_current - tsi_last;}
+        else {change = 0;}
+        tsi_last = tsi_current;
+        int delta = change * multiplier;
+        pc.printf("change in slider:%f, change in total:%f",change,delta);
         switch (o_setting) {
             case(11):
-                newval = a_h + tsi_d() * multiplier;
+                
+                newval = a_h + delta ;
                 while (newval < 0) {
                     newval += 24;
                 }
@@ -171,7 +185,7 @@
                 TFT.printf("%d", a_h);//Alarm_Hour
                 break;
             case(12):
-                newval = a_m + tsi_d() * multiplier;
+                newval = a_m + delta ;
                 while (newval < 0) {
                     newval += 60;
                 }
@@ -183,7 +197,7 @@
                 TFT.printf("%d", a_m);//Alarm_Min
                 break;
             case(13):   //set time hour
-                newval = t_h + tsi_d() * multiplier;
+                newval = t_h + delta ;
                 if (newval < 0) newval += 24;
                 t_h = newval % 25;
                 TFT.fillrect(90, 140, 150, 180, Black);
@@ -193,7 +207,7 @@
                 TFT.printf("%d",t_h); // Time_hour
                 break;
             case(14): //set time min
-                newval = t_m + tsi_d() * multiplier;
+                newval = t_m + delta ;
                 if (newval < 0) newval += 60;
                 t_m = newval % 60;
                 TFT.fillrect(200, 140, 300, 180, Black);
@@ -203,8 +217,8 @@
                 TFT.printf("%d",t_m);//Time Min
                 break;
             case(15): // set time date
-                newval = t_d + tsi_d() * multiplier;
-                if (newval < 0) newval += 31;
+                newval = t_d + delta ;
+                if (newval < 1) newval += 31;
                 t_d = newval % 32;
                 TFT.fillrect(55, 202, 148, 238, Black);
                 TFT.foreground(Red);
@@ -213,9 +227,10 @@
                 TFT.printf("%d",t_d); //print date
                 break;
             case(16): // set time month
-                newval = a_h + tsi_d() * multiplier;
-                if (newval < 0) newval += 12;
-                a_h = newval % 13;
+                newval = t_mo + delta ;
+                if (newval < 1) newval += 12;
+                t_mo = newval % 13 ;
+                
                 TFT.fillrect(148, 202, 263, 238, Black);
                 TFT.foreground(Red);
                 TFT.set_font((unsigned char*) Arial12x12);
@@ -223,8 +238,8 @@
                 TFT.printf("%d",t_mo); //print month
                 break;
             case(17): //set time year
-                newval = a_h + tsi_d() * multiplier;
-                if (newval > 1970 && newval < 2700) a_h = newval;
+                newval = t_y + delta ;
+                if (newval > 1970 && newval < 2700) t_y = newval;
                 TFT.fillrect(263, 202, 310, 238, Black);
                 TFT.foreground(Red);
                 TFT.set_font((unsigned char*) Arial12x12);
--- a/slider.h	Thu May 25 13:24:26 2017 +0000
+++ b/slider.h	Thu May 25 15:32:20 2017 +0000
@@ -9,14 +9,16 @@
 #error TARGET NOT DEFINED
 #endif
 float tsi_current, tsi_last = 0;
-
+TSIAnalogSlider tsi(PTB16, PTB17, 40);
 float tsi_d()
 {
-    TSIAnalogSlider tsi(ELEC0, ELEC1, 40);
+    //wait(0.5);
     tsi_current = tsi.readPercentage();
     float delta = 0;
+    
     if (tsi_current != 0 && tsi_last != 0) delta = tsi_current - tsi_last;
     else delta = 0;
     tsi_last = tsi_current;
+    pc.printf("%f\n\r",tsi_current);
     return delta;
 }