Pack-Man manual

This is a manual for making a video game system with 5 joysticks, such as PACK-MAN

JOYSTICKS

We got out joysticks at HAPP (there are a whole lot, but we went with the cheap Ultimate Joystick, which is pictured below). You can pick between a few very primary colors, and if you order 6 or more, it’s a little cheaper per unit.

Joystick

These are 4-position joysticks, which means that it is either at rest in the middle (like in the photograph) or it has been pushed UP, RIGHT, DOWN, or LEFT. There is no way to be in more than one position (for example, UP and RIGHT). It’s physically impossible.

What I mean is that there are 4 switches on the bottom (the kind you buy at an electronics store - a momentary SPDT switch, two of which can be seen in the picture). The joystick is only able to activate one switch at a time.

In order to actually use the joysticks, you need to be able to wire them; and then once you’ve wired them, you need to be able to read them and send this information onward (to a computer, to a video game console, to your stereo’s remote control, etc.) I’ll get more into wiring below, but first, think about how to mount the joysticks. It’s kind of uncomfortable to hold onto one of these in the raw. We found clear plastic containers at Super Home Mart. But maybe you just want to mount them all in a single piece of plywood. Either way, you have to cut a hole in the surface (bigger than the "stick" but smaller than that plastic ring around the stick, so it remains hidden) and then secure the joystick to the surface.

ELECTRONICS

We decided to have a microcontroller regularly (about 50 times a second) poll the joysticks; the microcontroller determined whether any of the joysticks had changed their position since the last time it polled them; and finally, it passed this information on to whoever cared to listen. We used Arduino as the microcontroller (Arduino is an AVR in a Basic Stamp-like package, kind of).

First, how do we "poll" a bunch of joysticks? Polling just means using the microcontroller to determine the position (UP, RIGHT, DOWN, or LEFT) of each of the joysticks. In words: we use 5 wires for each joystick. One wire goes to the metal part on each of the four switches (that’s 4 wires total). And one wire goes to one of the two metal parts on the end of one switch, and then it’s connected to the metal part on the end of the next switch, and then the third switch and then the fourth switch (that’s just one wire connecting the four switches together). [Image of how to wire one joystick] Those four wires are then connected to INPUT pins on the microcontroller, and the one wire is connected to an OUTPUT pin. The microcontroller sets one of the four wires to HIGH. It then reads the INPUT pin. If it reads a HIGH, then that means the joystick is pushed in that direction! If it reads a LOW, then the joystick isn’t pushed in that direction. The microcontroller continues through the other three INPUT pins in exactly the same manner.

Now, that was just for one of the joysticks. How do we check the rest of them? In exactly the same way! If you do the math, that is 5 wires for each joystick, so 5 joysticks would mean you’d need 25 pins right? Well, as it turns out, we can take a little shortcut. Those four INPUT pins can actually be shared by each of the joysticks. But each joystick needs its own OUTPUT pin. This means that five joysticks actually only uses 9 pins. There are four INPUT pins and then five OUTPUT pins (one for each joystick). Why? Well let’s say only one person is pushing UP. When we set the OUTPUT pin for that joystick to HIGH, there is 5V going to all the switches of that joystick. But since only the UP switch is activated, only the corresponding INPUT will read HIGH. If we set the OUTPUT pin for a different joystick to HIGH, instead, then none of the INPUTS will get 5V (or HIGH). Here is an image of the circuit:

Pack-Man switch schematic

So you can see that it is easy to add more joysticks. All you need to do is keep using the same 4 INPUT pins, but add an OUTPUT pin for each additional joystick.

Now, all of these wires could get pretty messy, so we used MIDI cables to carry the wires from the microcontroller to the joysticks (but you don’t have to). We’re not using real MIDI, we’re just using MIDI cables, because there are 5 wires inside of a MIDI cable we can use. So don’t let the MIDI confuse you. You could probably use phone cable if you felt like it, or ethernet. Just keep track of which wires should connect to what. Of course, if you use MIDI cables, then you’ll want to be able to plug them into something, like jacks. Then, you only have to solder wires between the jack and the joystick, and between the other jack and the microcontroller.

