# Go Fishing with Rotary Encoders

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/079/309/medium800/makecode_crankcase1.jpg?1565650788)

https://www.youtube.com/watch?v=q1k2WJmluo4

A rotary encoder (aka "endless encoder") can be used as a controller on the PyBadge and PyGamer in MakeCode Arcade. We can determine the speed and direction of rotation and then apply that to sprite positions or other settings in a game. This fishing game makes use of the "crank" blocks in MakeCode Arcade to reel in the fish!

## Parts
### Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

[Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino](https://www.adafruit.com/product/4242)
What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the **Adafruit PyGamer!** We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4242)
[Related Guides to the Product](https://learn.adafruit.com/products/4242/guides)
![Angled shot of Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino.](https://cdn-shop.adafruit.com/640x480/4242-00.jpg)

### Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino

[Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino](https://www.adafruit.com/product/4200)
What's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino? That's right, its the **Adafruit PyBadge!** We wanted to see how much we could cram into a ​3 3⁄8 × ​2 1⁄8 inch rounded rectangle, to make an all-in-one dev board with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4200)
[Related Guides to the Product](https://learn.adafruit.com/products/4200/guides)
![Angled shot of a Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino. ](https://cdn-shop.adafruit.com/640x480/4200-01.jpg)

### Rotary Encoder + Extras

[Rotary Encoder + Extras](https://www.adafruit.com/product/377)
This rotary encoder is the best of the best, it's a high-quality 24-pulse encoder, with detents and a nice feel. It is panel mountable for placement in a box, or you can plug it into a breadboard (just cut/bend the two mechanical side tabs.) We also include a nice soft-touch knob with an...

In Stock
[Buy Now](https://www.adafruit.com/product/377)
[Related Guides to the Product](https://learn.adafruit.com/products/377/guides)
![Rotary Encoder with rubbery knob](https://cdn-shop.adafruit.com/640x480/377-02.jpg)

### Lithium Ion Polymer Battery with Short Cable - 3.7V 350mAh

[Lithium Ion Polymer Battery with Short Cable - 3.7V 350mAh](https://www.adafruit.com/product/4237)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 350mAh for a total of about 1.3 Wh. If you need a larger (or smaller!) battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4237)
[Related Guides to the Product](https://learn.adafruit.com/products/4237/guides)
![Lithium Ion Polymer Battery 3.7v 350mAh with JST 2-PH connector and short cable](https://cdn-shop.adafruit.com/640x480/4237-04.jpg)

### Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt

[Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt](https://www.adafruit.com/product/4227)
Hear the good news! This wee speaker&nbsp;is&nbsp;a&nbsp;great addition to any audio project where you need 8 ohm impedance and 1W or less of power. We particularly like this&nbsp;speaker&nbsp;as it is&nbsp;small and comes with nice skinny wires with a connector on the end. It has a handy...

In Stock
[Buy Now](https://www.adafruit.com/product/4227)
[Related Guides to the Product](https://learn.adafruit.com/products/4227/guides)
![Mini Oval Speaker with Short Wires ](https://cdn-shop.adafruit.com/640x480/4227-06.jpg)

### Silicone Cover Stranded-Core Wire - 26AWG in Various Colors

[Silicone Cover Stranded-Core Wire - 26AWG in Various Colors](https://www.adafruit.com/product/1970)
Silicone-sheathing wire is super-flexible and soft, and it's also strong! Able to handle up to 200°C and up to 600V, it will do when PVC covered wire wimps out. We like this wire for being extremely supple and flexible, so it is great for wearables or projects where the wire-harness...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1970)
[Related Guides to the Product](https://learn.adafruit.com/products/1970/guides)
![Stranded-core wires in white, gray, black, blue, green, red, orange, and yellow.](https://cdn-shop.adafruit.com/640x480/1970-00.jpg)

## Optional

You can 3D print a case and spinning reel crank for your PyGamer and rotary encoder.

### Filament for 3D Printers in Various Colors and Types

[Filament for 3D Printers in Various Colors and Types](https://www.adafruit.com/product/2080)
Having a 3D printer without filament is sort of like having a regular printer without paper or ink. &nbsp;And while a lot of printers come with some filament there's a good chance you've been printing up a storm and need something new. &nbsp;That's why we've started carrying a...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2080)
[Related Guides to the Product](https://learn.adafruit.com/products/2080/guides)
![Filament for 3D printers in various colors and types stacked together.](https://cdn-shop.adafruit.com/640x480/2080-07.jpg)

# Go Fishing with Rotary Encoders

## Adding a Rotary Encoder to PyGamer/PyBadge

I used the excellent [Gaming Handheld Crank](https://learn.adafruit.com/gaming-handheld-crank/overview) guide by the Ruiz Bros. as a launching off point for building this project. Check it out for lots of details.

For the fishing controller, I connected the PyGamer to the rotary encoder like this:

- **Pin A2** connects to the **B pin** (Green wire)
- **Pin A3** connects to the **A pin** (Blue wire)
- **GND&nbsp;** connects to the common **C pin&nbsp;** (Gray wire)
- **Pin D9** connects to the **Switch** pin (Yellow wire)

Since the rotary encoder's switch pin side also uses the common ground, I simply connected it to the **C** pin over on the encoder side of the part. This prevents you from connecting another wire all the way from the encoder to the board.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/255/medium800/makecode_fritzFish.png?1565384393)

I soldered silicone stranded hookup wire to the encoder pins on one end and to 90° angle header pins on the other so I could insert them in the PyGamer's Feather headers without protruding too far from the board.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/256/medium800/makecode_IMG_7423.jpg?1565384892)

The additional unused header pins are there simply for mechanical stability of the connections.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/257/medium800/makecode_IMG_7422.jpg?1565384901)

With the battery and speaker also plugged in, we're ready to start programming in MakeCode Arcade!

# Go Fishing with Rotary Encoders

## Rotary Encoder in MakeCode Arcade

## Rotary Encoder Basics

Rotary encoders are very useful, and seem a bit mysterious sometimes. They can spin endlessly in either direction. And, both the speed at which they're turned and the direction they're being turned can be detected and used by the microcontroller, in this case the PyGamer. But how?!

Inside the switch are two contact pints, **A** & **B** , and a perforated disc of multiple common ground contact points, **C**. There's no need for resistors or a voltage pin as we'll use the PyGamer's built in pull-up resistors automatically in the encoder extension.

As the disc spins, say, clockwise, one of the **C** pads touches **A** causing a square wave pulse to go high on the **A** pin. Then, a short moment later, the&nbsp; **C** pad touches **B** causing an pulse on the **B** pin. The PyGamer is able to determine the speed of the rotation by sensing the period of time between the two pulses.

When the knob is turned counterclockwise, the **B** pulse will come first, followed by the **A** pulse, so it is this way that the PyGamer know which direction the rotary encoder is turning.

Info: 

Here is an excellent explainer video from **How to Mechatronics** :

https://www.youtube.com/watch?v=v4BbSzJ-hz4&amp;t=60

## MakeCode Arcade

MakeCode Arcade is a free Microsoft block programming environment designed specifically to make games, but we can also use it for non-game application development. Learning to use MakeCode is easy & fun.

If you're not already familiar with the basics of MakeCode Arcade, [check out this guide](https://learn.adafruit.com/makecode-arcade-pixel-art-sprites/creating-sprites-in-makecode-arcade) on creating a character sprite and moving it with controls.

To start, open a new Chrome browser window (Chrome works best) and go to [MakeCode Arcade](https://arcade.makecode.com/beta#editor) beta.

These MakeCode Arcade guides are designed to take you through the fundamentals before tackling more complex games:

- [Pixel Art](https://learn.adafruit.com/makecode-arcade-pixel-art-sprites)
- [Animation](https://learn.adafruit.com/makecode-arcade-pixel-animation)
- [Level Design](https://learn.adafruit.com/makecode-arcade-platform-level)
- _[Sparky Invaders](https://learn.adafruit.com/makecode-arcade-sparky-invaders)_
- [Next Level Game Techniques](https://learn.adafruit.com/next-level-makecode-arcade-games)

For intermediate-level techniques, check out:

- [Re-MakeCode the Classics: _Arkanoid_](https://learn.adafruit.com/re-makecode-the-classics-arkanoid/overview)
- [Re-MakeCode the Classics: _Py Hunter_](https://learn.adafruit.com/re-makecode-the-classics-spy-hunter/overview)
- [_Trash Panda_](https://learn.adafruit.com/trash-panda-the-game)
- [_Trash Panda 2: Garbage Day_](https://learn.adafruit.com/trash-panda-2-dumpster-dive)
- [_Marble Labyrinth_](https://learn.adafruit.com/pygamer-marble-labyrinth-in-makecode-arcade)

Info: 

## "Crank" in MakeCode Arcade

Partly inspired by the [Playdate](https://play.date/) handheld designed by Panic and Teenage Engineering, the Microsoft MakeCode Arcade team developed a set of **"crank"** blocks to use rotary encoders.

Here's how to add the blocks and use them.

## Add Extensions

First, head to [MakeCode Arcade beta](https://arcade.makecode.com/beta#editor) editor and click on the setting gear wheel menu and click on Extensions.

From the gallery of extensions, we'll add both **controller** and **feather** (you'll need to go to this gallery twice to pick them each individually.)

Now, when we go to the **Controller** category, we'll see the **crank position** block and the **set crank pinA \_\_ pinB \_\_** block are available.

By adding the **Feather** extension, we are able to select any of the exposed pins on the back of the PyGamer!

![makecode_Microsoft_MakeCode_Arcade.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/262/medium640/makecode_Microsoft_MakeCode_Arcade.jpg?1565387220)

![makecode_Microsoft_MakeCode_Arcade02.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/263/medium640/makecode_Microsoft_MakeCode_Arcade02.jpg?1565387437)

![makecode_Microsoft_MakeCode_Arcade_2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/264/medium640/makecode_Microsoft_MakeCode_Arcade_2.jpg?1565388694)

![makecode_Microsoft_MakeCode_Arcade_3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/265/medium640/makecode_Microsoft_MakeCode_Arcade_3.jpg?1565388850)

## Example Code

Here's a very simple program we can create in order to test the rotary encoder in MakeCode Arcade on the PyBadge.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/266/medium800/makecode_Microsoft_MakeCode_Arcade_4.jpg?1565389189)

Note how we've set the crank **pinA** to **A3** and **pinB** to **A2** , which is how we wired the encoder on the previous page.

This creates a piece of delicious cake as a player sprite, and sets its horizontal position to be driven by the rotary encoder's position.

Upload the code to your PyGamer and give it a try now!

https://youtu.be/0loRigfxF6w

Primary: 

![](https://cdn-learn.adafruit.com/assets/assets/000/079/267/medium800/makecode_crankarm2.jpg?1565392240)

## Fishing Reel Crank

Based on the crank design by the Ruiz Bros. [found here](https://www.thingiverse.com/thing:3685385), I remixed it into a spinning reel style crank to use in our fishing game.

You can [download the model here](https://www.thingiverse.com/thing:3800735) and 3D print it. It prints the arm and handle at the same time, but they aren't touching each other, so the handle is free spinning. The crank is designed to press fit onto the rotary encoder shaft.

I printed the case and [followed their build instructions](https://learn.adafruit.com/gaming-handheld-crank/assembly), but decided to leave off the front of the case so I could admire the awesome PyGamer silkscreen!

![](https://cdn-learn.adafruit.com/assets/assets/000/079/268/medium800/makecode_crankcase1.jpg?1565396548)

# Go Fishing with Rotary Encoders

## Fishing Game in MakeCode Arcade

![](https://cdn-learn.adafruit.com/assets/assets/000/079/276/medium800/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade.jpg?1565482587)

## Gone Fishing

Let's load the completed version of _ **Gone Fishing** _ and try it out. Download the **arcade-Gone\_Fishing.png** image cartridge file here by right-clicking on the image and saving it to your computer.

![](https://cdn-learn.adafruit.com/assets/assets/000/079/277/medium800/makecode_arcade-Gone_Fishing.png?1565483077)

## Load the Code

This is a special .png file that contains not only an image, but the entire game is embedded in it as well!

Simply drag it from the location to which you saved the image on your computer (such as the desktop as shown here) onto the Chrome browser window that is already running MakeCode Arcade (MCA). Note that the image in this graphic is of a different game, but you'll be dragging the _Gone Fishing ._png file.

This will open the code into the MCA editor.

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/278/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade.jpg?1565483148)

![makecode_loadCode_Arcade.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/279/medium640/makecode_loadCode_Arcade.jpg?1565483180)

Primary: 

## Play the Game

Download the game onto your PyGamer (it won't play in the simulator window in the browser due to the use of external peripherals).

Here's how you play:

### Casting

- pull back (down) on the thumbpad to lock the reel
- make a casting motion and shake the PyGamer (you'll hear a tone play)
- release the thumbpad to finish casting

Now, wait for a fish to swim by. You can reel the hook up and down with the crank, and you can move the hook and line side to side a bit randomly by clicking the rotary encoder's push switch.

### Reeling

Once you've hooked a fish start reeling it in by rotating the crank forward. You need to reel at a medium pace or you'll loose the fish! The word "GOOD" will display while you're at a good speed, otherwise "TOO FAST" or "TOO SLOW" will pop up and you'll need to correct your speed. If you crank at the wrong speed for too long, the fish gets away and you loose one of five hearts.

## How it Works

Here are the key features of the gameplay mechanic:

![](https://cdn-learn.adafruit.com/assets/assets/000/079/280/medium800/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_2.jpg?1565483741)

## On Start

In the setup, we provide the game splash screen as well as the instruction text blocks.

Next, we'll set the crank pins as we did on the previous example. (You remember the one with the cake, right? Yummy.)

### set pull pin

Since we loaded the **Feather** extension, we have access to the IO pins on the board. We can use the rotary encoder button (momentary switch) which we plugged into the PyGamer's **D9** pin.

In the **Pins** category, you'll find the **set pull pin \_\_ to down** block. Here we've chosen pin **D9** and set the pull up resistor direction to **up.** This means the pin voltage will be normally pulled to **high** , and when the button is pressed the pin will drop to **low.** Later we'll see how to read this stated of the button press.

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/281/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_3.jpg?1565483915)

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_4.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/282/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_4.jpg?1565484364)

### Casting Variables

We set up a few variables to keep track of the reel casting motions, as well as the state of a fish being hooked or not. These are used later to determine things such as which sprites to display, location of the hook and line, and more.

### Background

We also create a background image sprite for our game screen. Note how the water color has been created with a checkerboard dither pattern of dark blue and light blue, which is done to match the water layer we'll look at next so the two transition seamlessly into each other at the top of the water's edge.

## Water Layer

The water layer sprite is also a checkerboard dither pattern, but this time the pattern alternates between light blue pixels and transparent pixels. The overall effect in the game when this sprite is set as the topmost layer in the Z-depth of the screen is that the fish swimming underneath it will appear as if they're under a semi-transparent layer. Since we can't do partial opacity pixels in MakeCode Arcade, this is a useful trick!

When a fish is hooked and reeled in, it will emerge from the water (as it is raised on the Y-axis above the topmost water pixels).

Additionally, as the fish move the will appear to have a bit of extra secondary motion for free, as the details on the fish move under the blue pixels and then reappear in the transparent spots.

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_5.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/283/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_5.jpg?1565487660)

## Painting with Code

In order to create the large dithered water layer, rather than paint one pixel at a time, or use and external image editing tool, I simply did some copying and pasting of the code in the **JavaScript** tab at the top of MakeCode Arcade.

This is what it looks like:

```auto
let waterLayer = sprites.create(img`
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . 9 . . . . . . . . . 9 . 9 . . . . . . . . . . . . . . . . . . . . . . . 9 . 9 . 9 . 9 . 9 . . . . . . . . . . . . . . . . . . . 9 . . . . . . . . . . . 9 . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . 9 . 9 . . . . . . . 9 . 9 . 9 . 9 . . . . . . . . . . . . . . . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . . . . . . . . . . . . . . . . . . . 9 . 9
    . . . . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . . . . . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . . . . . . . . . . . 9 . 9 . 9 . 9 . 9 .
    . . . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . . . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . . . . . . . . . 9 . 9 . 9 . 9 . 9 . 9
    9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . . . . . . . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 .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 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 .
    . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9
    9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 . 9 .
`, SpriteKind.setDressing)
```

## Hook and Line

The hook and line sprites are made of two separate sprites so we can detect collisions between the fish and the hook, while ignoring the line.

All position settings when casting and reeling will be applied to the hook, while the line will simply follow along. To keep this simple, both sprites are the same dimensions, even though the hook is much smaller than the line vertically.

![makecode_hooline.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/286/medium640/makecode_hooline.jpg?1565487567)

## Spawn Fish

We've used two **functions** with associated **on game update every \_\_\_ ms** blocks to create our fish with some randomness of spawn rate and velocity.

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_6.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/284/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_6.jpg?1565487593)

## Casting

In order to cast the line, it's a three step process. The **on down button pressed** block begins the process by checking that the line isn't already cast, then sets the **triggered** variable to **true.**

The **prevCrank** variable is used to store the current value of the **crank position** of the rotary encoder, which will be used later to offset the raw value from where we want to place the hook on the screen.

We set the **hook** and **line** sprites to blank, as if they're over the player's head and behind them as they prepare to cast the line. We also play a low tone.

When the player shakes the PyGamer, the **on shake** block flips the **thrown** variable to **true** so that the game will then pay attention to the release of the down button. It also plays a high tone.

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_7.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/285/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_7.jpg?1565487618)

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_11.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/290/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_11.jpg?1565506661)

Finally, when the **on down button released** block runs it resets the **thrown** and **triggered** variables, sets the hook to a random position on the X-axis, makes the sprites visible again, and plays a different tone. It also sets the **cast** variable true, which is what allows the next important code to run.

If the player wants to try moving the line side to side, they can press the rotary encoder push button in. This will cause the **digital read pin D9** block to return a **Low** or **false** signal, and then the **hook x** value will be set to a random position.

## Cranking and Hooking

This **forever** loop is always running. When the game starts, the **cast** variable is **false,** &nbsp;so the hook and line are set near the top of the screen.

The hook and line are sent to the bottom of the lake when cast. Then if a fish is hooked, the sprite will change from a swimming fish to a **hookedFish** sprite. It is set to **auto destroy** so that it will disappear when successfully reeled in.

When the line has been **cast,** we set the **crankScaling** variable to **4** (you can adjust if needed) and is used as a multiplier on the number of encoder rotations needed to move the hook. As the rotary encoder is turned, the **crank position** is updated and the **hook** sprite's&nbsp; **y&nbsp;** position is set to the&nbsp; **crank position&nbsp;** minus the&nbsp; **prevCrank&nbsp;** position, divided by the&nbsp; **crankScaling&nbsp;** value and then an offset of 45 is added to get the **hook** lower down.&nbsp;

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_10.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/287/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_10.jpg?1565488056)

 **Hooking a Fish**

When the **hook** player sprite overlaps either an **orangeFish** or **yellowFish** if one hasn't already been **hooked** and **caught** , the original fish sprite is destroyed so the hooked fish sprite can take its place. We also set the **fightCounter** to **0** which will be used during reeling to determine when the fish or fisherperson has won!

![makecode_Screenshot_8_10_19__11_52_PM.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/289/medium640/makecode_Screenshot_8_10_19__11_52_PM.jpg?1565506430)

## Cranking Battle

Trying to reel in a fish can be hard! To simulate this in the game, we use this **game update every 150ms** block and check if the player is rotating too fast (more than 10 **crank position** value changes per 150ms) or too slow (fewer than 5 **crank position** value changes per 150ms).

Note that these values are set to negative values because of the pin order of the rotary encoder. If the encoder pins were swapped these would be positive value changes.

At each 150ms check, if the **change** value isn't in the 5-10 range, then the **fightCounter** is increased by 1. When the **fight counter** is greater than **30,** the fish gets away!

&nbsp;

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_11.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/288/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_11.jpg?1565506132)

 **Fish Catch or Escape**

We'll use the **on destroyed sprite of kind Food** to react to a fish either being reeled off the screen or getting away.

First, we'll reset all of the casting checks

Then, if the fish **gotAway** we play the sad power down sound, splash the text "That one got away.", and subtract one from the life counter

If the fish didn't get away, then we increase the score by 1 for orange fish or 2 for the rarer yellow fish.

![makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_12.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/291/medium640/makecode_Banners_and_Alerts_and_Microsoft_MakeCode_Arcade_12.jpg?1565507149)

The&nbsp; **ba ding&nbsp;** sound is played, and then we show the long text congratulating the player on catching the fish, and reporting the fish's weight from a random number to text conversion block.

Everything is reset and they can start fishing again!

https://www.youtube.com/watch?v=q1k2WJmluo4

# Go Fishing with Rotary Encoders

## Update the PyBadge/PyGamer Bootloader

You are at the bleeding edge of handheld, open source, game playing hardware and software, what with your PyBadge/PyBadge LC or PyGamer! Congratulations! It's fun and exciting! It is also changing and improving all the time, so please update your bootloaders before proceeding to put your MakeCode Arcade games on the board!!

Info: 

## PyBadge/PyBadge LC Bootloader

If you have a **PyBadge** or **PyBadge LC** , [please go to this page for instructions on updating the bootloader.](https://learn.adafruit.com/adafruit-pybadge/updating-the-bootloader)

![gaming_pyb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/076/276/medium640/gaming_pyb.jpg?1559330072)

## PyGamer Bootloader

If you have a **PyGamer** , [please go to this page for instructions on updating the bootloader.](https://learn.adafruit.com/adafruit-pygamer/updating-the-bootloader)

![gaming_pyg.jpg](https://cdn-learn.adafruit.com/assets/assets/000/076/277/medium640/gaming_pyg.jpg?1559330110)

Danger: 

## Hardware Checks

If, after updating your board's bootloader, you still think you may have a hardware problem, here's a great way to test out all of the functions. From buttons, to the light sensor, thumbstick (PyGamer only), accelerometer (PyGamer and PyBadge only, not the LC), and more, we've got a super nifty set of hardware test .UF2 files you can use.

Click on the link for your board below for more info and a link to the appropriate UF2 file.

[PyBadge/PyBadge LC Hardware Check](https://learn.adafruit.com/adafruit-pybadge/arduino-test)
[PyGamer Hardware Check](https://learn.adafruit.com/adafruit-pygamer/arduino-test)
Another way to do a hardware check is with the handy, dandy MakeCode Arcade Basic Hardware Test. This was created with MakeCode Arcade and you can use it to check that your d-pad buttons or thumb joystick can move the yellow face around the screen, and that the A and B buttons work to play a sound (just make sure you have a speaker plugged in to the PyGamer first).

You can [open this link](https://makecode.com/_icwXcg4PWRYW) to get to it, or download the UF2 file below and drag it onto your board's USB drive in bootloader mode.

[arcade-Basic-Hardware-Test.UF2](https://cdn-learn.adafruit.com/assets/assets/000/076/316/original/arcade-Basic-Hardware-Test-PyBadge_and_PyGamer.uf2?1559345409)
![](https://cdn-learn.adafruit.com/assets/assets/000/076/317/medium800/gaming_hwtest.png?1559345457)

# Go Fishing with Rotary Encoders

## Load a MakeCode Game on PyGamer/PyBadge

Let's load a game! For example, here's a link to **Run, Blinka, Run!&nbsp;** To open the game in the MakeCode Arcade editor, first, click the share link below. This will allow you to play the game in the browser right away.

[Makecode Arcade Game: Run, Blinka, Run!](https://makecode.com/_Y90aTaiHfh41)
Then, click on the&nbsp;Show Code&nbsp;button in the upper left corner. The shows the code for the game, and by clicking the&nbsp;Edit&nbsp;button in the upper right corner, it'll open into the editor where you can upload it to your PyGamer/PyBadge.

Once you have a game working on the MakeCode Arcade web editor, it's time to download it and flash it onto your board.

![adafruit_products_Run_Blinka_Run__-_Microsoft_MakeCode_2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/078/777/medium640/adafruit_products_Run_Blinka_Run__-_Microsoft_MakeCode_2.jpg?1564457638)

![adafruit_products_Run_Blinka_Run__-_Microsoft_MakeCode_3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/078/778/medium640/adafruit_products_Run_Blinka_Run__-_Microsoft_MakeCode_3.jpg?1564457679)

Primary: 

## Board Definition

In order to load a game made in MakeCode Arcade onto the PyBadge, first choose the proper board definition inside of MakeCode. Click the ellipsis (...) next to DOWNLOAD and then the **Choose Hardware** item.

![adafruit_products_MakeCode_choose_hardware.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/981/medium640/adafruit_products_MakeCode_choose_hardware.jpg?1644859647)

## Change Board screen

Click on the image of your board, either the PyBadge/PyBadge LC or the PyGamer

![adafruit_products_MakeCode_Arcade.jpg](https://cdn-learn.adafruit.com/assets/assets/000/078/781/medium640/adafruit_products_MakeCode_Arcade.jpg?1564458209)

This will cause the game .uf2 file for your particular board to be saved to your hard drive. You only need to do this the first time you use a new board. Thereafter you can simply click the **Download** button on the MakeCode Arcade editor page.

![](https://cdn-learn.adafruit.com/assets/assets/000/074/943/medium800/gaming_downloaded.png?1556169879)

Danger: 

## Bootloader Mode

Now, we'll put the board into bootloader mode so we can drag on the saved .uf2 file. On the back side of the board you'll see a reset button at the top. Make sure the board is plugged into your computer via USB with a USB micro B to A data cable. Also, be sure the board is turned on.

&nbsp;

Then, press the reset button. This will initiate bootloader mode.

&nbsp;

When the board is in bootloader mode you'll see a screen similar to this one show up.

![gaming_IMG_5427.jpg](https://cdn-learn.adafruit.com/assets/assets/000/074/945/medium640/gaming_IMG_5427.jpg?1556170490)

![gaming_IMG_5428.jpg](https://cdn-learn.adafruit.com/assets/assets/000/074/991/medium640/gaming_IMG_5428.jpg?1556308393)

![gaming_IMG_5429.jpg](https://cdn-learn.adafruit.com/assets/assets/000/074/992/medium640/gaming_IMG_5429.jpg?1556308428)

## Drag and Drop

Now that the board is in bootloader mode, you should see a **BADGEBOOT** drive show up on your computer as a USB flash drive. Simply drag the arcade game .uf2 file onto the drive.

![gaming_dragtoPyBadge.jpg](https://cdn-learn.adafruit.com/assets/assets/000/074/944/medium640/gaming_dragtoPyBadge.jpg?1556308458)

## Play!

That's all there is to it! Once the file is copied over the board will restart and launch the game!

![](https://cdn-learn.adafruit.com/assets/assets/000/074/948/medium800/gaming_IMG_5430.jpg?1556170587)

https://youtu.be/au5w1sLjsaU

Keep an eye on Adafruit.com for additional game related content.

# Go Fishing with Rotary Encoders

## Troubleshooting MakeCode Arcade

If you run into trouble with MakeCode Arcade, here are some resources for getting help:

- [Microsoft MakeCode Arcade Forum](https://forum.makecode.com/c/Share-your-Arcade-projects-here)
- [Adafruit MakeCode Forum](https://forums.adafruit.com/viewforum.php?f=64)
- [Microsoft MakeCode Arcade Discord](https://aka.ms/makecodecommunity) -- look for the #arcade channel
- [Adafruit MakeCode Discord](https://adafru.it/discord) -- look for the #makecode channel

Primary: 


## Featured Products

### Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

[Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino](https://www.adafruit.com/product/4242)
What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the **Adafruit PyGamer!** We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4242)
[Related Guides to the Product](https://learn.adafruit.com/products/4242/guides)
### Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino

[Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino](https://www.adafruit.com/product/4200)
What's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino? That's right, its the **Adafruit PyBadge!** We wanted to see how much we could cram into a ​3 3⁄8 × ​2 1⁄8 inch rounded rectangle, to make an all-in-one dev board with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4200)
[Related Guides to the Product](https://learn.adafruit.com/products/4200/guides)
### Rotary Encoder + Extras

[Rotary Encoder + Extras](https://www.adafruit.com/product/377)
This rotary encoder is the best of the best, it's a high-quality 24-pulse encoder, with detents and a nice feel. It is panel mountable for placement in a box, or you can plug it into a breadboard (just cut/bend the two mechanical side tabs.) We also include a nice soft-touch knob with an...

In Stock
[Buy Now](https://www.adafruit.com/product/377)
[Related Guides to the Product](https://learn.adafruit.com/products/377/guides)
### Lithium Ion Polymer Battery with Short Cable - 3.7V 350mAh

[Lithium Ion Polymer Battery with Short Cable - 3.7V 350mAh](https://www.adafruit.com/product/4237)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 350mAh for a total of about 1.3 Wh. If you need a larger (or smaller!) battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4237)
[Related Guides to the Product](https://learn.adafruit.com/products/4237/guides)
### Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt

[Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt](https://www.adafruit.com/product/4227)
Hear the good news! This wee speaker&nbsp;is&nbsp;a&nbsp;great addition to any audio project where you need 8 ohm impedance and 1W or less of power. We particularly like this&nbsp;speaker&nbsp;as it is&nbsp;small and comes with nice skinny wires with a connector on the end. It has a handy...

In Stock
[Buy Now](https://www.adafruit.com/product/4227)
[Related Guides to the Product](https://learn.adafruit.com/products/4227/guides)
### Break-away 0.1" 36-pin strip right-angle male header (10 pack)

[Break-away 0.1" 36-pin strip right-angle male header (10 pack)](https://www.adafruit.com/product/1540)
Breakaway header is like the duct tape of electronics. Its great for connecting things together, soldering to perf-boards, fits into any breadboard, etc. We go through these guys real fast, and thought that given how handy they are, we'd offer them in a pack of ten!  
  
Each pack...

In Stock
[Buy Now](https://www.adafruit.com/product/1540)
[Related Guides to the Product](https://learn.adafruit.com/products/1540/guides)
### Silicone Cover Stranded-Core Wire - 26AWG in Various Colors

[Silicone Cover Stranded-Core Wire - 26AWG in Various Colors](https://www.adafruit.com/product/1970)
Silicone-sheathing wire is super-flexible and soft, and it's also strong! Able to handle up to 200°C and up to 600V, it will do when PVC covered wire wimps out. We like this wire for being extremely supple and flexible, so it is great for wearables or projects where the wire-harness...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1970)
[Related Guides to the Product](https://learn.adafruit.com/products/1970/guides)
### Filament for 3D Printers in Various Colors and Types

[Filament for 3D Printers in Various Colors and Types](https://www.adafruit.com/product/2080)
Having a 3D printer without filament is sort of like having a regular printer without paper or ink. &nbsp;And while a lot of printers come with some filament there's a good chance you've been printing up a storm and need something new. &nbsp;That's why we've started carrying a...

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

## Related Guides

- [Adafruit PyBadge and PyBadge LC](https://learn.adafruit.com/adafruit-pybadge.md)
- [Introducing Adafruit PyGamer](https://learn.adafruit.com/adafruit-pygamer.md)
- [PyBadger Event Badge](https://learn.adafruit.com/pybadger-event-badge.md)
- [Game & Watch Octopus](https://learn.adafruit.com/game-watch-octopus.md)
- [Creating Your First Tilemap Game with CircuitPython](https://learn.adafruit.com/creating-your-first-tilemap-game-with-circuitpython.md)
- [NES Emulator for Arcada](https://learn.adafruit.com/nes-emulator-for-arcada.md)
- [Program CircuitPython USB Devices with iPhone & iPad](https://learn.adafruit.com/use-circuitpython-devices-with-iphone-ipad.md)
- [Trash Panda 2: Garbage Day](https://learn.adafruit.com/trash-panda-2-dumpster-dive.md)
- [MLX90640 Thermal Camera with Image Recording](https://learn.adafruit.com/mlx90640-thermal-image-recording.md)
- [Playing Gamebuino META Games on Arcada](https://learn.adafruit.com/playing-gamebuino-meta-games-on-arcada.md)
- [Use circup to easily keep your CircuitPython libraries up to date](https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup.md)
- [Playing Arduboy Games on Arcada](https://learn.adafruit.com/playing-arduboy-games-on-arcada.md)
- [How to train new TensorFlow Lite micro speech models](https://learn.adafruit.com/how-to-train-new-tensorflow-lite-micro-speech-models.md)
- [Next Level MakeCode Arcade Games](https://learn.adafruit.com/next-level-makecode-arcade-games.md)
- [PyGamer Marble Labyrinth in MakeCode Arcade](https://learn.adafruit.com/pygamer-marble-labyrinth-in-makecode-arcade.md)
- [Creating Custom Symbol Fonts for Adafruit GFX Library](https://learn.adafruit.com/creating-custom-symbol-font-for-adafruit-gfx-library.md)
- [Custom Color Palettes for MakeCode Arcade Games](https://learn.adafruit.com/custom-color-palettes-for-makecode-arcade-games.md)
