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)
Committer:
scat6490
Date:
Tue May 23 15:50:45 2017 +0000
Revision:
3:6a328c7e9b1c
Parent:
2:21c4f254786f
Child:
4:2013f3158cc6
Tuesday 5pm (to delete)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scat6490 0:4fd6c8718206 1
scat6490 0:4fd6c8718206 2 #include "stdio.h"
scat6490 0:4fd6c8718206 3 #include "mbed.h"
scat6490 0:4fd6c8718206 4 #include "SPI_TFT_ILI9341.h"
scat6490 0:4fd6c8718206 5 #include "string"
scat6490 0:4fd6c8718206 6 #include "Arial12x12.h"
scat6490 0:4fd6c8718206 7 #include "Arial24x23.h"
scat6490 0:4fd6c8718206 8 #include "Arial28x28.h"
scat6490 0:4fd6c8718206 9 #include "font_big.h"
scat6490 0:4fd6c8718206 10
scat6490 1:a33f6ca5a5b3 11 Ticker timer;
scat6490 1:a33f6ca5a5b3 12 DigitalOut output_high1(PTA4);
scat6490 1:a33f6ca5a5b3 13 DigitalOut output_high60(PTC8);
scat6490 2:21c4f254786f 14 DigitalOut buzzer(PTA12);
scat6490 3:6a328c7e9b1c 15 DigitalOut output_time_change(PTA2);
scat6490 1:a33f6ca5a5b3 16 DigitalIn input1(PTA5);
scat6490 1:a33f6ca5a5b3 17 DigitalIn input60(PTC9);
scat6490 3:6a328c7e9b1c 18 DigitalIn input_time_change(PTC2);
scat6490 1:a33f6ca5a5b3 19 Serial pc(USBTX,USBRX);
scat6490 0:4fd6c8718206 20 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
scat6490 0:4fd6c8718206 21
scat6490 3:6a328c7e9b1c 22 int clock_minutes, clock_hours = 0;
scat6490 3:6a328c7e9b1c 23 int alarm_hours = 7;
scat6490 3:6a328c7e9b1c 24 int alarm_minutes = 0;
scat6490 1:a33f6ca5a5b3 25
scat6490 1:a33f6ca5a5b3 26 void timeup(){
scat6490 3:6a328c7e9b1c 27 clock_minutes = (clock_minutes + 1) % 60;
scat6490 3:6a328c7e9b1c 28 if (clock_minutes==0) (clock_hours++) % 24;
scat6490 1:a33f6ca5a5b3 29 }
scat6490 1:a33f6ca5a5b3 30
scat6490 0:4fd6c8718206 31 int main()
scat6490 0:4fd6c8718206 32 {
scat6490 0:4fd6c8718206 33 //pc.baud(115200);
scat6490 0:4fd6c8718206 34 wait(0.2);
scat6490 3:6a328c7e9b1c 35
scat6490 0:4fd6c8718206 36 TFT.set_orientation(1); // Make it horizontal
scat6490 0:4fd6c8718206 37 TFT.background(Red); // Set background to black
scat6490 0:4fd6c8718206 38 TFT.foreground(White); // Set text to white
scat6490 0:4fd6c8718206 39 TFT.cls(); // Clear screen
scat6490 0:4fd6c8718206 40 TFT.set_font((unsigned char*) Arial12x12); // Set the font
scat6490 0:4fd6c8718206 41
scat6490 0:4fd6c8718206 42 TFT.fillrect(0, 0, 320, 30, Red);
scat6490 0:4fd6c8718206 43 TFT.printf("Clock by Duncan and Kieran");
scat6490 0:4fd6c8718206 44
scat6490 0:4fd6c8718206 45 wait(0.1);
scat6490 0:4fd6c8718206 46
scat6490 0:4fd6c8718206 47 TFT.background(Black); // Set background to black
scat6490 0:4fd6c8718206 48 TFT.set_font((unsigned char*) Arial28x28); // Set the font
scat6490 1:a33f6ca5a5b3 49
scat6490 3:6a328c7e9b1c 50 output_time_change = 1;
scat6490 1:a33f6ca5a5b3 51 output_high1 = 1;
scat6490 1:a33f6ca5a5b3 52 output_high60 = 1;
scat6490 1:a33f6ca5a5b3 53 timer.attach(&timeup, 1);
scat6490 1:a33f6ca5a5b3 54
scat6490 3:6a328c7e9b1c 55 while(1) {
scat6490 3:6a328c7e9b1c 56 if (input_time_change == 1)
scat6490 3:6a328c7e9b1c 57 {
scat6490 3:6a328c7e9b1c 58 switch(input1){
scat6490 3:6a328c7e9b1c 59 case 1:
scat6490 3:6a328c7e9b1c 60 clock_minutes = (clock_minutes++) % 60;
scat6490 3:6a328c7e9b1c 61 wait(0.2);
scat6490 3:6a328c7e9b1c 62 break;
scat6490 3:6a328c7e9b1c 63 case 0:
scat6490 3:6a328c7e9b1c 64 break;
scat6490 3:6a328c7e9b1c 65 }
scat6490 3:6a328c7e9b1c 66 switch(input60){
scat6490 3:6a328c7e9b1c 67 case 1:
scat6490 3:6a328c7e9b1c 68 clock_hours = clock_hours++;
scat6490 3:6a328c7e9b1c 69 wait(0.2);
scat6490 3:6a328c7e9b1c 70 break;
scat6490 3:6a328c7e9b1c 71 case 0:
scat6490 3:6a328c7e9b1c 72 break;
scat6490 3:6a328c7e9b1c 73 }
scat6490 3:6a328c7e9b1c 74 } else
scat6490 3:6a328c7e9b1c 75 {
scat6490 3:6a328c7e9b1c 76 switch(input1){
scat6490 3:6a328c7e9b1c 77 case 1:
scat6490 3:6a328c7e9b1c 78 alarm_minutes = (alarm_minutes++) % 60;
scat6490 3:6a328c7e9b1c 79 wait(0.2);
scat6490 3:6a328c7e9b1c 80 break;
scat6490 3:6a328c7e9b1c 81 case 0:
scat6490 3:6a328c7e9b1c 82 break;
scat6490 3:6a328c7e9b1c 83 }
scat6490 3:6a328c7e9b1c 84 switch(input60){
scat6490 3:6a328c7e9b1c 85 case 1:
scat6490 3:6a328c7e9b1c 86 alarm_hours = alarm_hours++;
scat6490 3:6a328c7e9b1c 87 wait(0.2);
scat6490 3:6a328c7e9b1c 88 break;
scat6490 3:6a328c7e9b1c 89 case 0:
scat6490 3:6a328c7e9b1c 90 break;
scat6490 3:6a328c7e9b1c 91 }
scat6490 1:a33f6ca5a5b3 92 }
scat6490 1:a33f6ca5a5b3 93
scat6490 3:6a328c7e9b1c 94 if (clock_hours == alarm_hours && clock_minutes == alarm_minutes)
scat6490 2:21c4f254786f 95 {
scat6490 2:21c4f254786f 96 buzzer = 1;
scat6490 2:21c4f254786f 97 } else
scat6490 2:21c4f254786f 98 {
scat6490 2:21c4f254786f 99 buzzer = 0;
scat6490 2:21c4f254786f 100 }
scat6490 1:a33f6ca5a5b3 101
scat6490 3:6a328c7e9b1c 102 clock_hours %= 24;
scat6490 3:6a328c7e9b1c 103 alarm_hours %= 24;
scat6490 3:6a328c7e9b1c 104
scat6490 1:a33f6ca5a5b3 105 TFT.locate(50, 50);
scat6490 3:6a328c7e9b1c 106 TFT.printf("Time: %d:%d ", clock_hours, clock_minutes);
scat6490 3:6a328c7e9b1c 107
scat6490 3:6a328c7e9b1c 108 TFT.locate(50, 100);
scat6490 3:6a328c7e9b1c 109 TFT.printf("Alarm: %d:%d ", alarm_hours, alarm_minutes);
scat6490 3:6a328c7e9b1c 110
scat6490 3:6a328c7e9b1c 111 TFT.locate(50, 150);
scat6490 3:6a328c7e9b1c 112 TFT.printf("%d ", (int) input_time_change);
scat6490 0:4fd6c8718206 113 }
scat6490 0:4fd6c8718206 114
scat6490 0:4fd6c8718206 115 }