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:
Fri May 26 09:15:06 2017 +0000
Parent:
5:f5fa116b57a1
Child:
7:007d23438920
Commit message:
Working clock, with everything, Friday 10:13pm

Changed in this revision

MMA8451Q.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Fri May 26 09:15:06 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- a/main.cpp	Wed May 24 14:57:37 2017 +0000
+++ b/main.cpp	Fri May 26 09:15:06 2017 +0000
@@ -1,4 +1,4 @@
-#include "stdio.h"
+#include "stdio.h" // Import libraries to use
 #include "mbed.h"
 #include "SPI_TFT_ILI9341.h"
 #include "string"
@@ -7,17 +7,17 @@
 #include "Arial28x28.h"
 #include "font_big.h"
 
-Ticker timer; // Set up a timer
-DigitalOut buzzer(PTA12); // Set up inputs and outputs
-DigitalIn input1(PTA4); // Input for the minute button
+Ticker timer; // Set up a timer                         
+DigitalOut buzzer(PTE30); // Set up inputs and outputs
+DigitalIn input1(PTA5); // Input for the minute button
 DigitalIn input60(PTC8); // Input for the hour button
 DigitalIn input_time_change(PTC9); // Input for the button which switches from changing the alarm and changing the time
 Serial pc(USBTX,USBRX); // Connection to the desktop, currently only used for debugging
 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
 
 int clock_minutes, clock_hours, clock_seconds = 0; // Initialise clock at 00:00.00
-int alarm_hours = 7; // Initialise alarm at 7am
-int alarm_minutes = 0;
+int alarm_hours = 7; // Initialise alarm hours as 07
+int alarm_minutes = 0; // Initialise alarm minutes as 00 so alarm is 07:00
 
 void timeup(){ // Function to increment the clock every second
     clock_seconds++; // Increment the time
@@ -31,7 +31,7 @@
     if (clock_minutes==0 && clock_seconds==0) 
     {
         clock_hours++; // Add an hour if the minutes got reset
-        clock_hours %= 24; // Reset the hour to 0 if it gets to 24
+        clock_hours %= 24; // Reset the hour to 0 if it gets to 24` 
     }
 }
 
@@ -54,7 +54,7 @@
     secondY = floor(0.85 * circleRadius * cos((double) (clock_seconds * factorS))); // Same for Y of second hand
     
     TFT.fillcircle(circleX, circleY, circleRadius, Red); // Draws a red circle
-    TFT.circle(circleX, circleY, circleRadius, White); // Draws a red circle
+    TFT.circle(circleX, circleY, circleRadius, White); // Draws a white circle around the red circle
     TFT.line(circleX, circleY, circleX + hourX, circleY - hourY, White); // Draws the hour hand
     TFT.line(circleX, circleY, circleX + minuteX, circleY - minuteY, White); // Draws the minute hand
     TFT.line(circleX, circleY, circleX + secondX, circleY - secondY, Black); // Draws the minute hand
@@ -72,7 +72,7 @@
 {
     wait(0.2); // Just wait for set up
      
-    TFT.set_orientation(1); // Make the display horizontal
+    TFT.set_orientation(3); // Make the display horizontal
     TFT.background(Black); // Set background to black
     TFT.foreground(White); // Set text to white
     TFT.cls(); // Clear screen
@@ -88,7 +88,7 @@
     timer.attach(&timeup, 1); // Set up the timer so it increments every second
     
     while(1) {
-        if (input_time_change) // Check if the toggle switch is pressed to change which time the other buttons adjust (pressed changes the time, unpressed changes the alarm)
+        if (!input_time_change) // Check if the toggle switch is pressed to change which time the other buttons adjust (pressed changes the time, unpressed changes the alarm)
         {
             switch(input1){ // Check if the minute button is pressed
                 case 1:
@@ -129,7 +129,7 @@
                     break;
             }
         }
-        
+
         if (clock_hours == alarm_hours && clock_minutes == alarm_minutes && (clock_seconds % 2) == 0) // Check if the time is equal to the alarm time, and the seconds is even
         {
             buzzer = 1; // Buzz
@@ -139,9 +139,10 @@
             buzzer = 0; // Don't buzz  
         }
         
+        TFT.foreground(White); // Set text to white
         TFT.locate(30, 70); // Move the text location
         TFT.printf("Time: %02d:%02d.%02d", clock_hours, clock_minutes, clock_seconds); // Write the time to the TFT
-        
+
         TFT.locate(30, 120); // Move the text location
         TFT.printf("Alarm: %02d:%02d", alarm_hours, alarm_minutes); // Write the alarm time to the TFT
         
--- a/mbed.bld	Wed May 24 14:57:37 2017 +0000
+++ b/mbed.bld	Fri May 26 09:15:06 2017 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/4eea097334d6
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/2241e3a39974
\ No newline at end of file