Unity Pinball Controller
.
Hamblen Fall 2015 ECE 4180 Sec.A Final Project, Georgia Tech: Jenny Hunter, Derek Travisano, Sandeep Vijayasekar, Zechariah Lin
Import programUnityPinballController
4180 Final Project Jenny Hunter, Derek Travisano, Sandeep Vijayasekar, Zechariah Lin
Overview
Mbed based pinball controller using serial to communicated with a pinball game created in Unity. Mbed prints a string that is parsed by Unity through serial in Windows. Concave buttons are used to activate two flippers; a potentiometer is used to act as the plunger to launch the ball; LSM9DS0 IMU used to detect tilt; and Infrared distance sensor is used to detect if a coin was inserted for additional lives after a 'Game Over'. All of these inputs edit the variables that are printed in the string over serial.
Unity Pinball Game
Pinball game created using Unity Game Engine that implements mbed-based controller through Windows Serial. User first launches a ball using a plunger with 4 potential launch speeds. Once the ball is play the user can use two buttons to controller the flippers to hit the ball, and tilt the controller to add tilt in order to try and keep the ball from falling off of the board and obtain high scores. The player has three extra lives, and once they run out will encounter a Game Over. More lives can be added by inserting a coin into the controller to extend gameplay.
Unity Pinball game can be found here: https://github.com/jhunter029/Pinball/
Note: Unity serial requires "/r/n" for newline character in Windows when reading serial inputs from the mbed controller.
mbed components used
- Concave button x2
- Slidepot
- Infrared distance sensor
- LSM9DS0 IMU
IR Distance Sensor Pinout
Pin number | IR pins | mbed pins |
---|---|---|
1 | 3.3V | VOUT |
2 | GND | GND |
3 | COM | p19= AnalogIn |
Concave Buttons Pinout
Pin number | Button Pins | mbed pins |
---|---|---|
1 | 3V | VOUT |
2 | GND | GND |
3 | Left COM | p21= DigitalIn |
4 | Right COM | p22= DigitalIn |
LSM9DS0 IMU Pinout
Pin number | IMU Pins | mbed pins |
---|---|---|
1 | VDD | VOUT |
2 | GND | GND |
3 | SDA | p9= SDA |
4 | SCL | p10= SCL |
Potentiometer Pinout
Pin number | Pot Pins | mbed pins |
---|---|---|
1 | 3.3V | VOUT |
2 | GND | GND |
3 | COM | p20=AnalogIn |
MBED Program
Import programUnityPinballController
4180 Final Project Jenny Hunter, Derek Travisano, Sandeep Vijayasekar, Zechariah Lin
UnityControllerCode
#include "mbed.h" #include "LSM9DS0.h" #include "PinDetect.h" // SDO_XM and SDO_G are pulled up, so our addresses are: #define LSM9DS0_XM_ADDR 0x1D // Would be 0x1E if SDO_XM is LOW #define LSM9DS0_G_ADDR 0x6B // Would be 0x6A if SDO_G is LOW LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR); // IMU DigitalIn L(p21); // Left flipper DigitalIn R(p22); // Right flipper Serial pc(USBTX, USBRX); // Serial read out AnalogIn plunger(p20); // Slide potentiometer DigitalOut led1(LED1); //left DigitalOut led2(LED2); //right DigitalOut led3(LED3); //coin AnalogIn coin(p19); // IR Sensor //variables changed by callback functions to be printed to serial int coins=0; int volatile left=0; int volatile right=0; int plungers=0; void L_hit_callback (void) { left=1; } void R_hit_callback (void) { right=1; } int main() { // Use the begin() function to initialize the LSM9DS0 library. // You can either call it with no parameters (the easy way): uint16_t status = imu.begin(); //Make sure communication is working (DEBUG) pc.printf("LSM9DS0 WHO_AM_I's returned: 0x%X\n", status); pc.printf("Should be 0x49D4\n\n"); while(1) { //Setup default values plungers=0; led1=L; led2=R; left=L; right=R; // imu readings imu.readAccel(); float heading = imu.calcHeading(); //detect if coin was inserted if (coin>0.35f) { led3=1; coins=1; } else { led3=0; coins=0; } // which speed to launch ball at if (plunger<0.25f) { plungers=1; } else if(plunger<0.5f) { plungers=2; } else if(plunger<0.75f) { plungers=3; } else if(plunger<2.0f) { plungers=4; } // Write to serial - order matters (left, right coin, plunger, imu) pc.printf("%i,%i,%i,%i,%.1f\r\n",left,right,coins,plungers, imu.ay); wait(0.20); } }
Libraries
LSM9DS0 IMU:
Import libraryLSM9DS0
Allows for reading accelerometer, gyroscope, and magnetometer data from an LSM9DS0 IMU device
Future Works
• More pinball levels
• Add component to detect force of flipper pressing
• SD card high score system
Links
• Unity Pinball Game: https://github.com/jhunter029/Pinball/
• LMS9DS0 IMU Wiki Page: https://developer.mbed.org/cookbook/LMS9DS0-IMU
• Sparkfun Concave buttons: https://www.sparkfun.com/products/9336
• Slider Pot: http://www.phidgets.com/products.php?category=37&product_id=1112_1
• IR Distance Sensor: http://www.sharp-world.com/products/device/lineup/data/pdf/datasheet/gp2y0a21yk_e.pdf
Please log in to post comments.