Final version, with changing analogue clock colours, Friday 11:20am

Dependencies:   MMA8451Q SPI_TFT_ILI9341 TFT_fonts mbed

Smart clock by Duncan and Kieran

Photo

http://www.imgur.com/SiyOshx.jpg

Equipment

  • PCB: FRDM-KL25Z
  • TFT Color Display: MI0283QT-9A
  • Buzzer
  • 3 x buttons
  • 3 x 2kΩ resistors and 1 x 100Ω resistor
  • Stripboard
  • Wires (stranded is preferable due to their flexibility)
  • USB to Mini-USB cable, and computer

Setup

PCB to TFT (Output)

FRDM-KL25ZMI0283QT-9A
P3V33.3V, IM1, IM2, IM3
GNDRD, IM0, LEDK
PTD5CS
PTD1RS
PTD0RST
PTD2SDI
PTD3SDO
PTA13WR
P5V_USB through 100Ω resistor (approx. 20mA)LEDA

The buzzer should be connected between PTA12 and ground.

Note: The resistance between P5V_USB and LEDA can be reduced to increase the brightness of the screen. However, resistors lower than 30Ω have not been tested, and may result in the current causing damage to the PCB.

PCB to Buttons (Inputs)

FRDM-KL25ZInput
PTA5Minute button
PTC8Hour button
PTC9Time change button - toggles between changing the alarm time and the clock time

Each button should be connected in series with a 2kΩ resistor between 3.3V and 0V, so that pressing the button switches between these two voltages.

Features

  • A digital clock, displayed in 24-hour format
  • An analogue clock, displaying the time in standard 12-hour format
  • Alarm can be changed using the minute and hour buttons
  • Time can be changed by holding the third button
  • Alarm will sound for one minute at the displayed time
  • Putting the alarm on its side will snooze the alarm if the alarm is going off (or just disable it if the alarm is not sounding)

Files at this revision

API Documentation at this revision

Comitter:
scat6490
Date:
Tue May 23 15:50:45 2017 +0000
Parent:
2:21c4f254786f
Child:
4:2013f3158cc6
Commit message:
Tuesday 5pm (to delete)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue May 23 15:05:29 2017 +0000
+++ b/main.cpp	Tue May 23 15:50:45 2017 +0000
@@ -12,24 +12,27 @@
 DigitalOut output_high1(PTA4);
 DigitalOut output_high60(PTC8);
 DigitalOut buzzer(PTA12);
+DigitalOut output_time_change(PTA2);
 DigitalIn input1(PTA5);
 DigitalIn input60(PTC9);
+DigitalIn input_time_change(PTC2);
 Serial pc(USBTX,USBRX);
 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
 
-int minutes = 0;
-int hours = 0;
+int clock_minutes, clock_hours = 0;
+int alarm_hours = 7;
+int alarm_minutes = 0;
 
 void timeup(){
-    minutes = (minutes + 1)%60;
-    if(minutes==0) (hours++)%24;
+    clock_minutes = (clock_minutes + 1) % 60;
+    if (clock_minutes==0) (clock_hours++) % 24;
 }
 
 int main()
 {
     //pc.baud(115200);
     wait(0.2);
-    
+     
     TFT.set_orientation(1);   // Make it horizontal
     TFT.background(Red);    // Set background to black
     TFT.foreground(White);    // Set text to white
@@ -44,32 +47,51 @@
     TFT.background(Black);    // Set background to black
     TFT.set_font((unsigned char*) Arial28x28); // Set the font
     
+    output_time_change = 1;
     output_high1 = 1;
     output_high60 = 1;
     timer.attach(&timeup, 1);
     
-    while(1) { 
-        switch(input1){
-            case 1:
-                minutes = (minutes++)%60;
-                wait(0.2);
-                break;
-            case 0:
-                break;
-            
+    while(1) {
+        if (input_time_change == 1)
+        {
+            switch(input1){
+                case 1:
+                    clock_minutes = (clock_minutes++) % 60;
+                    wait(0.2);
+                 break;
+                case 0:
+                 break;
+            }
+            switch(input60){
+                case 1:
+                    clock_hours = clock_hours++;
+                    wait(0.2);
+                    break;
+                case 0:
+                    break;
+            }
+        } else
+        {
+            switch(input1){
+                case 1:
+                    alarm_minutes = (alarm_minutes++) % 60;
+                    wait(0.2);
+                    break;
+                case 0:
+                    break;
+            }
+            switch(input60){
+                case 1:
+                    alarm_hours = alarm_hours++;
+                    wait(0.2);
+                    break;
+                case 0:
+                    break;
+            }
         }
         
-        
-        switch(input60){
-           case 1:
-              hours=hours++;
-               wait(0.2);
-                break;
-            case 0:
-                break;
-        }
-        
-        if (hours == 9 && minutes == 0)
+        if (clock_hours == alarm_hours && clock_minutes == alarm_minutes)
         {
             buzzer = 1;
         } else
@@ -77,8 +99,17 @@
             buzzer = 0;    
         }
         
+        clock_hours %= 24;
+        alarm_hours %= 24;
+        
         TFT.locate(50, 50);
-        TFT.printf("%d:%d ",hours,minutes);
+        TFT.printf("Time: %d:%d ", clock_hours, clock_minutes);
+        
+        TFT.locate(50, 100);
+        TFT.printf("Alarm: %d:%d ", alarm_hours, alarm_minutes);
+        
+        TFT.locate(50, 150);
+        TFT.printf("%d ", (int) input_time_change);
     }
 
 }