# Digital Clock with CircuitPython

## Overview

https://youtu.be/C1xh4Bx-6-E

## Accurately Stylish

You can build a digital clock with a large 7-segment display, a Feather RP2040, and CircuitPython --&nbsp;no internet required! For time keeping, this build uses the DS3231 Real Time Clock module for precise and accurate timing.&nbsp;

## Easy Time Setting&nbsp;

A rotary encoder is used to set the time, making daylight savings time changes easy and intuitive. It also has an auto-dimming feature which lowers the display’s brightness during sleeping hours.

![leds_time-change.gif](https://cdn-learn.adafruit.com/assets/assets/000/127/657/medium640thumb/leds_time-change.jpg?1707839360)

## Elegantly&nbsp;Simple

The 3D printed enclosure design is inspired by mid-century modern aesthetics.&nbsp;The enclosure snap fits together and can be 3D printed without any support material.

![leds_hero-wood.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/656/medium640/leds_hero-wood.jpg?1707835846)

![](https://cdn-learn.adafruit.com/assets/assets/000/127/494/medium800/leds_hero-black.jpg?1707240897)

# Parts
### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
![Angled shot of black rectangular microcontroller "Feather RP2040"](https://cdn-shop.adafruit.com/640x480/4884-04.jpg)

### Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red

[Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red](https://www.adafruit.com/product/1270)
What's better than a single LED? Lots of LEDs! A fun way to make a numeric display is to use a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). LED matrices like these are 'multiplexed' - so to control all the seven-segment LEDs you need 14 pins....

Out of Stock
[Buy Now](https://www.adafruit.com/product/1270)
[Related Guides to the Product](https://learn.adafruit.com/products/1270/guides)
![Huge red 7-segment clock display soldered to backpack with all segments lit](https://cdn-shop.adafruit.com/640x480/1270-00.jpg)

### Adafruit DS3231 Precision RTC - STEMMA QT

[Adafruit DS3231 Precision RTC - STEMMA QT](https://www.adafruit.com/product/5188)
&nbsp;

The datasheet for the **DS3231** explains that this part is an "Extremely Accurate I²C-Integrated RTC/TCXO/Crystal". And, hey, it does exactly what it says on the tin! This **Real Time Clock (RTC)** is the most precise you can get in a...

In Stock
[Buy Now](https://www.adafruit.com/product/5188)
[Related Guides to the Product](https://learn.adafruit.com/products/5188/guides)
![Angled shot of RTC breakout.](https://cdn-shop.adafruit.com/640x480/5188-05.jpg)

### Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder

[Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder](https://www.adafruit.com/product/5880)
Rotary encoders are soooo much fun! Twist em this way, then twist them that way. Unlike potentiometers, they go all the way around and often have little detents for tactile feedback. But, if you've ever tried to add encoders to your project you know that they're a real challenge to...

In Stock
[Buy Now](https://www.adafruit.com/product/5880)
[Related Guides to the Product](https://learn.adafruit.com/products/5880/guides)
![Angled Shot of the I2C Stemma QT Rotary Encoder Breakout with Encoder.](https://cdn-shop.adafruit.com/640x480/5880-00.jpg)

### Part: STEMMA QT Cable
quantity: 3
JST SH 4-pin Cable - 100mm Long
[STEMMA QT Cable](https://www.adafruit.com/product/4210)

### Part: CR1220 12mm Diameter
quantity: 1
3V Lithium Coin Cell Battery - CR1220
[CR1220 12mm Diameter](https://www.adafruit.com/product/380)

### Part: USB-C Cable
quantity: 1
Pink and Purple Woven USB A to C - 2 meters long
[USB-C Cable](https://www.adafruit.com/product/5044)

## Hardware

The following hardware is required for the assembly.

- 6x M2.5 x 6mm long machine screws
- 4x M2 x 8mm long machine screws
- 4x M3 x 6mm long machine screws
- 4x M3 x 10mm long machine screws
- 4x M2 hex nuts
- 4x M3 hex nuts

# Optional
### Part: Light Diffuser Gel Overlays
quantity: 1
11.7 by 8.3 Inches colored sheets
[Light Diffuser Gel Overlays](https://www.amazon.com/Lystaii-Correction-Overlays-Transparent-Lighting/dp/B08NG8PLS3)

![](https://cdn-learn.adafruit.com/assets/assets/000/127/702/medium800/leds_hero-wood-bg.jpg?1707917499)

![](https://cdn-learn.adafruit.com/assets/assets/000/127/703/medium800/leds_hero-adabot-pink.jpg?1707917527)

![](https://cdn-learn.adafruit.com/assets/assets/000/127/704/medium800/leds_hero-white-bg.jpg?1707917536)

# Digital Clock with CircuitPython

## Circuit Diagram

The diagram below provides a general visual reference for wiring of the components once you get to the **Assembly** page. This diagram was created using the software package [Fritzing](http://fritzing.org/download/).

## Adafruit Library for Fritzing

Adafruit uses the Adafruit's Fritzing parts library to create circuit diagrams for projects. You can download the library or just grab individual parts. Get the library and parts from [GitHub - Adafruit Fritzing Parts](https://github.com/adafruit/Fritzing-Library/tree/master/parts).

![](https://cdn-learn.adafruit.com/assets/assets/000/127/482/medium800/leds_Circuit-Diagram-V1.jpg?1707158430)

## Wired Connections

- Feather connects to 1.2" LED Backpack via STEMMA QT.
- The DS3231 breakout connects to 1.2" LED Backpack via STEMMA QT
- The Rotary Encoder connects to DS3231 breakout via STEMMA QT

**USB Power**

The Feather RP2040 is powered with a 5V 1A USB power supply.

# Digital Clock with CircuitPython

## CAD Files

## 3D Printed Parts

STL files for 3D printing are oriented to print "as-is" on FDM style machines. Parts are designed to 3D print without any support material using PLA filament. Original design source may be downloaded using the links below.

![leds_3d-parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/635/medium640/leds_3d-parts.jpg?1707751088)

[Download STLs.zip](https://cdn-learn.adafruit.com/assets/assets/000/127/636/original/STLs.zip?1707751215)
[Download CAD source](https://cdn-learn.adafruit.com/assets/assets/000/127/637/original/CAD.zip?1707752989)
## CAD Assembly

The LED breakout is secured to the LED mount with M2 sized screws.

The LED mount is mounted to the casing using M3 sized screws.

The Feather RP2040 and DS3231 breakouts are secured to the PCB mount using M2.5 sized screws.

The rotary encoder is panel mounted to the left side of the casing.

The base legs are secured to the bottom of the casing with M3 sized screws.

The PCB mount is secured inside the casing using the screws from the base legs.

The back and front covers press fit into the casing.

![leds_CAD.gif](https://cdn-learn.adafruit.com/assets/assets/000/127/632/medium640thumb/leds_CAD.jpg?1707750589)

## Build Volume

The parts require a 3D printer with a minimum build volume.

- 140mm (X) x 66mm (Y) x 80mm (Z)

![leds_cura-slice.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/633/medium640/leds_cura-slice.jpg?1707750754)

## Design Source Files

The project assembly was designed in Fusion 360. This can be downloaded in different formats like STEP, STL and more.

Electronic components like Adafruit's boards, displays, connectors and more can be downloaded from the&nbsp;[Adafruit CAD parts GitHub Repo](https://github.com/adafruit/Adafruit_CAD_Parts/).

![leds_1271_1.2in_7_Segment_Backpack.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/634/medium640/leds_1271_1.2in_7_Segment_Backpack.jpg?1707751055)

# Digital Clock with CircuitPython

## Install CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_rp2040/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/102/705/medium800/adafruit_products_FeatherRP_buttons_highlighted.jpg?1623167565)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RPI-RP2**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **RPI-RP2.**

![install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/656/medium640/install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg?1618943666)

![install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/657/medium640/install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg?1618943674)

The **RPI-RP2** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/658/medium640/install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg?1618943864)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2](https://cdn-learn.adafruit.com/assets/assets/000/101/659/original/flash_nuke.uf2?1618945856)
# Digital Clock with CircuitPython

## Code the Clock

![](https://cdn-learn.adafruit.com/assets/assets/000/127/655/medium800/leds_code-banner.jpg?1707772957)

Once you've finished setting up your Feather RP2040 with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **Download Project Bundle** button in the window below. It will download to your computer as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Digital_Clock_with_CircuitPython/code.py

## Upload the Code and Libraries to the Feather RP2040

After downloading the Project Bundle, plug your Feather RP2040 into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called **CIRCUITPY**. Unzip the folder and copy the following items to the Feather RP2040's **CIRCUITPY** drive:

- **lib** folder
- **code.py**

Your Feather RP2040 **CIRCUITPY** drive should look like this after copying the **lib** folder and the **code.py** file.

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/Digital_Clock_with_CircuitPython.png )

## How the CircuitPython Code Works

At the top of the code are user configurable settings for the clock. The first two are for the brightness range. The `max_brightness` is the setting the clock will have during the day and `min_brightness` is the setting the clock will have overnight. The next settings are for the hours that trigger the brightness to change during the week and during the weekend. These hours are in 24-hour time.

```python
# min and max display brightness range
# value must be 0.0 to 1.0
max_brightness = 1
min_brightness = 0.01
# weekday hours to have clock on max brightness
# (24-hour time)
weekday_wakeup = 8
weekday_sleep = 21
# weekend hours to have clock on max brightness
# (24-hour time)
weekend_wakeup = 9
weekend_sleep = 23
```

## I2C

Next all of the breakouts are instantiated over I2C. The button on the rotary encoder is passed as a `Button` object to the **adafruit\_debouncer** library.

```python
i2c = board.STEMMA_I2C()

rtc = adafruit_ds3231.DS3231(i2c)
seesaw = seesaw.Seesaw(i2c, addr=0x36)
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
ss_pin = digitalio.DigitalIO(seesaw, 24)
button = Button(ss_pin, long_duration_ms=1000)

encoder = rotaryio.IncrementalEncoder(seesaw)
last_position = 0

display = segments.BigSeg7x4(i2c)
```

## Set the RTC

There is a bit of code that lets you initially set the RTC module. If you change the `if` statement to `True`, you can edit the `struct_time` object to match your current time and save the code to program the RTC.

Remember to change it back to `False` and resave it when done setting the time, otherwise if the board is reset or power cycled the time we be incorrectly set.

```python
if False:  # change to True if you want to set the time!
    #                     year, mon, date, hour, min, sec, wday, yday, isdst
    t = time.struct_time((2024, 1, 25, 15, 7, 0, 3, -1, -1))
    # you must set year, mon, date, hour, min, sec and weekday
    # yearday is not supported, isdst can be set but we don't do anything with it at this time
    print("Setting time to:", t)  # uncomment for debugging
    rtc.datetime = t
    print()
```

## Clock Conversion

There is a function called `clock_conversion` that takes care of converting the time from the RTC to 12-hour time for displaying on the 7-segment display. It also adjusts the display brightness.

```python
def clock_conversion(h, m, set_brightness):
    # pylint: disable-msg=simplifiable-if-expression
    am_pm = False if h &lt; 12 else True
    hour_12 = h if h &lt;= 12 else h - 12
    if hour_12 == 0:
        hour_12 = 12
    display.print(f"{(hour_12):02}:{m:02}")  # Use for leading zero re. 09:35
    # display.print(f"{hour_12:2}:{m:02}")   # uncomment to suppress leading zero
    #                                        #  (shows 1:00 instead of 01:00)
    display.ampm = am_pm
    if set_brightness:
        if awake_hours[0] &lt;= h &lt;= awake_hours[1] - 1:
            display.brightness = max_brightness
        elif h is awake_hours[0] - 1:
            bright = simpleio.map_range(m, 0, 59, min_brightness, max_brightness)
            display.brightness = bright
        elif h is awake_hours[1]:
            bright = simpleio.map_range(m, 0, 59, max_brightness, min_brightness)
            display.brightness = bright
        else:
            display.brightness = min_brightness
    else:
        display.brightness = max_brightness
```

Note the default behavior is to display a leading zero for times between 01:00 and 09:59. It you'd rather have a "space/blank" leading time, Comment the one line and uncomment out the others as shown below:

Default (leading zero):

```python
display.print(f"{(hour_12):02}:{m:02}")  # Use for leading zero re. 09:35
# display.print(f"{hour_12:2}:{m:02}")   # uncomment to suppress leading zero
```

Suppress leading zero:

```auto
# display.print(f"{(hour_12):02}:{m:02}")  # Use for leading zero re. 09:35
display.print(f"{hour_12:2}:{m:02}")   # uncomment to suppress leading zero
```

## The Loop

In the loop, `ticks` is used to check the RTC every second. When the minute advances, the `clock_conversion` function is called to update the display. The `awake_hours` (full brightness hours on the weekend versus weekdays) are also adjusted depending on the reading from the RTC.

```python
if clock_mode:
        button.update()
        if ticks_diff(ticks_ms(), clock_clock) &gt;= clock_timer:
            t = rtc.datetime
            if t.tm_wday in range(5, 6):
                awake_hours = [weekend_wakeup, weekend_sleep]
            else:
                awake_hours = [weekday_wakeup, weekday_sleep]
            if t.tm_sec &lt; 1 or power_up:
                power_up = False
                clock_conversion(t.tm_hour, t.tm_min, True)
            clock_clock = ticks_add(clock_clock, clock_timer)
```

## Set the Time

If a long press is read from the button on the encoder while in `clock_mode`, `clock_mode` is set to `False` and you are able to use the encoder to adjust the hour and minute settings. While in this mode, the display blinks. When you long press the button again, it updates the RTC with the hour and minute settings you've just entered with the encoder and goes back to `clock_mode`.

```python
else:
        button.update()
        position = -encoder.position
        if position != last_position:
            if position &gt; last_position:
                if set_hour:
                    hour = (hour + 1) % 24
                else:
                    minute = (minute + 1) % 60
            else:
                if set_hour:
                    hour = (hour - 1) % 24
                else:
                    minute = (minute - 1) % 60
            clock_conversion(hour, minute, False)
            last_position = position
        if button.short_count:
            set_hour = not set_hour
        # toggling dots with not did not seem to work consistantly
        # so setting manually
        if set_hour:
            display.top_left_dot = True
            display.bottom_left_dot = False
        else:
            display.top_left_dot = False
            display.bottom_left_dot = True
    if button.long_press:
        if not clock_mode:
            t = rtc.datetime
            new_t = time.struct_time((t.tm_year, t.tm_mon, t.tm_mday,
                                      hour, minute, t.tm_sec, t.tm_wday,
                                      t.tm_yday, t.tm_isdst))
            print("Setting time to:", new_t)
            rtc.datetime = new_t
            clock_clock = ticks_add(clock_clock, clock_timer)
            power_up = True
            display.top_left_dot = False
            display.bottom_left_dot = False
        else:
            set_hour = True
            t = rtc.datetime
            hour = t.tm_hour
            minute = t.tm_min
        clock_mode = not clock_mode
        display.blink_rate = not display.blink_rate
```

# Digital Clock with CircuitPython

## Wiring Assembly

## Parts

Gather up the electronics and cables.

![leds_parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/589/medium640/leds_parts.jpg?1707505630)

## Install LED Display

Insert the 1.2in LED 7-segment display onto the breakout in the correct orientation.

Solder all of the pins from the LED display to the breakout board.

Clip the long pins using flush diagonal snips.

Reference the full assembly on the [product learn guide](https://learn.adafruit.com/adafruit-led-backpack/1-2-inch-7-segment-backpack-assembly).

![leds_LED-breakout-soldered.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/590/medium640/leds_LED-breakout-soldered.jpg?1707505641)

![leds_led-breakout-parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/661/medium640/leds_led-breakout-parts.jpg?1707843154)

## Install Coin Cell Battery

Insert a fresh CR1220 coin cell into the coin cell holder with the positive side facing up.

![leds_DS3231-coincell.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/591/medium640/leds_DS3231-coincell.jpg?1707505653)

## Connect Components

Use the STEMMA QT cables to connect the electronics together.

- Connect the Feather RP2040 to the LED breakout
- Connect the DS3231 to the LED breakout
- Connect the Rotary Encoder to the DS3231

![leds_parts-connected.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/601/medium640/leds_parts-connected.jpg?1707505810)

## Mount for LED Breakout

Use the following hardware to secure the LED breakout to the mount.

- 4x M2 x 6mm&nbsp;
- 4x M2 hex nuts

Place the 3D printed mount over the LED breakout with the mounting holes lined up.

![leds_LED-breakout-mount-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/592/medium640/leds_LED-breakout-mount-screws.jpg?1707505671)

![leds_LED-breakout-mount-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/627/medium640/leds_LED-breakout-mount-install.jpg?1707507135)

## LED Breakout Mount

Use the M2 x 6mm long screws and hex nuts to secure the LED breakout to the 3D printed mount.

![leds_LED-breakout-mount-secure.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/593/medium640/leds_LED-breakout-mount-secure.jpg?1707505694)

![leds_LED-breakout-mount-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/594/medium640/leds_LED-breakout-mount-secured.jpg?1707505703)

## Install Feather to PCB Mount

Place the Feather RP2040 over the PCB mount with the mounting holes lined up.

![leds_feather-mount-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/595/medium640/leds_feather-mount-install.jpg?1707505719)

## Secure Feather

Use 4x M2.5 x 6mm long screws to secure the Feather RP2040 to the PCB mount.

![leds_feather-securing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/596/medium640/leds_feather-securing.jpg?1707505738)

![leds_feather-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/597/medium640/leds_feather-secured.jpg?1707505759)

## Install DS3231 to PCB mount

Place the DS3231 STEMMA QT breakout onto the PCB mount with the mounting holes lined up.

![leds_DS3231-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/598/medium640/leds_DS3231-install.jpg?1707505770)

## Secure DS3231

Use 2x M2.5 x 6mm long screws to secure the DS3231 breakout to the PCB mount.

![leds_DS3231-securing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/599/medium640/leds_DS3231-securing.jpg?1707505782)

![leds_DS3231-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/600/medium640/leds_DS3231-secured.jpg?1707505789)

## Mounted Components

Take a moment to inspect that the components have been secured to the 3D printed mounts.

![leds_parts-mounted-connected.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/602/medium640/leds_parts-mounted-connected.jpg?1707505859)

## Size & Cut Gel Filter (Optional)

Use scissors or a hobby knife and straight edge to cut a piece of the gel filter to fit over the 7-segment display.

Recommended Filter Size: 132mm(5.2in) x 50mm (1.9in)&nbsp;

![leds_cut-GelFilter.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/660/medium640/leds_cut-GelFilter.jpg?1707842753)

## Install LED Display Mount

Insert the LED display mount through the 3D printed enclosure.

Place the LED display mount over the built-in standoffs with mounting holes lined up.

![leds_LED-casing-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/603/medium640/leds_LED-casing-installing.jpg?1707505889)

![leds_LED-casing-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/605/medium640/leds_LED-casing-install.jpg?1707505927)

## Secure LED Display Mount

Insert and fasten 4x M3 x 6mm long screws to secure the LED display mount to the enclosure.

![leds_LED-casing-secure.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/606/medium640/leds_LED-casing-secure.jpg?1707505942)

![leds_LED-casing-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/607/medium640/leds_LED-casing-secured.jpg?1707505951)

## Secure Rotary Encoder

Remove the washer and hex nut from the rotary encoder.

Insert the rotary encoder through the hole on the side of the enclosure.

Use the washer and hex nut to secure the rotary encoder to the enclosure.

![leds_rotary-case-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/608/medium640/leds_rotary-case-installing.jpg?1707505978)

![leds_rotary-case-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/609/medium640/leds_rotary-case-secured.jpg?1707505987)

## Install Rotary Knob

Press fit the rotary knob onto the shaft of the rotary encoder.

![leds_rotary-knob-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/610/medium640/leds_rotary-knob-install.jpg?1707506002)

![leds_rotary-knob-installed.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/611/medium640/leds_rotary-knob-installed.jpg?1707506011)

## Install PCB Mount

Fit the PCB mount into the enclosure with the mounting holes lined up.

![leds_pcb-mount-casing-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/612/medium640/leds_pcb-mount-casing-install.jpg?1707506054)

## Install Base Legs

Place the 3D printed legs under the enclosure with the mounting holes lined up.

![leds_legs-casing-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/614/medium640/leds_legs-casing-install.jpg?1707506075)

## Secure Base Legs

Use 4x M3 x 10mm long screws to secure the base legs to the enclosure.

![leds_legs-casing-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/615/medium640/leds_legs-casing-installing.jpg?1707506090)

![leds_legs-casing-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/616/medium640/leds_legs-casing-secured.jpg?1707506100)

## Install Back Cover

Snap fit the back cover onto the back of the enclosure with the USB hole lined up with the Feather RP2040's USB port.

![leds_cover-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/617/medium640/leds_cover-installing.jpg?1707506115)

![leds_cover-installed.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/618/medium640/leds_cover-installed.jpg?1707506124)

## Install Gel Filter (optional)

Place the sized gel filter over the LED display.

![leds_gel-filter-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/619/medium640/leds_gel-filter-install.jpg?1707506171)

![leds_gel-filter-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/620/medium640/leds_gel-filter-installing.jpg?1707506179)

## Install Front Cover

Press fit the front cover over the front of the enclosure.

![leds_front-cover-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/621/medium640/leds_front-cover-install.jpg?1707506191)

![leds_front-cover-installed.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/622/medium640/leds_front-cover-installed.jpg?1707506200)

## USB Power

Plug in a USB-C cable to the Feather RP2040's USB Port.

![leds_USB-power.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/623/medium640/leds_USB-power.jpg?1707506213)

## Final Build

Congratulations on your build!

![leds_final-with-filter.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/625/medium640/leds_final-with-filter.jpg?1707506244)

![leds_final-no-filter.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/626/medium640/leds_final-no-filter.jpg?1707506286)

# Digital Clock with CircuitPython

## Usage

![](https://cdn-learn.adafruit.com/assets/assets/000/127/654/medium800thumb/leds_time-change.jpg?1707772787)

## Changing Time

1. Press and hold down rotary wheel until LED display blinks
2. Rotate rotary wheel to desired hour
3. Press and hold to save hour and switch to minutes
4. Rotate rotary wheel to desired minutes
5. Press and hold until LED display stops blinking to save time and exit


## Featured Products

### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
### Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red

[Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red](https://www.adafruit.com/product/1270)
What's better than a single LED? Lots of LEDs! A fun way to make a numeric display is to use a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). LED matrices like these are 'multiplexed' - so to control all the seven-segment LEDs you need 14 pins....

Out of Stock
[Buy Now](https://www.adafruit.com/product/1270)
[Related Guides to the Product](https://learn.adafruit.com/products/1270/guides)
### Adafruit DS3231 Precision RTC - STEMMA QT

[Adafruit DS3231 Precision RTC - STEMMA QT](https://www.adafruit.com/product/5188)
&nbsp;

The datasheet for the **DS3231** explains that this part is an "Extremely Accurate I²C-Integrated RTC/TCXO/Crystal". And, hey, it does exactly what it says on the tin! This **Real Time Clock (RTC)** is the most precise you can get in a...

In Stock
[Buy Now](https://www.adafruit.com/product/5188)
[Related Guides to the Product](https://learn.adafruit.com/products/5188/guides)
### Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder

[Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder](https://www.adafruit.com/product/5880)
Rotary encoders are soooo much fun! Twist em this way, then twist them that way. Unlike potentiometers, they go all the way around and often have little detents for tactile feedback. But, if you've ever tried to add encoders to your project you know that they're a real challenge to...

In Stock
[Buy Now](https://www.adafruit.com/product/5880)
[Related Guides to the Product](https://learn.adafruit.com/products/5880/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
### CR1220 12mm Diameter - 3V Lithium Coin Cell Battery

[CR1220 12mm Diameter - 3V Lithium Coin Cell Battery](https://www.adafruit.com/product/380)
These are the highest quality & capacity batteries, the same as shipped with the iCufflinks,&nbsp;iNecklace, Datalogging and GPS Shields, GPS HAT, etc. One battery per order (you'll want one battery per cufflink or pendant.)  
  
Brand may vary but all battery brands are verified...

In Stock
[Buy Now](https://www.adafruit.com/product/380)
[Related Guides to the Product](https://learn.adafruit.com/products/380/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [Introducing Adafruit Feather RP2040](https://learn.adafruit.com/adafruit-feather-rp2040-pico.md)
- [Adafruit I2C QT Rotary Encoder](https://learn.adafruit.com/adafruit-i2c-qt-rotary-encoder.md)
- [An Introduction to RP2040 PIO with CircuitPython](https://learn.adafruit.com/intro-to-rp2040-pio-with-circuitpython.md)
- [Discord and Slack Connected Smart Plant with Adafruit IO Actions](https://learn.adafruit.com/discord-and-slack-connected-smart-plant-with-adafruit-io-triggers.md)
- [Prop-Maker Feather Talking Adabot Clock](https://learn.adafruit.com/prop-maker-feather-talking-adabot-clock.md)
- [Adding a Real Time Clock to Raspberry Pi](https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi.md)
- [Walkmp3rson: Personal MP3 'Tape' Player](https://learn.adafruit.com/walkmp3rson-personal-mp3-tape-player.md)
- [Circle of Fifths Euclidean Synth with synthio and CircuitPython](https://learn.adafruit.com/circle-of-fifths-euclidean-synth-with-synthio-and-circuitpython.md)
- [Blahaj Alarm and Lamp](https://learn.adafruit.com/blahaj-alarm.md)
- [MIDI Controlled Robot Lyre with CircuitPython](https://learn.adafruit.com/midi-controlled-robot-lyre-with-circuitpython.md)
- [Adafruit Floppy FeatherWing with 34-Pin IDC Connector](https://learn.adafruit.com/adafruit-floppy-featherwing-with-34-pin-idc-connector.md)
- [CircuitPython Hardware: LED Backpacks & FeatherWings](https://learn.adafruit.com/micropython-hardware-led-backpacks-and-featherwings.md)
- [Disconnected CO2 Data Logger](https://learn.adafruit.com/disconnected-co2-data-logger.md)
- [3D Printed Frame for Adafruit IS31FL3741 LED Glasses](https://learn.adafruit.com/3d-printed-frame-for-led-glasses-is31fl3741.md)
- [Large Pi-based Thermometer and Clock](https://learn.adafruit.com/large-pi-based-thermometer-and-clock.md)
- [Hacking Holiday Animatronics](https://learn.adafruit.com/hacking-holiday-animatronics.md)
- [Raspberry Pi Physical Dashboard](https://learn.adafruit.com/raspberry-pi-physical-dashboard.md)
