teaching machines

CS 491: Meeting 1 – Push Button

February 4, 2020 by . Filed under gamedev, lectures, spring-2020.

Dear students:

Welcome to CS 491! The Registrar doesn’t really give this elective class a name, but between you and me, I’m calling it Game Development and Physical Computing. The Game Development part means we’re going to be making games. The Physical Computing part means we’re going to be assembling hardware. That hardware will sense the world in order to control our games.


First, let’s address some expectations for this course:

Weekly Plan

Each week will look like this:


Let’s make a game—one that uses hardware. The simplest piece of interactive hardware that exists is the push button switch. Surely we can make a game with just one button? When the button is pressed, let’s just have the boss disappear.


The first step is to assemble our controller’s circuit. Your instructor will provide you with a collection of hardware. For input, we’ll use a standard push button. Inspect the one that your instructor has provided. You’ll see it has four pins. We will use just two that are on the same side. Electrons will flow in one and out the other when the button is pressed.

Follow these steps to build your circuit:

All told, your controller should look like this:


An Arduino is a miniature computer. It runs a single program, its firmware, which we write on a standard computer and then upload.

Our program must contain definitions for two functions: setup and loop. In setup, we initialize state and any global variables. In loop, we do the ongoing work of reading pins and communicating back to the computer.

Follow these steps to get your firmware up and running:

Note that the function is called loop, but it doesn’t actually contain a loop. The Arduino tooling automatically inserts a main function that effectively looks like this:

void main() {
  while (true) {

But you don’t write this main.

Now we’re ready to install and test the firmware.

You should see a number once every 100 milliseconds, which is a lot of output. Let’s fix that with this open-ended challenge:

Once your program is printing 0 and 1 only when the button changes, let’s do one last step:


Now we are ready to hook up this controller to a game in Unity. Complete the following steps to build your game:

Your game is running. There’s the boss—and there’s no way to get rid of it. What a hard game! Let’s get our boss-removing button controller integrated with these steps:

Let’s finish off the boss and the game with an open-ended exercise:


Here’s your TODO list for next time:

See you next time!