# Adabot Operation Game

## Overview

https://youtu.be/0URbv7UFebI

![](https://cdn-learn.adafruit.com/assets/assets/000/059/275/medium800/gaming_IMG_0487_2k_b.jpg?1534460728)

Adabot needs your help, Doctor! It's time to operate!! It takes a steady hand to remove the game pieces!

You can build this fun, classic game using a Circuit Playground Express to react whenever your hand isn't so steady and your tweezers bump the edge of an opening. You'll build the board, and then program the Circuit Playground Express using CircuitPython or MakeCode to test the capacitive touch pads for contact.

A tip of the hat goes to Maker Camp for their i[nspiring project](https://makercamp.com/projects/makey-makey-makey-operation) using the [Makey Makey](https://www.adafruit.com/product/1068) board.

## Parts

To build this project you'll need the parts below, as well as a computer for programming and uploading code to the Circuit Playground Express.

### Part: Circuit Playground Express
quantity: 1
Round, Awesome Microcontroller Board
[Circuit Playground Express](https://www.adafruit.com/product/3333)

### Part: Copper Foil Tape
quantity: 1
25mm x 15 meter roll
[Copper Foil Tape](https://www.adafruit.com/product/1127)

### Part: Short Wire Alligator Clip Test Leads
quantity: 1
Set of 12
[Short Wire Alligator Clip Test Leads](https://www.adafruit.com/product/1592)

### Part: 3x AAA Battery Holder
quantity: 1
with On/Off Switch and 2-Pin JST
[3x AAA Battery Holder](https://www.adafruit.com/product/727)

### Part: Alkaline AAA batteries
quantity: 1
3 pack
[Alkaline AAA batteries](https://www.adafruit.com/product/3520)

### Part: Black Nylon Screw and Stand-off Set
quantity: 1
M2.5 Thread
[Black Nylon Screw and Stand-off Set](https://www.adafruit.com/product/3299)

### Part: USB Cable
quantity: 1
A/MicroB - 3ft
[USB Cable](https://www.adafruit.com/product/592)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/351/medium800/gaming_IMG_0366_2k_b.jpg?1534523756)

## Materials & Tools

In addition to the parts listed above, you'll also need:

- Small cardboard box, such as an Adafruit shipping box
- Metal tweezers
- Color printer with white paper or cardstock
- Hobby knife or scissors
- Glue stick
- Scotch tape
- Small Philips screwdriver

# Adabot Operation Game

## Build the Operating Table

![](https://cdn-learn.adafruit.com/assets/assets/000/059/352/medium800/gaming_IMG_0366_2k_b.jpg?1534523780)

## Print the Board and Pieces

Use a color laser or inkjet printer to print the file linked here onto a piece of white cardstock. Be sure to print without any image scaling so that the parts will align.

[Adabot_Operation_Game.pdf](https://cdn-learn.adafruit.com/assets/assets/000/059/293/original/Adabot_Operation_Game.pdf?1534461127)
![](https://cdn-learn.adafruit.com/assets/assets/000/059/334/medium800/gaming_adabotOperation.png?1534465491)

Info: 

## Mount the Board

&nbsp;

- Cut out the board image  
&nbsp;
- Glue it to the top of a cardboard box. An Adafruit shipping box may be large enough or find another box approximately the size of the board or larger.

![gaming_IMG_0367_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/290/medium640/gaming_IMG_0367_2k.jpg?1534460988)

![gaming_IMG_0368_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/291/medium640/gaming_IMG_0368_2k.jpg?1534460995)

![gaming_IMG_0369_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/292/medium640/gaming_IMG_0369_2k.jpg?1534461004)

## Cut the Openings

&nbsp;

- Use a hobby knife to cut out the board image and cardboard lid of your box at all of the indicated "incision" points  
&nbsp;
- Also cut out the holes for the Circuit Playground Express mounting points and touch pads so we can connect alligator clips to them later from below the board

![gaming_IMG_0371_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/294/medium640/gaming_IMG_0371_2k.jpg?1534461144)

![gaming_IMG_0372_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/295/medium640/gaming_IMG_0372_2k.jpg?1534461155)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/296/medium800/gaming_IMG_0415_2k_b.jpg?1534461521)

## Add Copper Tape Contacts

The copper tape is what we'll use to detect errant tweezers touches, by running it around the edges of each incision hole. Each tape site will be connected to the Circuit Playground Express via an alligator clip lead.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/305/medium800/gaming_IMG_0432_2k.jpg?1534461867)

- Cut out a piece of copper tape that is just a bit bigger than the opening
- Press it down to fit and to indicate the hole below
- Slit the tape along the top and bottom edges
- Slit the tape vertically up the center as shown
- Push the two flaps down into the hole
- Repeat for each of the seven part holes

![gaming_IMG_0420_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/297/medium640/gaming_IMG_0420_2k.jpg?1534461608)

![gaming_IMG_0422_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/299/medium640/gaming_IMG_0422_2k.jpg?1534461691)

![gaming_IMG_0423_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/300/medium640/gaming_IMG_0423_2k.jpg?1534461696)

![gaming_IMG_0425_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/301/medium640/gaming_IMG_0425_2k.jpg?1534461715)

![gaming_IMG_0427_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/302/medium640/gaming_IMG_0427_2k.jpg?1534461721)

![gaming_IMG_0429_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/303/medium640/gaming_IMG_0429_2k.jpg?1534461730)

![gaming_IMG_0430_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/304/medium640/gaming_IMG_0430_2k.jpg?1534461739)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/306/medium800/gaming_IMG_0433_2k.jpg?1534461904)

## Tape Connector Tabs

&nbsp;

Inside each taped hole, connect another short strip of copper tape as shown. This is where each alligator clip will connect.

![gaming_IMG_0394_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/307/medium640/gaming_IMG_0394_2k.jpg?1534462002)

![gaming_IMG_0395_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/308/medium640/gaming_IMG_0395_2k.jpg?1534462008)

![gaming_IMG_0396_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/309/medium640/gaming_IMG_0396_2k.jpg?1534462014)

![gaming_IMG_0398_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/310/medium640/gaming_IMG_0398_2k.jpg?1534462025)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/311/medium800/gaming_IMG_0437_2k.jpg?1534462056)

## Inner Boxes

&nbsp;

- Next, cut out the papercraft boxes from the printed sheet. (Yours may vary in color from the ones shown here)
- Cut along the solid lines
- Fold along the dotted lines -- the outer set will be "mountain" folded to form a lip, the inner set a "valley" fold to form the walls -- see the picture for proper fold directions
- Tape the boxes under each hole as shown

&nbsp;

![gaming_IMG_0438_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/312/medium640/gaming_IMG_0438_2k.jpg?1534462076)

![gaming_IMG_0439_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/313/medium640/gaming_IMG_0439_2k.jpg?1534462176)

![gaming_IMG_0440_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/314/medium640/gaming_IMG_0440_2k.jpg?1534462183)

![gaming_IMG_0441_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/315/medium640/gaming_IMG_0441_2k.jpg?1534462243)

![gaming_IMG_0442_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/316/medium640/gaming_IMG_0442_2k.jpg?1534462248)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/335/medium800/gaming_adabotBox.png?1534465511)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/317/medium800/gaming_IMG_0443_2k.jpg?1534462570)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/318/medium800/gaming_IMG_0446_2k.jpg?1534462580)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/320/medium800/gaming_IMG_0447_2k.jpg?1534462604)

## Add Circuit Playground Express

You'll now add the Circuit Playground Express by fastening it to the board with four medium screws and nuts.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/321/medium800/gaming_IMG_0448_2k.jpg?1534462758)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/322/medium800/gaming_IMG_0449_2k.jpg?1534462766)

## Connect the Alligator Clips

Follow the images here to connect the Circuit Playground Express capacitive touch pads to the copper tape tabs.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/323/medium800/gaming_IMG_0451_2k.jpg?1534462844)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/324/medium800/gaming_IMG_0452_2k.jpg?1534462850)

## Game Pieces

&nbsp;

- Glue the game pieces section of the printout to a piece of scrap cardboard
- Cut out the pieces with a hobby knife or scissors

![gaming_IMG_0460_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/325/medium640/gaming_IMG_0460_2k.jpg?1534462926)

![gaming_IMG_0461_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/326/medium640/gaming_IMG_0461_2k.jpg?1534462934)

![gaming_IMG_0483_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/327/medium640/gaming_IMG_0483_2k.jpg?1534462941)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/336/medium800/gaming_adabotPieces.png?1534465536)

Primary: 

[Adabot_Operation_Game_Pieces.stl](https://cdn-learn.adafruit.com/assets/assets/000/059/328/original/Adabot_Operation_Game_Pieces.stl?1534463701)
Next, we'll program the Circuit Playground Express in CircuitPython, or you can skip ahead to program it with MakeCode.

# Adabot Operation Game

## Code with CircuitPython

![](https://cdn-learn.adafruit.com/assets/assets/000/059/337/medium800/gaming_IMG_0498_2k.jpg?1534465574)

The key feature of Operation is that the lights and buzzers alarm whenever your tweezers touch the edge of a hole. We've connected the copper tape at each hole to a capacitive touch pad on the Circuit Playground Express -- now we want to code the board in CircuitPython to react.

Primary: 

## CircuitPython Setup

To get started, you'll want to set up the Circuit Playground Express for use with CircuitPython by [following this guide](https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart). When you're ready, and can upload code to the board return here.

Adafruit really likes using the Mu editor to edit the CircuitPython code. [See this guide on loading and using Mu](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

## Code

You can copy the code here and then paste it into Mu. Save it to your Circuit Playground Express as **code.py**

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

## Code Breakdown

### Libraries

Here's what's going on in the code. First, we import the `board, touchio,` and `adafruit_circuitplayground.express` libraries. These give us the commands we need to address the board and it's capacitive touch pads, as well as the NeoPixels by using the `cpx` commands.

(Note that the `time` library import is commented out, you will uncomment this if later you decide to check your raw touch values, which is covered later.)

```auto
import board
import touchio
from adafruit_circuitplayground.express import cpx
# import time  # uncomment if testing raw read values

```

### Lists and Touchpads

Next, we'll create a list of the board's cap touch pins and initialize them as **touchio** touch pads. And, we'll set the touch threshold to 3500. This can be tuned later.

```auto
cap_pins = (board.A1, board.A2, board.A3, board.A4, board.A5,
            board.A6, board.A7)

touch_pads = []

for i in range(7):
    touch_pads.append(touchio.TouchIn(cap_pins[i]))

for touch_pad in touch_pads:
    touch_pad.threshold = 3500 
```

### Color Lists

We'll create a set of variables for different colors and their values. Then, we'll create a list of those colors called ... **COLORS**. This way we can associate an index number for each touch pad to a color in the list.

```auto
MAGENTA = (10,  0, 10)
VIOLET =  ( 5,  0, 15)
BLUE =    ( 0,  0, 20)
CYAN =    ( 0, 10, 10)
GREEN =   ( 0, 20,  0)
YELLOW =  (10, 10,  0)
ORANGE =  (15,  5,  0)
RED =     (20,  0,  0)
WHITE =   ( 3,  3,  3)

COLORS = [MAGENTA, VIOLET, BLUE, CYAN, GREEN, YELLOW, ORANGE, RED, WHITE]
```

### NeoPixel Fill

We'll then fill all of the on-board NeoPixels white with this command:

`cpx.pixels.fill(WHITE)`

### The Loop

Now that everything is set up, we have the main loop of the program. What happens here is that we'll iterate through each of the seven pads, checking to see if their value is above the threshold. If it is, we fill the NeoPixels red, play a buzzer sound, and then fill the pixels to the color associated with that pad.

```auto
while True:

    for i in range(7):

        # uncomment this block to check the raw touch pad values
        # print("raw %s value for pad " % i)
        # print(touch_pads[i].raw_value)
        # time.sleep(.5)

        if touch_pads[i].value:
            print("Touched %s" % i)
            cpx.pixels.fill(RED)
            cpx.play_tone(660, 0.7)
            cpx.pixels.fill(COLORS[i])
```

### Threshold Tuning

Note the section in the code above that is commented out. If you uncomment it by removing the leading pound symbols (`#`) you can watch the raw touch values being printed in the Mu REPL or other serial terminal connected to your Circuit Playground Express. Watch for the typical values when not being touched and then the values when they are touched.

If, say, the pads typically read around 2000 but then shoot up to 4000 when you touch them with your tweezers, you could set the threshold to 3500.

With the code uploaded to the board, you're ready to play!

# Adabot Operation Game

## Code with MakeCode

If you'd prefer to code the Adabot Operation Game with MakeCode, this is the page for you!

## Getting Started with MakeCode

If you're new to MakeCode, [head to this guide to get started](https://learn.adafruit.com/makecode). Once you're able to upload MakeCode to your Circuit Playground Express, return here.

## Operation MakeCode

The key feature of Operation is that the lights and buzzers alarm whenever your tweezers touch the edge of a hole. We've connected the copper tape at each hole to a capacitive touch pad on the Circuit Playground Express -- now we want to code the board in MakeCode to react.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/366/medium800/gaming_makecodeOperation.png?1534534782)

## On Start

First, we set all the pixels to white, with the **set all pixels** block from the **NEOPIXEL** category **.**

Then set the capacitive touch threshold on all pins to 1000 with the&nbsp; **button pin A1 set threshold 200&nbsp;** block found in the&nbsp; **INPUT** category.&nbsp; You can adjust this value as needed in case your tweezers aren't causing the copper tape and alligator jumper wire antennae to trigger!

## Per Pin Block

The rest of the code is very simple! We're going to create an **on button A click** block from the **INPUT** category and then change it to **on pin A1 down**. This is how you can test a pad for a capacitive touch event.

Inside this block we'll set the pixels red when the pad has triggered, and then play a tone. Finally, we'll change the pixels to a unique color, in this case, magenta.

Simply duplicate this block six times, changing each one to use a different pad from A2-A7, and adjusting the colors. That's all there is to it!

Click this button to open the live MakeCode session in your browser.

[Adabot Operation Game MakeCode](https://makecode.com/_MLia22Rv1bP7)
# Adabot Operation Game

## Operate!

https://youtu.be/fAAuGiFeGIc

![](https://cdn-learn.adafruit.com/assets/assets/000/059/330/medium800/gaming_IMG_0509_2k.jpg?1534465396)

To play the game, plug in the battery pack and then turn it on. Load the pieces into their holes. Then, with a steady hand, try removing each piece using the tweezers! If you touch the sides and the buzzer goes off, your turn ends! See who can collect the most pieces.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/331/medium800/gaming_IMG_0506_2k.jpg?1534465421)

https://youtu.be/0URbv7UFebI

![](https://cdn-learn.adafruit.com/assets/assets/000/059/332/medium800/gaming_IMG_0492_2k.jpg?1534465434)

![](https://cdn-learn.adafruit.com/assets/assets/000/059/333/medium800/gaming_IMG_0494_2k.jpg?1534465442)

Info: 


## Featured Products

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

Out of Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
### Copper Foil Tape with Conductive Adhesive - 25mm x 15 meter roll

[Copper Foil Tape with Conductive Adhesive - 25mm x 15 meter roll](https://www.adafruit.com/product/1127)
Copper tape can be an interesting addition to your toolbox. The tape itself is made of thin pure copper so its extremely flexible and can take on nearly any shape. You can easily solder to it, and the tape itself can carry current just like a wire. On the back is an electrically conductive...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1127)
[Related Guides to the Product](https://learn.adafruit.com/products/1127/guides)
### Short Wire Alligator Clip Test Lead (set of 12)

[Short Wire Alligator Clip Test Lead (set of 12)](https://www.adafruit.com/product/1592)
Connect this to that without soldering using these handy mini alligator clip test leads. Approximately 4.5" overall cables with alligator clip on each end, color coded. You get 12 pieces in 6 colors. Strong and grippy, these always come in handy! We often use these in conjunction with a...

In Stock
[Buy Now](https://www.adafruit.com/product/1592)
[Related Guides to the Product](https://learn.adafruit.com/products/1592/guides)
### Black Nylon Machine Screw and Stand-off Set – M2.5 Thread

[Black Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)
Totaling 380 pieces, this **M2.5 Screw Set** &nbsp;is a must-have for your workstation.&nbsp;You'll have enough screws, nuts, and hex standoffs to fuel your maker tendencies&nbsp;for days on end! M2.5 size screws fit almost all of the Adafruit breakout/dev board mounting holes...

In Stock
[Buy Now](https://www.adafruit.com/product/3299)
[Related Guides to the Product](https://learn.adafruit.com/products/3299/guides)
### 3 x AAA Battery Holder with On/Off Switch and 2-Pin JST

[3 x AAA Battery Holder with On/Off Switch and 2-Pin JST](https://www.adafruit.com/product/727)
This battery holder connects 3 AAA batteries together in series for powering all kinds of projects. We spec'd these out because the box is slim, and 3 AAA's add up to about 3.3-4.5V, a very similar range to Lithium Ion/polymer (Li-Ion) batteries and have an on-off switch. That makes...

In Stock
[Buy Now](https://www.adafruit.com/product/727)
[Related Guides to the Product](https://learn.adafruit.com/products/727/guides)
### Alkaline AAA batteries - 3 pack

[Alkaline AAA batteries - 3 pack](https://www.adafruit.com/product/3520)
Battery power for your portable project! These batteries are good quality at a good price, and work fantastic with any of the kits or projects in the shop that use AAA's. This is a pack of **3 AAA batteries**.  
  
These batteries are Alkaline (MnO2) chemistry, with a...

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

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Installing Microsoft MakeCode for Adafruit](https://learn.adafruit.com/installing-makecode-for-adafruit.md)
- [Circuit Playground Express Automatic Sunglasses](https://learn.adafruit.com/circuit-playground-express-auto-sunglasses.md)
- [LEGO Compatible Crickit Rover](https://learn.adafruit.com/lego-compatible-crickit-rover.md)
- [PyPortal Weather Station](https://learn.adafruit.com/pyportal-weather-station.md)
- [Illuminated City Skyline with MakeCode](https://learn.adafruit.com/city-skyline-with-makecode-for-cpx.md)
- [HalloWing M4 Animated Eye Candy Bowl](https://learn.adafruit.com/hallowing-m4-candy-bowl.md)
- [Lucky Cat with Circuit Playground Express](https://learn.adafruit.com/lucky-cat-with-circuit-playground-express.md)
- [Color Spinner Camera Ring Light ](https://learn.adafruit.com/camera-ring-light-with-cpx.md)
- [DAC Hacks for Circuit Playground Express & other ATSAMD21 Boards](https://learn.adafruit.com/circuit-playground-express-dac-hacks.md)
- [Remote Control Candy Dispenser Ghost](https://learn.adafruit.com/ble-claw.md)
- [Crickit Powered Holiday Diorama](https://learn.adafruit.com/crickit-powered-holiday-diorama.md)
- [Cardboard Circuit Playground Express Inchworm Robot](https://learn.adafruit.com/cardboard-robot-inchworm.md)
- [CircuitPython Powered AT Hand-Raiser](https://learn.adafruit.com/at-hand-raiser.md)
- [Automatic Mechanical Watch Winder](https://learn.adafruit.com/automatic-mechanical-watch-winder.md)
- [NeoPixel Mini VU Meter](https://learn.adafruit.com/neopixel-mini-vu-meter.md)