One thing in the schematic that I haven’t mentioned is what the resistors are doing. It is a very common technique in digital electronics, which is to "pull down" the INPUT pins to ground when the switch isn’t activated. This is necessary because the pin might "float" otherwise and the microcontroller might read unexpected HIGH values. The resistor anchors the pin to LOW, except when the switch is actually activated, at which point the INPUT pin reads a reliable HIGH.

CODE

The last part of this whole system is the code that is running on the microcontroller. The text in the section above that described how to "poll" the joysticks actually explains the what the code is doing. But here is the Arduino code to actually do it:



		  int joystickNum = 5;                  // This is a hack because I can't figure out how to access an array's length
		  int joystickPower[] = {2,3,4,5,6};    // which pins are connected to the power of each joystick
		  int joystickDirections[] = {7,8,9,10}; // which pins connect to up, right, down, left (all joysticks connect here)
		  byte joysticks[] = {0,0,0,0,0};       // initialize all of the joystick values
		  byte dataToSend;
		  int i,j;
		  byte tmp;

void readJoysticks() {
	// set all output pins to low
  	for (i=0; i<joystickNum; i++) {
		digitalWrite(joystickPower[i], LOW);
	}
	for (i=0; i<joystickNum; i++) { // for each one of the joysticks
		digitalWrite(joystickPower[i], HIGH); // set its pin to HIGH
		tmp = 0; // this is a temporary variable that will hold the direction of this joystick
		for (j=0; j<4; j++) { // and then for each of the directions of the joystick
			if ( digitalRead(joystickDirections[j])==HIGH ) { // check to see if it's activated
				tmp = 1 << j; // do bit shifting to represent the direction (up=1<<0=1,right=1<<1=2,down=1<<2=4,left=1<<3=8)
			}
		}
		if ( joysticks[i] != tmp ) { // check the current direction against the previous direction, which is stored in the joysticks array
			dataToSend = i << 4; // put the joystick's index into the data we're about to send to the PC
			dataToSend = dataToSend | tmp; // now put in the direction
			joysticks[i] = tmp; // and set the previous direction to the current direction (for next time)
			serialWrite(dataToSend); // finally send the data to the PC
		}
		digitalWrite(joystickPower[i], LOW); // we're done with this joystick, set it to LOW and do the loop again for the next joystick
	}
}


// this is called once when the chip is first given power
void setup() {
	for (i=0; i<joystickNum; i++) {
		pinMode(joystickPower[i], OUTPUT);
	}
	for (i=0; i<4; i++) {
		pinMode(joystickDirections[i], INPUT);
	}
	beginSerial(19200);      // begin communication with the PC at 19200 baud (can be changed if you need to)
}


// this is called over and over and over
void loop() {
	delay(10);
	readJoysticks();
}

The code that’s above checks all the joysticks. But it also checks whether the joystick is in a different position than it was before. If the joystick is in a different position, then it sends its position over the serial port. One of the nice things about Arduino is that "over the serial port" actually means that it sends the data through USB to a computer. So in this case, the end recipient of the joystick control is a computer program (in PACK-MAN, it is an emulator running Pac-Man). It is entirely possible to send the data to an actual video game console too, if that’s what you want. But then you’d need to reverse-engineer how a joystick/controller to one of these consoles works and then mimick that with the microcontroller. I’ll leave that up to you!

 


