# Moon Phase Clock for Adafruit Matrix Portal

## Overview

Danger: If you are using the Adafruit Matrix Portal **M4**, you must [update the firmware](https://learn.adafruit.com/upgrading-esp32-firmware/upgrade-all-in-one-esp32-airlift-firmware) on the AirLift co-processor on your board to version 3.0.0 or later. This is due to changes at the website the code uses for moon data. This is not an issue with the Matrix Portal S3.

![](https://cdn-learn.adafruit.com/assets/assets/000/094/887/medium800/led_matrices_banner-image.jpg?1600648581)

It’s hard work being a werewolf, and I don’t just mean cleaning blood stains out of the carpet or dealing with fleas in the house.

It’s this messy business of the full Moon.&nbsp;Most wall calendars and news sources, if they even mention Moon phases, there’s about a 50/50 chance that they’re **off by a full day** &nbsp;(explained on the “Moon Facts” page).&nbsp;You might be out at a fancy event wearing a rental tuxedo when things turn weird. There goes your deposit. So awkward.

The _only_ way to get a _correct_&nbsp;Moon phase for your time and location is with **math** and **science**. Our Matrix Portal Moon phase clock lets you know where things stand _right here and now,_ portraying the Moon’s phase more accurately than a printed calendar, and whether it’s currently in the sky or has set.

So now you can **prepare**. No tux! Stay home and put on a comfortable flannel shirt like werewolves do.

This project requires:

- Adafruit [**Matrix Portal M4**](https://www.adafruit.com/product/4745) board
- Any of our **64x32** pixel “HUB75” (_not_ NeoPixel) RGB LED matrices (other sizes are _not_ supported by this code)
- **USB C** cable
- USB **power supply** with output of 2 Amps or more
- **WiFi** internet access
- An [**Adafruit IO**](https://io.adafruit.com) account (the **free basic plan** will suffice, we’re just using this to set the time)
- An insatiable hunger for human flesh

This guide will get the software running on the bare Matrix Portal hardware. Mounting or supporting the clock in an enclosure or frame is left as an exercise to the reader.

Next we’ll connect the Matrix Portal board and LED matrix. _Do not_ over-tighten the screws on the power terminals or they can shear off. This is best done in human form.

## Parts
### Adafruit Matrix Portal - CircuitPython Powered Internet Display

[Adafruit Matrix Portal - CircuitPython Powered Internet Display](https://www.adafruit.com/product/4745)
Folks love our [wide selection of RGB matrices](https://www.adafruit.com/category/327) and accessories, for making custom colorful LED displays... and our RGB Matrix Shields and FeatherWings can be quickly soldered together to make the wiring much easier. But what if we made it...

In Stock
[Buy Now](https://www.adafruit.com/product/4745)
[Related Guides to the Product](https://learn.adafruit.com/products/4745/guides)
![Video of a person rotating an LED matrix panel with animation resembling falling colored sand.](https://cdn-shop.adafruit.com/product-videos/640x480/4745-05.jpg)

### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
![Angled shot of a coiled black, USB-C to USB-A cable.](https://cdn-shop.adafruit.com/640x480/4474-02.jpg)

You can use a USB C power supply or a USB micro B with a [micro B to C adapter](https://www.adafruit.com/product/4299)

### Official Raspberry Pi Power Supply 5.1V 3A with USB C

[Official Raspberry Pi Power Supply 5.1V 3A with USB C](https://www.adafruit.com/product/4298)
The official Raspberry Pi USB-C power supply is here! And of course, we have 'em in classic Adafruit black! Superfast with just the right amount of cable length to get your Pi 4 projects up and running!

Best for use with Pi 4 series, [Pi...](https://www.adafruit.com/product/5814)

In Stock
[Buy Now](https://www.adafruit.com/product/4298)
[Related Guides to the Product](https://learn.adafruit.com/products/4298/guides)
![Angled shot of Official Raspberry Pi Power Supply 5.1V 3A with USB C with Power plug facing down. ](https://cdn-shop.adafruit.com/640x480/4298-04.jpg)

### 5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable

[5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable](https://www.adafruit.com/product/1995)
Our all-in-one 5V 2.5 Amp + MicroUSB cable power adapter is the perfect choice for powering single-board computers like Raspberry Pi, BeagleBone, or anything else that's power-hungry!

This adapter was specifically designed to provide 5.25V, not 5V, but we still call it a 5V USB...

In Stock
[Buy Now](https://www.adafruit.com/product/1995)
[Related Guides to the Product](https://learn.adafruit.com/products/1995/guides)
![MicroUSB power supply with bundled cable and U.S. plugs.](https://cdn-shop.adafruit.com/640x480/1995-02.jpg)

### Micro B USB to USB C Adapter

[Micro B USB to USB C Adapter](https://www.adafruit.com/product/4299)
As technology changes and adapts, so does Adafruit, and speaking of&nbsp;_adapting_, this&nbsp;_ **adapter** _&nbsp;has a Micro B USB jack&nbsp;and a USB C plug.

USB C is the latest industry-standard connector for transmitting data&nbsp;_and_&nbsp;power....

In Stock
[Buy Now](https://www.adafruit.com/product/4299)
[Related Guides to the Product](https://learn.adafruit.com/products/4299/guides)
![Angled shot of Micro B USB to USB C Adapter.](https://cdn-shop.adafruit.com/640x480/4299-02.jpg)

If you'd like your LEDs diffused, some acrylic may help

### Black LED Diffusion Acrylic Panel 12" x 12" - 0.1" / 2.6mm thick

[Black LED Diffusion Acrylic Panel 12" x 12" - 0.1" / 2.6mm thick](https://www.adafruit.com/product/4594)
A nice whoppin' slab of some lovely black acrylic to add some extra diffusion to your LED Matrix project. This material is 2.6mm (0.1") thick and is made of special cast acrylic that makes it perfect for glowy projects, especially matricies or NeoPixels.

Unlike smoke or...

In Stock
[Buy Now](https://www.adafruit.com/product/4594)
[Related Guides to the Product](https://learn.adafruit.com/products/4594/guides)
![LED RGB matrix 12" x 12" with "Adafruit Industries LED Matrix" text showing, and LED acrylic slowly covering to make it nicely diffused](https://cdn-shop.adafruit.com/product-videos/640x480/4594-04.jpg)

Adafruit carries a number of 64x32 RGB LED Matrices, varying between the space between LEDs (pitch) and whether rigid or flexible. Choose your favorite - larger pitch means the display is larger, width and height-wise but with the same number of pixels, and larger may be easier to read further away. Smaller for near your desk, for example.

### 64x32 RGB LED Matrix - 3mm pitch

[64x32 RGB LED Matrix - 3mm pitch](https://www.adafruit.com/product/2279)
Bring a little bit of Times Square into your home with this sweet 64 x 32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked...

In Stock
[Buy Now](https://www.adafruit.com/product/2279)
[Related Guides to the Product](https://learn.adafruit.com/products/2279/guides)
![Two white hands hold out an assembled and powered on 64x32 RGB LED Matrix Panel - 3mm pitch. The matrix displays "Adafruit Industries LED MATRIX! 32x64 *RGB*"](https://cdn-shop.adafruit.com/640x480/2279-00.jpg)

### 64x32 RGB LED Matrix - 4mm pitch

[64x32 RGB LED Matrix - 4mm pitch](https://www.adafruit.com/product/2278)
Bring a little bit of Times Square into your home with this sweet 64 x 32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked...

In Stock
[Buy Now](https://www.adafruit.com/product/2278)
[Related Guides to the Product](https://learn.adafruit.com/products/2278/guides)
![Two white hands hold out an assembled and powered on 64x32 RGB LED Matrix Panel - 4mm pitch. The matrix displays "Adafruit Industries LED MATRIX! 32x64 *RGB*"](https://cdn-shop.adafruit.com/640x480/2278-00.jpg)

### 64x32 RGB LED Matrix - 5mm pitch

[64x32 RGB LED Matrix - 5mm pitch](https://www.adafruit.com/product/2277)
Bring a little bit of Times Square into your home with this sweet 64x32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked really...

In Stock
[Buy Now](https://www.adafruit.com/product/2277)
[Related Guides to the Product](https://learn.adafruit.com/products/2277/guides)
![Two white hands hold out an assembled and powered on 64x32 RGB LED Matrix Panel - 5mm pitch. The matrix displays "Adafruit Industries LED MATRIX! 32x64 *RGB*"](https://cdn-shop.adafruit.com/640x480/2277-00.jpg)

### 64x32 RGB LED Matrix - 6mm pitch

[64x32 RGB LED Matrix - 6mm pitch](https://www.adafruit.com/product/2276)
Bring a little bit of Times Square into your home with this sweet 64x32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked really...

In Stock
[Buy Now](https://www.adafruit.com/product/2276)
[Related Guides to the Product](https://learn.adafruit.com/products/2276/guides)
![Two white hands hold out an assembled and powered on 64x32 RGB LED Matrix Panel - 6mm pitch. The matrix displays "Adafruit Industries LED MATRIX! 32x64 *RGB*"](https://cdn-shop.adafruit.com/640x480/2276-00.jpg)

# Moon Phase Clock for Adafruit Matrix Portal

## Prep the MatrixPortal

## Power Prep

The MatrixPortal supplies power to the matrix display panel via two standoffs. These come with protective tape applied (part of our manufacturing process) which MUST BE REMOVED!

Use some tweezers or a fingernail to remove the two amber circles.

![adafruit_io_mxprtl-3866.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/902/medium640/adafruit_io_mxprtl-3866.jpg?1600706317)

![adafruit_io_mxprtl-3867.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/903/medium640/adafruit_io_mxprtl-3867.jpg?1600706324)

## Power Terminals

Next, screw in the spade connectors to the corresponding standoff.

- **red** wire goes to **+5V** &nbsp;
- **black** wire goes to **GND**

![adafruit_io_mxprtl-3869.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/907/medium640/adafruit_io_mxprtl-3869.jpg?1600706432)

![adafruit_io_mxprtl-3871.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/908/medium640/adafruit_io_mxprtl-3871.jpg?1600706551)

## Panel Power

Plug either one of the four-conductor power plugs into the power connector pins on the panel. The plug can only go in one way, and that way is marked on the board's silkscreen.

![adafruit_io_mxprtl-3872.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/910/medium640/adafruit_io_mxprtl-3872.jpg?1600706597)

![adafruit_io_mxprtl-3873.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/911/medium640/adafruit_io_mxprtl-3873.jpg?1600706672)

## Dual Matrix Setup

If you're planning to use a 64x64 matrix, [follow these instructions on soldering the Address E Line jumper](https://learn.adafruit.com/adafruit-matrixportal-m4/pinouts#address-e-line-jumper-3072815).

## Board Connection

Now, plug the board into the left side shrouded 8x2 connector as shown. The orientation matters, so take a moment to confirm that the **white indicator arrow on the matrix panel is oriented pointing up and right** as seen here and the MatrixPortal overhangs the edge of the panel when connected. This allows you to use the edge buttons from the front side.

&nbsp;

Check nothing is impeding the board from plugging in firmly. If there's a plastic nub on the matrix that's keeping the Portal from sitting flat, cut it off with diagonal cutters

![adafruit_io_mxprtl-3874.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/912/medium640/adafruit_io_mxprtl-3874.jpg?1600706721)

![adafruit_io_mxprtl-3875.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/913/medium640/adafruit_io_mxprtl-3875.jpg?1600706732)

![](https://cdn-learn.adafruit.com/assets/assets/000/094/914/medium800/adafruit_io_mxprtl-3876.jpg?1600706891)

![](https://cdn-learn.adafruit.com/assets/assets/000/094/915/medium800/adafruit_io_mxprtl-3877.jpg?1600706894)

Info: 

# Moon Phase Clock for Adafruit Matrix Portal

## 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.

## Set up CircuitPython Quick Start!

Follow this quick step-by-step for super-fast Python power :)

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/matrixportal_m4/)
## Further Information

For more detailed info on installing CircuitPython, check out [Installing CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython).

 **Click the link above and download the latest UF2 file.**

Download and save it to your desktop (or wherever is handy).

![led_matrices_Save_to_Desktop.png](https://cdn-learn.adafruit.com/assets/assets/000/095/075/medium640/led_matrices_Save_to_Desktop.png?1601050695)

Plug your MatrixPortal M4 into your computer using a known-good USB cable.

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

Double-click the **Reset** button (indicated by the green arrow) on your board, and you will see the NeoPixel RGB LED (indicated by the magenta arrow) turn green. If it turns red, check the USB cable, try another USB port, etc.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

![led_matrices_matrixportal_install_cp.jpg](https://cdn-learn.adafruit.com/assets/assets/000/125/447/medium640/led_matrices_matrixportal_install_cp.jpg?1697644568)

You will see a new disk drive appear called **MATRIXBOOT**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **MATRIXBOOT****.**

![led_matrices_MATRIXBOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/125/448/medium640/led_matrices_MATRIXBOOT.png?1697644692)

![led_matrices_Drag_to_Drive.png](https://cdn-learn.adafruit.com/assets/assets/000/125/449/medium640/led_matrices_Drag_to_Drive.png?1697644703)

The LED will flash. Then, the **MATRIXBOOT** &nbsp;drive will disappear and a new disk drive called **CIRCUITPY** will appear.

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

![led_matrices_circuitpy.png](https://cdn-learn.adafruit.com/assets/assets/000/125/450/medium640/led_matrices_circuitpy.png?1697645066)

# Moon Phase Clock for Adafruit Matrix Portal

## Install Code and Graphics

Primary: 

Danger: If you are using the Adafruit Matrix Portal **M4**, you must [update the firmware](https://learn.adafruit.com/upgrading-esp32-firmware/upgrade-all-in-one-esp32-airlift-firmware) on the AirLift co-processor on your board to version 3.0.0 or later. This is due to changes at the website the code uses for moon data. This is not an issue with the Matrix Portal S3.

## Installing Project Code

To use with CircuitPython, you need to first install a few libraries, into the lib folder on your **CIRCUITPY** drive. Then you need to update **code.py** with the example script.

Thankfully, we can do this in one go. In the example below, click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, open the directory **Matrix\_Portal\_Moon\_Clock/** and then click on the directory that matches the version of CircuitPython you're using and copy the contents of that directory to your **CIRCUITPY** drive.

Your **CIRCUITPY** drive should now look similar to the following image:

![CIRCUITPY](https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/folder-images/Matrix_Portal_Matrix_Portal_Moon_Clock.png?raw=true )

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

One additional file you’ll create or edit yourself — **settings.toml** — is explained on the next page…

# Moon Phase Clock for Adafruit Matrix Portal

## Configure Network and Location

 **settings.toml** on the CIRCUITPY drive holds your **WiFi network and Adafruit IO credentials** and other info. This file can be created or edited with any simple text editor you prefer. It resides in the **root directory** of the CIRCUITPY drive, not inside a folder.

If you already have this file on your Matrix Portal from prior projects…great!

If not, it should resemble what’s below. Some items are strings (in single quotes), others are numbers (no quotes).

**The format of this file is&nbsp;**** super persnickety**, every space and comma counts! If creating it for the first time, best to copy-and-paste the text below exactly, then change any items of interest (preserving quotation marks and such).

**CIRCUITPY\_WIFI\_SSID** and&nbsp; **CIRCUITPY\_WIFI\_PASSWORD** are your WiFi network name and password.

**ADAFRUIT\_AIO\_USERNAME** and&nbsp; **ADAFRUIT\_AIO\_KEY** can be found by logging into your [**Adafruit IO**](https://io.adafruit.com) account and clicking the yellow key icon near the top-right. If you don’t yet have an account, set one up, the basic service is free! This is used by the software to set the clock.

**timezone** is needed to distinguish your local time from UTC (aka Greenwich time). [Here’s a list of valid time zone strings](http://worldtimeapi.org/timezones); find a city in your zone and copy/paste it here (in quotes).

**latitude** and **longitude** are **optional but recommended**. The clock can do IP geolocation (estimating your location using IP address), but having it here is more accurate. These values are floating-point numbers (in degrees and decimal fractions thereof) but **should be in&nbsp;quotes**. For latitude, positive values are north, negative is south. For longitude, negative is west, positive is east. If you change the program and need the actual floating point values, use `float(latitude)` and `float(longitude)`.

```python
CIRCUITPY_WIFI_SSID="your-wifi-ssid"
CIRCUITPY_WIFI_PASSWORD="your-wifi-password"
timezone="America/New_York"  # http://worldtimeapi.org/timezones
ADAFRUIT_AIO_USERNAME="my_username"
ADAFRUIT_AIO_KEY="my_key"
latitude="32.71193"
longitude="-117.16072"
```

You can easily get your decimal latitude and longitude from [**Google Maps**](https://www.google.com/maps). Zoom in on a location and **right-click** on the map. Information there includes latitude and longitude in exactly the format we need…click the coordinates to copy them to the clipboard, then paste into the **settings.toml** file and reformat the text as shown above.

![](https://cdn-learn.adafruit.com/assets/assets/000/108/516/medium800/projects_werewolf-map.png?1643663632)

The code will relaunch any time there’s a change on the **CIRCUITPY** drive…so, after editing **settings.toml** , the clock should start up on its own and you’ll see a splash screen after a few seconds.

**If the clock does NOT start up, or shows the splash screen but then crashes:** most likely the WiFi credentials are incorrect, or something is wrong with the **settings.toml** file syntax…make sure every quote, and equals sign is there and in the right place.

# Moon Phase Clock for Adafruit Matrix Portal

## Clock Usage

On power-up, the clock will display a splash screen while it connects to the WiFi network and makes a couple of initial server requests for time and Moon data.

![projects_splash.jpg](https://cdn-learn.adafruit.com/assets/assets/000/095/015/medium640/projects_splash.jpg?1600886226)

 **Time** is provided by [Adafruit IO](https://io.adafruit.com), and **astronomical data** from the&nbsp;**[Norwegian Meteorological Institute](https://www.met.no/en)**. These two sources were chosen as they are **free** and **do not require a paid account** for access.

The orientation of the clock at startup determines how information is displayed — in a vertical “portrait” format, or horizontal “landscape” format. There’s different artwork for all four directions!

## **Clock Operation Basics**
With the clock set up **horizontally** (either hung or propped up with a stand or case), the current Moon phase (with percentage lit) is displayed on the left.

The current time and date are displayed on the right. Below this is an indication of the next moonrise or set…

![led_matrices_clock-horiz.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/886/medium640/led_matrices_clock-horiz.jpg?1600638512)

A **downward-pointing arrow** (as shown above) indicates the next lunar event will be a **moonset** — that the Moon is currently **above** the horizon (in the sky) as seen from your position, regardless of phase.

An **upward-pointing arrow** indicates a **moonrise** is next — the Moon is currently **below** the horizon, not currently visible from your position, regardless of phase.

The **time** shown next to the arrow is when this next lunar rise or set event will occur. It can alternately be configured as a countdown, explained shortly.

The **color** of the time and arrow indicates whether this next event occurs in the a.m. hours (green) or p.m. (amber).

The rise and set times are for an “idealized” horizon.&nbsp;Hills or other local obstructions could have it rising a short time later or setting earlier.

All the same data is displayed when the clock’s in a **vertical** orientation, but the visibility of the Moon from your location is made more apparent.

When the Moon is **above** the local horizon (in the sky) the phase is shown at the **top** of the matrix.

![led_matrices_clock-vert-1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/884/medium640/led_matrices_clock-vert-1.jpg?1600638458)

And if the Moon is currently **below** the local horizon, the phase scoots to the **bottom**.

The Moon might still appear above the horizon for someone to the west of you, but the phase will be nearly the same. That’s how this game of cosmic billiards works.

![led_matrices_clock-vert-2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/885/medium640/led_matrices_clock-vert-2.jpg?1600638469)

The percentage shown is the amount of the lunar “disc” that’s **currently illuminated** , _not_ the “age” of the current lunar month. So this will go from 0% (new Moon) to 100%\* (full Moon) and back down to 0% (next new Moon) over the course of the lunar month. The _lunar terminator_ — the line between light and dark — always moves right to left, like turning the pages of a book (that’s why it doesn’t bother reporting if the phase is _waxing_ or _waning_ — it’s easy to visualize).

\* It’s normal some months that you’ll see this only go to 99.8 or 99.9 percent…the Moon’s [never _quite_ perfectly full](http://www.nbcnews.com/id/4402294/ns/technology_and_science-space/t/full-moon-merely-fallacy/) from our position.

_If the clock starts up in the wrong orientation…just tap the reset button and let it try again.&nbsp;Occasionally the accelerometer gets confused when grappling the clock to plug it in, or the “snap” of a USB cable being inserted._

## **Customizing the Clock Display**
Some aspects of the clock display can be changed by editing the file **code.py** &nbsp;in your text editor of choice. Starting around line 35, look for this section of code:

```python
# CONFIGURABLE SETTINGS -------------------------------------

TWELVE_HOUR = True # If set, use 12-hour time vs 24-hour
COUNTDOWN = False  # If set, show time to next rise/set event
```

Change the value of&nbsp;`TWELVE_HOUR` to `False` (capitalized — Python is case sensitive) to have the clock display times in 24-hour military time.

Changing `COUNTDOWN` to `True` makes the clock show the time _to_ the next rise/set event (hours and minutes), rather than the time _of_ the event. Both modes are shown in the same HH:MM format, so COUNTDOWN mode may be confusing if you’re not familiar with the clock’s operation.

The startup splash screen images are inside the **moon** folder, named&nbsp; **splash-0.bmp** ,&nbsp; **splash-90.bmp** ,&nbsp; **splash-180.bmp** and&nbsp; **splash-270.bmp** — one image is selected on startup based on the Matrix Portal orientation. If you’ve settled on a position for installing your Moon clock but want the opposite splash image, you can just rename these files, e.g. swap the filenames on splash-0.bmp and splash-180.bmp (or 90 and 270).&nbsp;Or you can delete the splash images (they might be frightening to children) or substitute your own BMP files.

_Matrix brightness is not currently adjustable. It’s just more than the microcontroller can handle._

## **Timekeeping**
The clock will periodically contact a time server to keep itself in sync. But if you observe the time drifting by more than a minute or two, you can have it sync more often.

Look for these lines in **code.py** (in the “MAIN LOOP” section):

```python
# Sync with time server every ~3 hours
if NOW_LOCAL_SECONDS - LAST_SYNC_LOCAL_SECONDS &gt; 3 * 60 * 60:
```

Change the `3` to a smaller value…perhaps `2`, or `1` if the time drift is _really_ pronounced. This is the period (in hours) between clock updates. To avoid over-taxing the server, provided as a free service, don’t set this too low.

Interestingly, the clock will keep better time if powered from a computer’s USB port (which provides a steady 1.000 KHz reference pulse) than from a passive USB “wall wart.” Not always practical, of course…but if you have a free USB port on a NAS or other nearby system that runs 24/7, it’s something to consider.

# Moon Phase Clock for Adafruit Matrix Portal

## Moon Facts

![](https://cdn-learn.adafruit.com/assets/assets/000/094/874/medium800/led_matrices_full-moon-wikipedia.jpg?1600580669 Image credit: Rogério da silva Santana, Wikipedia)

So what's the big deal? What’s wrong with the Moon phases on wall calendars? Surely those dates come from trusted sources! NASA, almanacs and stuff!

The problems are many…some technical, some semantic…each alone may be minor, but there’s the potential for them to _compound_ and really mix things up.

- Most importantly, unless they explain their data sources, static media can’t take into account different **time zones**. At any given moment, the Moon’s phase appears nearly the same from anywhere on Earth (if it’s above the local horizon), but the time of day…and even the day itself…may vary. If a calendar is basing their phases on UTC time but you’re in North America, they might be reporting a lunar phase on on a Thursday while to you it’s still late Wednesday (this can happen in the other direction too).
- Each day’s changeover at midnight doesn’t align with our **semantic concept of a “night”** — we tend to lump early morning hours with the prior day. So, if a lunar phase crossing occurs in the early hours after midnight (for a given time zone), it might be _reported_ as Thursday, while we’re inclined to _think_ of it as late Wednesday night…but, seeing Thursday on the calendar, we think “Thursday night” and could easily end up celebrating a “full” Moon that’s past its ideal freshness date.
- What even is “full,” or any other phase of the Moon? It’s erroneous to think there’s a single night that the Moon is locked in “full,” because this is an **analog system** with celestial bodies in **continual motion** , and phase can change by several percent in a single 24-hour period. To the unaided eye, anything more than about 98% illumination of the lunar disc is pretty much indistinguishable from “full,” and you’ll get two to three successive nights that would qualify. Those dates on the calendar typically refer to an “instantaneous” phase crossing (and once again, for whatever time zone they’re using for reference). If at that moment the Moon is below the horizon (is on the opposite side of the planet from you, due to the Earth’s rotation), and if your definition of “full” is too narrow…have you really experienced a full Moon at all? Sometimes it’s okay to think of a phase as “ish.”
- Sometimes just sloppy reporting…the instantaneous time of a phase crossing is sometimes improperly reported as the Moon rise time instead, and other slip-ups.

As you can see, it’s _A Huge Ordeal_, and that was the inspiration for making this clock. No more “do they mean Wednesday night or Thursday morning?” This is the Moon _as it is right now._

## **Other Moon Factoids**

- We tend to think of the Moon as a **nighttime** phenomenon, but really it spends just as much time on the **daylight** side. During a new Moon, it rises and sets close to the same time as the Sun, the narrow crescent lost in the glare of the daylight sky.
- The cycle of phases — the “lunar month” — is about **29.5 days** long. It varies a bit due to the elliptical nature of orbits and that the Earth-Moon system is in turn orbiting the Sun.
- If you really want to get lost in all the details, **[NASA’s Dial-A-Moon page](https://svs.gsfc.nasa.gov/4768)** is packed with information and nuance!
- A **lunar eclipse** can only happen during the full Moon, but not all full Moons experience a lunar eclipse … the orbital planes of the Earth and Moon diverge by a few degrees.&nbsp;Correspondingly, a **solar eclipse** can only happen during the new Moon, but not all new Moons experience a solar eclipse. (_WolfCop_ got this wrong, with a solar eclipse the day after a full moon, and I’m still bitter about it.)
- Some full moons have **special names** — a “blue Moon” is an infrequent second full Moon in the same month, the “pink Moon” is usually the full Moon in April — but these are _only_ names and are&nbsp;_not_&nbsp;actually descriptive of the Moon’s color. Sometimes atmospheric phenomena (smoke, etc.) can cast the Moon in varying hues, but it’s entirely unrelated to these names.


## Featured Products

### Adafruit Matrix Portal - CircuitPython Powered Internet Display

[Adafruit Matrix Portal - CircuitPython Powered Internet Display](https://www.adafruit.com/product/4745)
Folks love our [wide selection of RGB matrices](https://www.adafruit.com/category/327) and accessories, for making custom colorful LED displays... and our RGB Matrix Shields and FeatherWings can be quickly soldered together to make the wiring much easier. But what if we made it...

In Stock
[Buy Now](https://www.adafruit.com/product/4745)
[Related Guides to the Product](https://learn.adafruit.com/products/4745/guides)
### Black LED Diffusion Acrylic Panel 12" x 12" - 0.1" / 2.6mm thick

[Black LED Diffusion Acrylic Panel 12" x 12" - 0.1" / 2.6mm thick](https://www.adafruit.com/product/4594)
A nice whoppin' slab of some lovely black acrylic to add some extra diffusion to your LED Matrix project. This material is 2.6mm (0.1") thick and is made of special cast acrylic that makes it perfect for glowy projects, especially matricies or NeoPixels.

Unlike smoke or...

In Stock
[Buy Now](https://www.adafruit.com/product/4594)
[Related Guides to the Product](https://learn.adafruit.com/products/4594/guides)
### 64x32 RGB LED Matrix - 3mm pitch

[64x32 RGB LED Matrix - 3mm pitch](https://www.adafruit.com/product/2279)
Bring a little bit of Times Square into your home with this sweet 64 x 32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked...

In Stock
[Buy Now](https://www.adafruit.com/product/2279)
[Related Guides to the Product](https://learn.adafruit.com/products/2279/guides)
### 64x32 RGB LED Matrix - 4mm pitch

[64x32 RGB LED Matrix - 4mm pitch](https://www.adafruit.com/product/2278)
Bring a little bit of Times Square into your home with this sweet 64 x 32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked...

In Stock
[Buy Now](https://www.adafruit.com/product/2278)
[Related Guides to the Product](https://learn.adafruit.com/products/2278/guides)
### 64x32 RGB LED Matrix - 5mm pitch

[64x32 RGB LED Matrix - 5mm pitch](https://www.adafruit.com/product/2277)
Bring a little bit of Times Square into your home with this sweet 64x32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked really...

In Stock
[Buy Now](https://www.adafruit.com/product/2277)
[Related Guides to the Product](https://learn.adafruit.com/products/2277/guides)
### 64x32 RGB LED Matrix - 6mm pitch

[64x32 RGB LED Matrix - 6mm pitch](https://www.adafruit.com/product/2276)
Bring a little bit of Times Square into your home with this sweet 64x32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked really...

In Stock
[Buy Now](https://www.adafruit.com/product/2276)
[Related Guides to the Product](https://learn.adafruit.com/products/2276/guides)
### 64x32 Flexible RGB LED Matrix - 4mm Pitch

[64x32 Flexible RGB LED Matrix - 4mm Pitch](https://www.adafruit.com/product/3826)
If you've played with multiplexed RGB matrices, you may have wondered "hey, could we possibly manufacture these on a thin enough PCB, so it's flexible?" and the answer is&nbsp; **Yes!** &nbsp;[T](http://www.adafruit.com/?q=64x32%20RGB)<a...></a...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3826)
[Related Guides to the Product](https://learn.adafruit.com/products/3826/guides)
### 64x32 Flexible RGB LED Matrix - 5mm Pitch

[64x32 Flexible RGB LED Matrix - 5mm Pitch](https://www.adafruit.com/product/3803)
If you've played with multiplexed RGB matrices, you may have wondered "hey, could we possibly manufacture these on a thin enough PCB so it's flexible?" and the answer is **Yes!** [T](http://www.adafruit.com/?q=64x32%20RGB)<a...></a...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3803)
[Related Guides to the Product](https://learn.adafruit.com/products/3803/guides)

## Related Guides

- [Adafruit MatrixPortal M4](https://learn.adafruit.com/adafruit-matrixportal-m4.md)
- [Matrix Portal Stained Glass with WLED](https://learn.adafruit.com/matrix-portal-stained-glass-with-wled.md)
- [Matrix Portal Creature Eyes](https://learn.adafruit.com/matrix-portal-creature-eyes.md)
- [RGB Matrix Panels With Raspberry Pi 5](https://learn.adafruit.com/rgb-matrix-panels-with-raspberry-pi-5.md)
- [Expressive Pixels for Adafruit Matrix Portal](https://learn.adafruit.com/expressive-pixels-for-matrix-portal.md)
- [Animated GIF Player for Matrix Portal](https://learn.adafruit.com/animated-gif-player-for-matrix-portal.md)
- [Adafruit Triple LED Matrix Bonnet for Raspberry Pi with HUB75](https://learn.adafruit.com/adafruit-triple-led-matrix-bonnet-for-raspberry-pi-with-hub75.md)
- [itsaSNAP Daily Weather Forecast Board](https://learn.adafruit.com/itsasnap-daily-weather-forecast-board.md)
- [Purple Air AQI Display](https://learn.adafruit.com/purple-air-aqi-display.md)
- [Matrix Portal Scoreboard](https://learn.adafruit.com/matrix-portal-scoreboard.md)
- [LED Protest Sign](https://learn.adafruit.com/led-protest-sign.md)
- [RGB LED Matrices with CircuitPython](https://learn.adafruit.com/rgb-led-matrices-matrix-panels-with-circuitpython.md)
- [Adafruit ItsyBitsy RP2040](https://learn.adafruit.com/adafruit-itsybitsy-rp2040.md)
- [DIY LED Video Wall](https://learn.adafruit.com/adafruit-diy-led-video-wall.md)
- [IoT Moon Phase Guide](https://learn.adafruit.com/moon-phase.md)
