---
title: "Digital clock state diagram"
subject: "Object Oriented Analysis and Design"
chapter: 2
key: "semester_6/object_oriented_analysis_and_design:digital-clock-state-diagram"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/digital-clock-state-diagram
site: BCT Engineering
---

# Digital clock state diagram

Object Oriented Analysis and Design · Chapter 2: Object Oriented Analysis

- Asked in: 2069 Bhadra, 10 marks
- Video: [1.3.7 – UML State Diagram - Object-Oriented Design](https://www.youtube.com/watch?v=qICdYjJA-Ps) — Le Hoang Ha
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/digital-clock-state-diagram
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-2

## Question

A new digital clock, recently available in the market, simultaneously displays the time and date. The time and date displays can be adjusted by the buttons available within the unit. The clock has two buttons, "mode" and "forward". If you wish to change the time you should first press the mode button, after which the time may be changed by the forward-button. If the mode button is pressed again, you can change the date (by the forward-button). If the mode button is pressed once again, you will go back to normal state. When the forward-button is pressed, the display will go a single unit (seconds or days) ahead. If the button is held down for more than two seconds, the display will change rapidly (once in every 0.2 second) ahead so long as the button is pressed.
Draw a state diagram for this clock control unit.

## Short answer

The clock has three states: Normal (display time/date), Set Time (adjust seconds), Set Date (adjust days). Mode button cycles Normal→Set Time→Set Date→Normal. Forward button increments by one unit; held >2s enters fast mode incrementing every 0.2s. Substates: Idle, Pressed, Fast with transitions on press, release, and after(2s).

## Answer

**Assumptions:** the clock has three modes: *Normal* (displays time and date, running), *Set Time* and *Set Date*. Events: `mode` and `forward` button presses, `forward` held for more than 2 s, and `forward` released. In Set Time one unit is one second; in Set Date one unit is one day.

#### State diagram

```text
  (*)
   |
   v
 +----------------------+
 |        Normal        |<--------------+
 | do/ run clock,       |               |
 |  display time, date  |               |
 +----------------------+               |
   |                                    |
  mode                                  |
   v                                    |
 +----------------------+               |
 |       Set Time       |               |
 | entry/ blink time    |               |
 | forward: +1 second   |               |
 +----------------------+               |
   |                                    |
  mode                                  |
   v                                    |
 +----------------------+     mode      |
 |       Set Date       |---------------+
 | entry/ blink date    |
 | forward: +1 day      |
 +----------------------+
```

The `mode` button cycles the states: Normal --mode--> Set Time --mode--> Set Date --mode--> Normal.

#### Substates for the forward button (inside Set Time and Set Date)

```text
 +----------------------------------------------------+
 |  (*)                                               |
 |   |                                                |
 |   v     forward pressed / +1 unit                  |
 |  Idle ----------------------------> Pressed        |
 |   ^  ^                                |            |
 |   |  +------- forward released -------+            |
 |   |                                   | after(2 s) |
 |   |                                   v            |
 |   +-------- forward released ------- Fast          |
 |                         do/ +1 unit every 0.2 s    |
 +----------------------------------------------------+
```

#### Transition table

| From | Event | To | Action |
|---|---|---|---|
| Normal | mode | Set Time | blink the time display |
| Set Time: Idle | forward pressed | Set Time: Pressed | time + 1 second |
| Pressed | after(2 s) while still pressed | Fast | none |
| Fast | every 0.2 s | Fast | time + 1 second |
| Pressed or Fast | forward released | Idle | stop incrementing |
| Set Time | mode | Set Date | blink the date display |
| Set Date | forward pressed / held | Set Date (same substates) | date + 1 day |
| Set Date | mode | Normal | resume the normal display |

The held-down behaviour is triggered by the time event `after(2 s)`, and the repeated increment is timed with `every(0.2 s)`.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the mode-button cycle in the state diagram?
   A. Normal to Set Time to Set Date to Normal
   B. Normal to Set Date to Set Time to Normal
   C. Set Time to Normal only
   D. Normal to Normal
   Answer: A. Each mode press moves to the next state; the third returns to Normal. (Key point: State cycle)

2. What happens when forward is held down for more than two seconds in Set Time?
   A. The display goes ahead once and stops
   B. It goes into a Fast substate, incrementing every 0.2 s while pressed
   C. The clock returns to Normal
   D. The date is set
   Answer: B. A single press increments one unit; holding more than 2 s repeats every 0.2 s until released. (Key point: Forward button substates)

3. What does releasing the forward button do?
   A. Moves to Set Date
   B. Stops the repeating and returns to the Idle substate
   C. Resets the time to 00:00
   D. Exits to Normal
   Answer: B. The forward released event returns to Idle and stops repeating. (Key point: Releasing button)

4. Which notations express the hold timing?
   A. after(2 s) guard and every(0.2 s) repeated increment
   B. entry/ and exit/ only
   C. never(2 s)
   D. {disjoint}
   Answer: A. after(2 s) triggers fast mode, and every(0.2 s) times the increments. (Key point: Timing notations)

## Related in Object Oriented Analysis and Design

- [Video rental shop class diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Avideo-rental-class-diagram) — Object Oriented Analysis and Design, chapter 2
- [Bottle recycling machine state diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Abottle-recycling-state-diagram) — Object Oriented Analysis and Design, chapter 2
- [Student course department class diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Astudent-course-diagram-type) — Object Oriented Analysis and Design, chapter 2
- [Math Training Institute use case diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Amath-training-institute-use-case) — Object Oriented Analysis and Design, chapter 2
- [Event management system summary and class diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aoems-executive-summary-class-diagram) — Object Oriented Analysis and Design, chapter 2
- [ATM withdrawal sequence diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aatm-withdrawal-sequence-diagram) — Object Oriented Analysis and Design, chapter 2

## Related in other subjects

- [Seconds section of a digital clock](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Adigital-clock-seconds-section) — Digital Logic, chapter 8
- [Operation of a digital clock](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Adigital-clock-operation) — Digital Logic, chapter 8
- [JavaScript DOM and date-time function](https://www.bctengineer.com/question.md?key=semester_7%2Fweb_technology%3Ajavascript-dom-date-time) — Web Technology, chapter 4
- [8255 mode 2 operation with timing diagram](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Appi-mode2) — Instrumentation II, chapter 2