cheap cialis from uk cheap levitra overnight delivery buy viagra from india cheapest viagra price order cheap viagra buy generic viagra cialis without a prescription viagra vendors no rx cialis find cialis on internet drug levitra levitra tablets levitra no rx required purchase cialis online buy viagra on line buy cialis internet cheap viagra from usa no prescription viagra viagra pharmacy online cialis in bangkok cheap levitra pharmacy viagra pill order cialis online cialis sales online pharmacy cialis purchase levitra no rx order cialis from canada purchase levitra overnight delivery cialis generic buy cheapest viagra on line levitra uk low cost viagra viagra in us order levitra from canada buy discount viagra online order discount viagra online buy levitra lowest price cialis online review cialis viagra in malaysia order cialis without prescription viagra no rx required purchase levitra without prescription compare levitra prices levitra malaysia cheap viagra in usa cialis no rx required cialis order levitra online lowest price for levitra tablet viagra cialis tablets viagra for order cialis for order buy cialis on line discount cialis online buy cheapest cialis on line order cheap levitra buy cialis lowest price discount viagra without prescription cialis no prescription order levitra no prescription cialis no rx cialis overnight shipping find no rx levitra purchase cialis overnight delivery cialis cheapest price drug viagra buy cheap cialis online no rx levitra find levitra no prescription required purchase levitra order discount cialis cheap viagra overnight delivery order discount levitra levitra buy viagra without rx cheap cialis in uk cheapest levitra order generic cialis viagra pharmacy levitra information compare levitra prices online levitra india buy no rx cialis levitra no rx viagra cheap drug order cheap cialis online buy levitra from india levitra pharmacy online lowest price viagra buying viagra cialis us viagra medication cheapest viagra cialis pills buy levitra on internet where to order viagra levitra overnight shipping best price for viagra order cialis levitra tablet buy levitra from canada order levitra no rx cialis online pharmacy order viagra overnight delivery find no rx viagra cialis india buy levitra low price buy levitra us buy discount levitra online levitra free sample order levitra without prescription buy levitra generic cheapest generic levitra online buy cheap levitra levitra in us buy levitra tablet levitra viagra buy drug online pharmacy viagra cheap cialis pharmacy viagra cheapest price buy generic cialis online cialis buy buy cheap viagra levitra from canada cheap levitra no rx levitra for sale buy cialis no rx cheap cialis from usa levitra online review buy levitra without prescription viagra generic levitra buy drug drug levitra online purchase levitra in malaysia drug cialis viagra no rx buy cheap viagra internet cheap cialis no prescription levitra sales cialis in australia buy cialis overnight delivery cheap price cialis order levitra online cialis drug buy levitra online discount levitra overnight delivery cheap cialis in usa cialis malaysia find cheap levitra online levitra vendors cialis vendors viagra information levitra australia buy viagra on internet viagra without prescription cialis uk cheap cialis internet order viagra without prescription discount cialis overnight delivery cialis canada cialis in us cheap viagra no prescription viagra us viagra in australia buy cialis low price buy viagra low price buy cialis no prescription required buy viagra generic sale levitra order no rx viagra cheapest cialis online online levitra find levitra without prescription buy levitra overnight delivery order cialis cheap online cheap levitra order levitra from us cheapest generic viagra online buying generic viagra order discount levitra online buy cheap levitra online buy cialis in us order cialis no prescription cheap levitra without prescription levitra for order find cheap cialis buy viagra lowest price tablet cialis purchase viagra without prescription levitra order cheap viagra viagra free delivery levitra pill find discount levitra online buy cheapest cialis find cialis find viagra online cheap levitra from uk cialis overnight viagra tablet lowest price levitra levitra bangkok cheap viagra pharmacy buy viagra from canada levitra overnight delivery order levitra in us certified viagra buy cheap cialis order viagra no prescription cheap viagra on internet viagra online review levitra canada discount levitra order levitra overnight delivery cialis online order viagra buy viagra no rx levitra cheapest price fda approved levitra cheap viagra from canada order cialis in canada buy cialis online find cialis no prescription required levitra buy levitra on line order viagra cheap online viagra from india discount levitra no rx cialis free delivery cost of levitra sale viagra viagra overnight free viagra levitra in australia levitra price compare cialis prices viagra no prescription cialis in malaysia levitra internet order cheap cialis viagra canada order viagra on internet cheap viagra in canada levitra overnight levitra without prescription generic cialis cheap find viagra without prescription order levitra in canada cialis from canada purchase viagra buy cheap cialis internet levitra no prescription cost viagra order cheap viagra online find cheap viagra online cheap levitra online certified levitra viagra side effects generic viagra levitra buy online order discount viagra cheap levitra in uk no prescription cialis buy cialis us find levitra online order viagra online find viagra on internet cialis pill viagra online without prescription viagra price cialis cheap drug cialis purchase cheap levitra on internet levitra us buying viagra online find cialis without prescription buy cheapest viagra online cheap levitra from canada best price for levitra generic levitra online levitra drug generic viagra cheap approved cialis pharmacy find cheap cialis online buy cheap viagra online levitra no online prescription buy generic viagra online buy levitra online cheap viagra for sale cheap cialis online buy generic levitra order cialis in us discount viagra cheap viagra from uk pharmacy levitra order levitra no prescription required buy viagra in canada buy viagra from us cheap levitra from usa cialis information cialis no online prescription buy levitra no rx order viagra from us viagra pills discount cialis no rx cialis tablet low cost levitra compare viagra prices buy cheapest levitra online levitra pharmacy cheapest cialis order no rx levitra viagra sale approved viagra pharmacy viagra approved levitra prescription buy cialis from india find viagra no prescription required buy levitra no prescription required cheap cialis on internet buy cheapest levitra on line online pharmacy levitra buy cialis from us drug cialis online purchase viagra order levitra cheap drug cost levitra purchase viagra overnight delivery generic levitra cheap viagra pill cialis buy drug cheapest generic viagra buy viagra internet buy no rx viagra cheap cialis pill cheapest levitra online cost of viagra cheap viagra in uk levitra from india cialis price viagra overnight delivery levitra in bangkok best price cialis levitra cheap price online viagra cheap levitra no prescription viagra malaysia cialis sale buy levitra from us order cialis no rx discount viagra online cheap levitra in usa cialis pharmacy online free cialis best price for cialis buy viagra us cheap cialis in canada cialis bangkok cialis australia lowest price cialis cialis cost purchase viagra online levitra without a prescription generic viagra online viagra australia viagra bangkok levitra free delivery buy viagra overnight delivery find cialis online online cialis cialis without prescription viagra without a prescription viagra rx approved levitra pharmacy viagra overnight shipping find viagra cheap cialis no rx lowest price for viagra buy cialis from canada find discount viagra online buying levitra cialis approved cialis buy online order discount cialis online viagra purchase certified cialis buy discount levitra order levitra discount cialis buy viagra viagra prescription cheap cialis without prescription fda approved cialis cialis free sample cialis from india viagra online buy cheap levitra internet generic levitra cheap buy generic cialis viagra in bangkok levitra approved cialis without rx best price viagra levitra online without prescription viagra drug cialis in uk order cheap levitra online find cheap viagra buy generic levitra online purchase cialis without prescription order viagra no prescription required levitra sale viagra buy online cialis side effects order viagra no rx discount viagra no rx buy viagra online cheap where to order levitra buy levitra internet discount viagra overnight delivery find no rx cialis viagra viagra cheap price compare viagra prices online viagra internet cialis cheap price buy viagra online buying generic cialis levitra rx cheap levitra tablet cialis internet cialis online without prescription cheap price viagra viagra uk discount levitra without prescription buying cialis find levitra order viagra in us buy cheapest cialis online cheap viagra tablet where to order cialis generic cialis overnight levitra order cialis no prescription required buy cialis generic viagra from canada buy cialis find discount viagra viagra free sample viagra buy buy viagra without prescription buy cheapest viagra cheap levitra internet buying cialis online buy discount cialis levitra online pharmacy buy no rx levitra order viagra in canada cheap viagra internet cheap cialis from canada free levitra cialis prescription buy cialis on internet cheapest viagra online viagra no online prescription levitra in uk sale cialis buying levitra online generic cialis online compare cialis prices online levitra pills cialis rx cheapest generic cialis online buying generic levitra viagra sales order viagra from canada cheap cialis overnight delivery buy levitra in us cheap viagra without prescription cheapest generic cialis cheap cialis tablet find discount cialis order levitra on internet cheapest cialis price drug viagra online purchase buy cheapest levitra levitra purchase buy viagra no prescription required buy discount viagra purchase cialis buy cialis online cheap viagra tablets no rx viagra cheapest generic levitra buy discount cialis online purchase cialis no rx order generic viagra cheap cialis viagra in uk overnight viagra best price levitra find discount cialis online buy viagra in us buy cialis without prescription cheap levitra in canada levitra generic find levitra on internet levitra side effects pharmacy viagra order no rx cialis order cialis on internet cheap price levitra buy cialis in canada purchase viagra no rx fda approved viagra cheap levitra pill discount levitra online overnight cialis cost of cialis levitra medication cost cialis buy levitra in canada cheap viagra online viagra cost cheapest levitra price viagra india lowest price for cialis order generic levitra find discount levitra levitra without rx no prescription levitra order levitra cheap online cialis for sale order cialis from us cialis pharmacy find cheap levitra pharmacy cialis viagra online pharmacy order cialis overnight delivery levitra cost cialis medication purchase levitra online cheap viagra no rx cialis overnight delivery low cost cialis discount cialis without prescription