# Dragon Drop: a CircuitPython Game for MacroPad

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/103/693/medium800/gaming_title-pic.jpg?1628012579)

Adafruit’s&nbsp;**[_MacroPad_](https://learn.adafruit.com/adafruit-macropad-rp2040)** was designed as the ultimate keyboard accessory —&nbsp;whether for [application hotkeys](https://learn.adafruit.com/macropad-hotkeys) or [making music](https://learn.adafruit.com/ableton-live-macropad-launcher)&nbsp;or other computer-like duties.

One thing that really sets MacroPad apart from similar devices is that it’s _not_ simply a small keyboard…it’s a whole _development board_ running [CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython).&nbsp;Very handy for computer-connected tasks, certainly, but nothing actually _demands_ that.&nbsp;What else could one do with this? How about a trinary handheld calculator? Attach a USB battery and make it portable. Make a _Quantum Leap_ Handlink cosplay accessory. Or program some little games.

Let’s try the latter and make a game! Just a simplistic one, but hopefully it plants some good ideas…

- MacroPad isn’t _just_ a keyboard, it’s _fully programmable in CircuitPython._
- It can do more than keyboard macros.
- It can be made portable with a USB battery.
- Consider using Macropad sideways or upside-down if your project calls for it. _There is no “up” in space!_

![](https://cdn-learn.adafruit.com/assets/assets/000/103/692/medium800/gaming_3-screens.jpg?1628012299)

## Parts
### Adafruit MacroPad RP2040 Starter Kit - 3x4 Keys + Encoder + OLED

[Adafruit MacroPad RP2040 Starter Kit - 3x4 Keys + Encoder + OLED](https://www.adafruit.com/product/5128)
Strap yourself in, we're launching in T-minus 10 seconds...Destination? A new Class M planet called MACROPAD! M here stands for Microcontroller because this 3x4 keyboard controller features the newest technology from the Raspberry Pi sector: say hello to the RP2040. It's a speedy...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5128)
[Related Guides to the Product](https://learn.adafruit.com/products/5128/guides)
![Video of a hand playing with a rainbow-glowing keypad.](https://cdn-shop.adafruit.com/product-videos/640x480/5128-08.jpg)

- or -

### Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED

[Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED](https://www.adafruit.com/product/5100)
Strap yourself in, we're launching in T-minus 10 seconds...Destination? A new Class M planet called MACROPAD! M here, stands for Microcontroller because this 3x4 keyboard controller features the newest technology from the Raspberry Pi sector: say hello to the RP2040. It's a speedy...
In Stock
[Buy Now](https://www.adafruit.com/product/5100)
[Related Guides to the Product](https://learn.adafruit.com/products/5100/guides)
![Angled shot of MacroPad](https://cdn-shop.adafruit.com/640x480/5100-00.jpg)

### Adafruit MacroPad RP2040 Enclosure + Hardware Add-on Pack

[Adafruit MacroPad RP2040 Enclosure + Hardware Add-on Pack](https://www.adafruit.com/product/5103)
Dress up your Adafruit Macropad with PaintYourDragon's fabulous decorative silkscreen enclosure and hardware kit. You get the two custom PCBs that are cut to act as a protective bottom plate and and a mechanically-stabilizing keyboard plate.

Use the included M3 screws to attach the...

In Stock
[Buy Now](https://www.adafruit.com/product/5103)
[Related Guides to the Product](https://learn.adafruit.com/products/5103/guides)
![Top view of MacroPad add on pack](https://cdn-shop.adafruit.com/640x480/5103-06.jpg)

### Kailh Mechanical Key Switches - Linear Red - 12 Pack

[Kailh Mechanical Key Switches - Linear Red - 12 Pack](https://www.adafruit.com/product/5122)
For crafting your very own custom keyboard, these **&nbsp;Kailh Red Linear mechanical key switches** &nbsp;are deeee-luxe! With smooth actuation and Cherry MX compatibility, they're lovely when you want a&nbsp; **smooth linear&nbsp;** keystroke:

- Type...

In Stock
[Buy Now](https://www.adafruit.com/product/5122)
[Related Guides to the Product](https://learn.adafruit.com/products/5122/guides)
![Top shot of 12 pack Red Kailh Mechanical Key Switches ](https://cdn-shop.adafruit.com/640x480/5122-02.jpg)

### Clear Keycaps for MX Compatible Switches - 12-pack

[Clear Keycaps for MX Compatible Switches - 12-pack](https://www.adafruit.com/product/5068)
Here is a **12&nbsp;pack** of Clear DSA keycaps for your next mechanical keyboard or&nbsp;[NeoKey](https://www.adafruit.com/?q=neokey&sort=BestMatch)&nbsp;project. Snap 'em onto any&nbsp; **Cherry MX or compatible switch&nbsp;** to turn your&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/5068)
[Related Guides to the Product](https://learn.adafruit.com/products/5068/guides)
![Group shot of Clear DSA Keycaps for MX Compatible Switches - 12 pack](https://cdn-shop.adafruit.com/640x480/5068-04.jpg)

# Dragon Drop: a CircuitPython Game for MacroPad

## 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_macropad_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/103/264/medium800/adafruit_products_MacroPad_boot_reset.jpg?1625068553)

Info: 

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)
# Dragon Drop: a CircuitPython Game for MacroPad

## Project Code

As games go, Dragon Drop is rudimentary…it’s more about presenting some starter code for your own project ideas, in a medium-size program. I was surprised how well CircuitPython could handle game animation on the little OLED screen.

 **CircuitPython 7.0.0 alpha 6 fixes some “scratchy” audio issues. If using an earlier version, it’s worth upgrading!**

## Text Editor

If you just want to try out the game, skip ahead to the “Download the Project Bundle” section below.

If you plan to get into the source code to customize gameplay or learn more about it,&nbsp;Adafruit recommends using the **Mu** editor for editing your CircuitPython code. You can get more info in [this guide](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

Alternatively, you can use any text editor that saves simple text files.

## Download the Project Bundle

Your project will use a specific set of CircuitPython libraries and the&nbsp; **code.py** &nbsp;file, along with a folder of graphics and sound files. To get everything you need, click on the&nbsp; **Download Project Bundle** &nbsp;link below, and uncompress the .zip file.

Make backups of any files on the board you want to keep, then drag the contents of the uncompressed bundle directory onto your MACROPAD board's **CIRCUITPY** &nbsp;drive, replacing any existing files or directories with the same names.

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

# Dragon Drop: a CircuitPython Game for MacroPad

## Gameplay

Turn MacroPad **sideways** , with the display and USB port on the **left**.&nbsp;This game uses the screen in a tall “portrait” orientation — we wanted to&nbsp;show that’s possible.

![](https://cdn-learn.adafruit.com/assets/assets/000/103/687/medium800/gaming_macropad-sideways.jpg?1628008528)

![](https://cdn-learn.adafruit.com/assets/assets/000/103/690/medium800/gaming_3-screens.jpg?1628009560)

From the title screen, tap any key to start.

During gameplay, there’s just **four keys** to worry about…or four columns, any key within a column will work.

![gaming_4-columns.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/688/medium640/gaming_4-columns.jpg?1628009492)

 **Dragon stuff** — eggs and fireballs — fall from the sky! These are arranged in **four columns** , corresponding to the **four keys**.

“Catch” an egg by tapping the corresponding key just before it hits the ground. _But not too soon either._

_Don’t_ catch the fireballs!

You’ll get a bit of additional visual feedback from the NeoPixels under MacroPad’s keys.

![gaming_gameplay.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/694/medium640/gaming_gameplay.jpg?1628013159)

Earn 10 points (and a little “rawr!” dragon hatchling) for every good catch.

Your “energy” (shown as a bar across top of screen) is depleted slightly for broken eggs or burned hands. Game continues until energy runs out. The pace gradually increases.

A closing screen shows your final score, and you can cap a key to try again.

# Dragon Drop: a CircuitPython Game for MacroPad

## Reflection

![](https://cdn-learn.adafruit.com/assets/assets/000/103/697/medium800/gaming_3-screens.jpg?1628018171)

So I wanted to write a **small but reasonably complete** game to show an “unexpected” (not-keyboard-macros) use of MacroPad.

Lately I’ve been enjoying VR rhythm games like _Beat Saber_ and _Synth Riders,_ and my initial idea was to capture just a tiny slice&nbsp;of that, albeit in two dimensions. Go back a couple generations, and prior rhythm games like _Guitar Hero_ and _Dance Dance Revolution_ were essentially that, and would suit MacroPad’s keys.

_(screenshot: [pydance](https://icculus.org/pyddr/))_

![gaming_pydance-5.png](https://cdn-learn.adafruit.com/assets/assets/000/103/703/medium640/gaming_pydance-5.png?1628020040)

But even this would be **Too Much Project** … building the “maps” to synchronize music and actions would be _A Development Ordeal_. I wanted something that could be written in a couple days, just a few bitmaps and a sensible amount of code. Not a serious game, just enough to show that these things can be done if you want.

Peeling back layers was like a reverse chronological walk through game history. _Tetris_ might be doable but a bit more code than desired. Full-on game music would be complex. And so forth, until reaching the irreducible “catch things falling from above” play mechanic, with some “avoid these other things” to spice it up. It’s rudimentary, but maybe I could add appeal with some **dragons**. _Everyone_ loves dragons!

The resulting flavor is reminiscent of some early “catch” games like Activision’s _Kaboom_ for the Atari 2600 (catch bombs) or the arcade game that inspired it, Atari’s _Avalanche_ (catch rocks). Amusingly, I learned afterward that the original concept for _Avalanche_ had falling eggs, but play testers didn’t like that. Oops.

![gaming_kaboom.png](https://cdn-learn.adafruit.com/assets/assets/000/103/698/medium640/gaming_kaboom.png?1628018315)

![gaming_avalanche.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/699/medium640/gaming_avalanche.jpg?1628018334)

That got me thinking how early video games always had elaborate box art and a whole _back story,_ even with simple games. Partly of course because the graphics were so crude…but also, video games were such a foreign concept, it was necessary to create some emotional “hook” to an otherwise abstract thing. Early players would be lost without it.

![gaming_adventure1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/700/medium640/gaming_adventure1.jpg?1628018612)

![gaming_adventure2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/701/medium640/gaming_adventure2.jpg?1628018623)

![gaming_adventure3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/103/702/medium640/gaming_adventure3.jpg?1628018630)

Nobody asks what the cubes are in _Beat Saber_ or why it’s so vital to chop them up. The concept is entirely abstract, but needs no back story…it’s intuitive to play and the action is viscerally appealing, what more do you need? “This is a rhythm game. Have fun!”

Nearly half a century in, video games evolved a stable of tropes — the maze game, the shooting game, puzzle game, RPG and so forth — much as movies and media tap into established tropes to avoid lengthy exposition…it simplified the “Gameplay” page significantly.&nbsp;You don’t always notice it when looking at a single specimen, but walk backward through a game’s or film’s predecessors and you can see a progression as things congeal.


## Featured Products

### Adafruit MacroPad RP2040 Starter Kit - 3x4 Keys + Encoder + OLED

[Adafruit MacroPad RP2040 Starter Kit - 3x4 Keys + Encoder + OLED](https://www.adafruit.com/product/5128)
Strap yourself in, we're launching in T-minus 10 seconds...Destination? A new Class M planet called MACROPAD! M here stands for Microcontroller because this 3x4 keyboard controller features the newest technology from the Raspberry Pi sector: say hello to the RP2040. It's a speedy...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5128)
[Related Guides to the Product](https://learn.adafruit.com/products/5128/guides)
### Adafruit MacroPad RP2040 Enclosure + Hardware Add-on Pack

[Adafruit MacroPad RP2040 Enclosure + Hardware Add-on Pack](https://www.adafruit.com/product/5103)
Dress up your Adafruit Macropad with PaintYourDragon's fabulous decorative silkscreen enclosure and hardware kit. You get the two custom PCBs that are cut to act as a protective bottom plate and and a mechanically-stabilizing keyboard plate.

Use the included M3 screws to attach the...

In Stock
[Buy Now](https://www.adafruit.com/product/5103)
[Related Guides to the Product](https://learn.adafruit.com/products/5103/guides)
### Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED

[Adafruit MACROPAD RP2040 Bare Bones - 3x4 Keys + Encoder + OLED](https://www.adafruit.com/product/5100)
Strap yourself in, we're launching in T-minus 10 seconds...Destination? A new Class M planet called MACROPAD! M here, stands for Microcontroller because this 3x4 keyboard controller features the newest technology from the Raspberry Pi sector: say hello to the RP2040. It's a speedy...
In Stock
[Buy Now](https://www.adafruit.com/product/5100)
[Related Guides to the Product](https://learn.adafruit.com/products/5100/guides)
### Kailh Mechanical Key Switches - Linear Red - 12 Pack

[Kailh Mechanical Key Switches - Linear Red - 12 Pack](https://www.adafruit.com/product/5122)
For crafting your very own custom keyboard, these **&nbsp;Kailh Red Linear mechanical key switches** &nbsp;are deeee-luxe! With smooth actuation and Cherry MX compatibility, they're lovely when you want a&nbsp; **smooth linear&nbsp;** keystroke:

- Type...

In Stock
[Buy Now](https://www.adafruit.com/product/5122)
[Related Guides to the Product](https://learn.adafruit.com/products/5122/guides)
### Clear Keycaps for MX Compatible Switches - 12-pack

[Clear Keycaps for MX Compatible Switches - 12-pack](https://www.adafruit.com/product/5068)
Here is a **12&nbsp;pack** of Clear DSA keycaps for your next mechanical keyboard or&nbsp;[NeoKey](https://www.adafruit.com/?q=neokey&sort=BestMatch)&nbsp;project. Snap 'em onto any&nbsp; **Cherry MX or compatible switch&nbsp;** to turn your&nbsp;<a...></a...>

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

## Related Guides

- [Adafruit MacroPad RP2040](https://learn.adafruit.com/adafruit-macropad-rp2040.md)
- [Ableton Live MacroPad Launcher](https://learn.adafruit.com/ableton-live-macropad-launcher.md)
- [3D Printed Stand for MacroPad RP2040](https://learn.adafruit.com/3d-printed-stand-for-macropad-rp2040.md)
- [MacroPad Summer Olympics Hotkeys](https://learn.adafruit.com/macropad-olympic-hotkeys.md)
- [AdaBox 019](https://learn.adafruit.com/adabox019.md)
- [DIY Decorative Resin Keycaps](https://learn.adafruit.com/diy-decorative-resin-keycaps.md)
- [Keypad and Matrix Scanning in CircuitPython](https://learn.adafruit.com/key-pad-matrix-scanning-in-circuitpython.md)
- [An Introduction to RP2040 PIO with CircuitPython](https://learn.adafruit.com/intro-to-rp2040-pio-with-circuitpython.md)
- [MacroPad Braille Keycaps](https://learn.adafruit.com/macropad-braille-keycaps.md)
- [Using QMK on RP2040 Microcontrollers](https://learn.adafruit.com/using-qmk-on-rp2040-microcontrollers.md)
- [MacroPad 2FA TOTP Authentication Friend](https://learn.adafruit.com/macropad-2fa-totp-authentication-friend.md)
- [MacroPad Remote Procedure Calls over USB to Control Home Assistant](https://learn.adafruit.com/macropad-remote-procedure-calls-over-usb-to-control-home-assistant.md)
- [Minecraft Turbopad](https://learn.adafruit.com/minecraft-turbopad.md)
- [Weather Wise Wifi Umbrella Stand](https://learn.adafruit.com/weather-wise-wifi-umbrella-stand.md)
- [Feather Guitar Hero Adapter](https://learn.adafruit.com/feather-guitar-hero-adapter.md)
