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
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-KL25Z | MI0283QT-9A |
---|---|
P3V3 | 3.3V, IM1, IM2, IM3 |
GND | RD, IM0, LEDK |
PTD5 | CS |
PTD1 | RS |
PTD0 | RST |
PTD2 | SDI |
PTD3 | SDO |
PTA13 | WR |
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-KL25Z | Input |
---|---|
PTA5 | Minute button |
PTC8 | Hour button |
PTC9 | Time 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)
Revision 9:d34cdff0205c, committed 2017-05-26
- Comitter:
- scat6490
- Date:
- Fri May 26 10:20:25 2017 +0000
- Parent:
- 8:6bd70a8697f4
- Commit message:
- Final version, with changing analogue clock colours, Friday 11:20am
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri May 26 10:03:27 2017 +0000 +++ b/main.cpp Fri May 26 10:20:25 2017 +0000 @@ -21,7 +21,7 @@ int clock_minutes, clock_hours, clock_seconds = 0; // Initialise clock at 00:00.00 int alarm_hours = 7; // Initialise alarm hours as 07 int alarm_minutes = 0; // Initialise alarm minutes as 00 so alarm is 07:00 -int previous_state; // Initialise the previous state variable to detect changing rotation +int previous_state, enable; // Initialise the previous state and enable variables to detect changing rotation void timeup(){ // Function to increment the clock every second clock_seconds++; // Increment the time @@ -57,18 +57,36 @@ secondX = floor(0.85 * circleRadius * sin((double) (clock_seconds * factorS))); // Same for X of second hand 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 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 - - for (int i = 0; i < 12; i++) + if (enable) // Checks if the alarm is enabled { - int timeX = floor(circleRadius * sin((double) (i * factorH))); // Calculate the X for the hour indicators around the edge - int timeY = floor(circleRadius * cos((double) (i * factorH))); // Same for Y of the hour indicators + TFT.fillcircle(circleX, circleY, circleRadius, Green); // Draws a green circle + TFT.circle(circleX, circleY, circleRadius, Black); // Draws a white circle around the red circle + TFT.line(circleX, circleY, circleX + hourX, circleY - hourY, Black); // Draws the hour hand + TFT.line(circleX, circleY, circleX + minuteX, circleY - minuteY, Black); // Draws the minute hand + TFT.line(circleX, circleY, circleX + secondX, circleY - secondY, White); // Draws the second hand + + for (int i = 0; i < 12; i++) + { + int timeX = floor(circleRadius * sin((double) (i * factorH))); // Calculate the X for the hour indicators around the edge + int timeY = floor(circleRadius * cos((double) (i * factorH))); // Same for Y of the hour indicators - TFT.line(circleX + 0.8 * timeX, circleY - 0.8 * timeY, circleX + timeX, circleY - timeY, White); // Draws the hour indicators + TFT.line(circleX + 0.8 * timeX, circleY - 0.8 * timeY, circleX + timeX, circleY - timeY, Black); // Draws the hour indicators + } + } else + { + TFT.fillcircle(circleX, circleY, circleRadius, Red); // 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 second hand + + for (int i = 0; i < 12; i++) + { + int timeX = floor(circleRadius * sin((double) (i * factorH))); // Calculate the X for the hour indicators around the edge + int timeY = floor(circleRadius * cos((double) (i * factorH))); // Same for Y of the hour indicators + + TFT.line(circleX + 0.8 * timeX, circleY - 0.8 * timeY, circleX + timeX, circleY - timeY, White); // Draws the hour indicators + } } } @@ -139,7 +157,7 @@ } float x = acc.getAccX(); // Check the x-orientation - int enable = 1; // Initialise the enable variable + enable = 1; // Initialise the enable variable if (x < 0.5){ // Check if the clock is tilted enable = 0; // Disable the alarm