<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=JeremyKlem</id>
	<title>Mech - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=JeremyKlem"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/JeremyKlem"/>
	<updated>2026-04-13T06:14:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=8443</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=8443"/>
		<updated>2008-03-21T01:56:14Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Baseball */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [http://depot.northwestern.edu/mht363/public_html/IR%20Track/Mar%2019%20IR%20tracker.mp4 See Spot Run.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &amp;#039;Steel Toe&amp;#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_setup1.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8406</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8406"/>
		<updated>2008-03-20T23:46:53Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Circuit Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_PIC_Circuitry.jpg|left|The PIC Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
Sensor&lt;br /&gt;
[[Image:baseball_sensor_circuitry.jpg|left|Example of Sensor Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pitcher and Bat&lt;br /&gt;
[[Image:baseball_pitcher_bat_circuitry.jpg|left|Pitcher and Bat Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LED Circuit&lt;br /&gt;
[[Image:baseball_LED_circuitry.jpg|left|Example of LED Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Seven Segment Display&lt;br /&gt;
[[image:CircuitDiag.jpg|thumb|300px|Circuit diagram for the 7-segment display circuit|left]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. The transistor will be receive a large amount of infrared radiation constantly, until a ball falls through. The obstruction will send a pulse to the PIC and either an out, single, double, triple or homerun will be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a [http://pdf1.alldatasheet.com/datasheet-pdf/view/105974/ETC/RSB5S.html RSB52 relay]. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8404</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8404"/>
		<updated>2008-03-20T23:46:23Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Circuit Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_PIC_Circuitry.jpg|left|The PIC Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
Sensor&lt;br /&gt;
[[Image:baseball_sensor_circuitry.jpg|left|Example of Sensor Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pitcher and Bat&lt;br /&gt;
[[Image:baseball_pitcher_bat_circuitry.jpg|left|Pitcher and Bat Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LED Circuit&lt;br /&gt;
[[Image:baseball_LED_circuitry.jpg|left|Example of LED Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Seven Segment Display&lt;br /&gt;
[[image:CircuitDiag.jpg|thumb|300px|[Circuit diagram for the 7-segment display circuit]|left]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. The transistor will be receive a large amount of infrared radiation constantly, until a ball falls through. The obstruction will send a pulse to the PIC and either an out, single, double, triple or homerun will be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a [http://pdf1.alldatasheet.com/datasheet-pdf/view/105974/ETC/RSB5S.html RSB52 relay]. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_PIC_Circuitry.jpg&amp;diff=8403</id>
		<title>File:Baseball PIC Circuitry.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_PIC_Circuitry.jpg&amp;diff=8403"/>
		<updated>2008-03-20T23:39:01Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8402</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8402"/>
		<updated>2008-03-20T23:38:47Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* PIC Schematic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_PIC_Circuitry.jpg|left|The PIC Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
Sensor&lt;br /&gt;
[[Image:baseball_sensor_circuitry.jpg|left|Example of Sensor Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pitcher and Bat&lt;br /&gt;
[[Image:baseball_pitcher_bat_circuitry.jpg|left|Pitcher and Bat Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LED Circuit&lt;br /&gt;
[[Image:baseball_LED_circuitry.jpg|left|Example of LED Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. The transistor will be receive a large amount of infrared radiation constantly, until a ball falls through. The obstruction will send a pulse to the PIC and either an out, single, double, triple or homerun will be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a [http://pdf1.alldatasheet.com/datasheet-pdf/view/105974/ETC/RSB5S.html RSB52 relay]. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8391</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8391"/>
		<updated>2008-03-20T23:16:39Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
Sensor&lt;br /&gt;
[[Image:baseball_sensor_circuitry.jpg|left|Example of Sensor Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pitcher and Bat&lt;br /&gt;
[[Image:baseball_pitcher_bat_circuitry.jpg|left|Pitcher and Bat Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LED Circuit&lt;br /&gt;
[[Image:baseball_LED_circuitry.jpg|left|Example of LED Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. The transistor will be receive a large amount of infrared radiation constantly, until a ball falls through. The obstruction will send a pulse to the PIC and either an out, single, double, triple or homerun will be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a [http://pdf1.alldatasheet.com/datasheet-pdf/view/105974/ETC/RSB5S.html RSB52 relay]. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_LED_circuitry.jpg&amp;diff=8390</id>
		<title>File:Baseball LED circuitry.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_LED_circuitry.jpg&amp;diff=8390"/>
		<updated>2008-03-20T23:15:51Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_pitcher_bat_circuitry.jpg&amp;diff=8389</id>
		<title>File:Baseball pitcher bat circuitry.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_pitcher_bat_circuitry.jpg&amp;diff=8389"/>
		<updated>2008-03-20T23:15:18Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_sensor_circuitry.jpg&amp;diff=8388</id>
		<title>File:Baseball sensor circuitry.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_sensor_circuitry.jpg&amp;diff=8388"/>
		<updated>2008-03-20T23:14:57Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8386</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8386"/>
		<updated>2008-03-20T23:14:38Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Circuit Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
Sensor&lt;br /&gt;
[[Image:baseball_sensor_circuitry.jpg|left|Example of Sensor Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pitcher and Bat&lt;br /&gt;
[[Image:baseball_pitcher_bat_circuitry.jpg|left|Pitcher and Bat Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LED Circuit&lt;br /&gt;
[[Image:baseball_LED_circuitry.jpg|left|Example of LED Circuit|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. The transistor will be receive a large amount of infrared radiation constantly, until a ball falls through. The obstruction will send a pulse to the PIC and either an out, single, double, triple or homerun will be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a [http://pdf1.alldatasheet.com/datasheet-pdf/view/105974/ETC/RSB5S.html RSB52 relay]. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8357</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8357"/>
		<updated>2008-03-20T22:21:47Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat Relay &amp;amp; Power Supplies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. The transistor will be receive a large amount of infrared radiation constantly, until a ball falls through. The obstruction will send a pulse to the PIC and either an out, single, double, triple or homerun will be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a [http://pdf1.alldatasheet.com/datasheet-pdf/view/105974/ETC/RSB5S.html RSB52 relay]. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8356</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8356"/>
		<updated>2008-03-20T22:20:00Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Photodiode/Phototransistor Sensor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. The transistor will be receive a large amount of infrared radiation constantly, until a ball falls through. The obstruction will send a pulse to the PIC and either an out, single, double, triple or homerun will be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8355</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8355"/>
		<updated>2008-03-20T22:18:26Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Pitcher */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx RS385 motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8354</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8354"/>
		<updated>2008-03-20T22:18:09Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Pitcher */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a [http://www.trossenrobotics.com/store/p/5145-RS-385-Motor-7-2V.aspx motor] and scooping arm were used. The motor was hooked up to a 9.6V battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game. The arm, bar and ramp were made out of scrap sheet metal found in the machine shop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8351</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8351"/>
		<updated>2008-03-20T22:13:47Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on two 9.6V rechargeable batteries, was used to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8350</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8350"/>
		<updated>2008-03-20T22:12:55Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036 Spring Return Solenoid], run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8347</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8347"/>
		<updated>2008-03-20T22:12:04Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A [http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036&lt;br /&gt;
Spring Return Solenoid], run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8346</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8346"/>
		<updated>2008-03-20T22:11:01Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.goldmine-elec-products.com/prodinfo.asp?number=G16036&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Ball_Sensor.jpg&amp;diff=8341</id>
		<title>File:Baseball Ball Sensor.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Ball_Sensor.jpg&amp;diff=8341"/>
		<updated>2008-03-20T22:02:32Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8340</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8340"/>
		<updated>2008-03-20T22:02:17Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Photodiode/Phototransistor Sensor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Ball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Base_LED.jpg&amp;diff=8339</id>
		<title>File:Baseball Base LED.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Base_LED.jpg&amp;diff=8339"/>
		<updated>2008-03-20T21:44:15Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8338</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8338"/>
		<updated>2008-03-20T21:44:06Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Base and Out LEDs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|A Base LED|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8337</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8337"/>
		<updated>2008-03-20T21:43:53Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Base and Out LEDs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8335</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8335"/>
		<updated>2008-03-20T21:43:30Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Electrical Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scoreboard Circuitry===&lt;br /&gt;
&lt;br /&gt;
For the scoreboard we used two seven segment displays [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTD-4708JS.pdf LTD-4708JS] and a [http://www.standardics.nxp.com/products/hef/datasheet/hef4543b.pdf HEF 4543B] decoder chip for each. We used pins RD0-RD5 and RB0-RB5 on the PIC for the two displays. The connections are the same as those outlined [http://hades.mech.northwestern.edu/wiki/index.php/Controlling_a_seven_segment_display here.] The scoreboard also had two LEDs for counting the number of outs.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Base and Out LEDs===&lt;br /&gt;
&lt;br /&gt;
For the three bases and the two out indicators we used the same bright red LEDs. We attached them in series with a 100 Ohm resistor and sent a signal from the PIC. Once a man was on base, or an out was indicated the PIC would output a digital high signal. Below is an example of a base LED. &lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Base_LED.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball_fullcode.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Variable and function definitions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#DEVICE ADC=8&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT&lt;br /&gt;
#use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
#define FIRSTBASE PIN_C0			//Output to base LEDs&lt;br /&gt;
#define SECONDBASE PIN_C1&lt;br /&gt;
#define THIRDBASE PIN_C2&lt;br /&gt;
#define SINGLE_SENSOR PIN_A0			//Analog input pins for each sensor   &lt;br /&gt;
#define DOUBLE_SENSOR PIN_A1&lt;br /&gt;
#define TRIPLE_SENSOR PIN_A2&lt;br /&gt;
#define HR_SENSOR PIN_A3&lt;br /&gt;
#define OUT_SENSOR PIN_A5&lt;br /&gt;
#define OUT1 PIN_E1       			//Output to scoreboard out LEDs    &lt;br /&gt;
#define OUT2 PIN_E2&lt;br /&gt;
#define BATSWITCH PIN_D7			//Output to enable bat &lt;br /&gt;
&lt;br /&gt;
void singlehit();			&lt;br /&gt;
void doublehit();&lt;br /&gt;
void triplehit();&lt;br /&gt;
void homerun();&lt;br /&gt;
void out();&lt;br /&gt;
void displayscore();&lt;br /&gt;
&lt;br /&gt;
int8 singlesensor, doublesensor, triplesensor, hrsensor, outsensor;&lt;br /&gt;
int8 outs=0, innings=0, stopswitch;&lt;br /&gt;
int8 team1score=0, remainder1=0, tensdigit1=0;&lt;br /&gt;
int8 team2score=0, remainder2=0, tensdigit2=0;&lt;br /&gt;
int8 team1=1, team2=0; 				//Team 1 starts at bat&lt;br /&gt;
	&lt;br /&gt;
int8 bases=0;&lt;br /&gt;
int8 singleadvance[8]={1,3,5,7,9,11,13,15};	//Look at diagram of array initialization&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};		&lt;br /&gt;
int8 tripleadvance[8]={4,12,12,20,12,20,20,28};&lt;br /&gt;
int8 hradvance[8]={8,16,16,24,16,24,24,32};&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     			//Three inning game&lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  			//Team 1 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);		&lt;br /&gt;
		delay_ms(500);      		//Time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);			//Read from analog inputs to detect ball	&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   	//Call appropriate function depending on where ball dropped&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);			//This delay prevents the program from misreading the sensor, for example, &lt;br /&gt;
            }					//if the ball jiggles and triggers the sensor twice in a short period of time&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();			//Update scoreboard&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  			//Team 2 at bat&lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      &lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   &lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;			//Next inning&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;				//New game after three innings&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the single, double, triple, and home run functions we used different arrays that were initialized at the beginning of the program. The values in these arrays are explained through the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:baseball_array_explanation2.jpg|left|Diagram of array initialization|thumb|700px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example for a double, the left side of the figure shows the eight possible base configurations. The first three bits represent first, second and third base (a 1 indicates a runner on base). After a double the baserunners advance two bases as shown on the right side of the figure. We kept track of runs scored by using the five bits on the left. At the beginning of the program arrays were initialized for each type of hit. For a double, the initialization would be: &lt;br /&gt;
&lt;br /&gt;
int8 doubleadvance[8]={2,6,10,14,10,14,18,22};&lt;br /&gt;
&lt;br /&gt;
This way we could use the global variable, &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;, to call up the appropriate value from each array. To determine the number of runs scored, we simply shifted the bits to the right by three places (&amp;gt;&amp;gt;3). To update the position of the baserunners, we had to clear all the bits except the first three. This was accomplished by shifting the bits to the left five places (&amp;lt;&amp;lt;5) then shifting them to the right by five (&amp;gt;&amp;gt;5) places. The result was the new value for &amp;lt;i&amp;gt;bases&amp;lt;/i&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;		//Determine run scored&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;				//Update baserunners&amp;#039; positions&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);				//Light up appropriate bases&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){				//Update score&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     		//Switch to Team 2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;					//Clear the bases&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     		//Switch to Team 1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {				&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;		&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);			//Activate ones digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);		&lt;br /&gt;
      output_high(PIN_B5);			//Activate tens digit&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      		//Out LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8121</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8121"/>
		<updated>2008-03-20T16:10:04Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball machines. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. A acrylic sheet was used to wrap around the back as the rear wall. Holes were cut to allow pitching and scoreboard display. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball3.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     &lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  &lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      //time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   //need to check appropriate threshold&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  &lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      //time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   //need to check appropriate threshold&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     //switch team2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     //switch team1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      //turn on LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8120</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=8120"/>
		<updated>2008-03-20T16:07:52Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Mechanical Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to make an interactive baseball game inspired by pinball machines. There is a solenoid-powered bat and a pitching mechanism that utilizes a motor and lever arm setup. Both of these are controlled by buttons so that two people can play against each other. The game has targets for a single, double, triple, and home run, with a simple photodiode-phototransistor circuit to sense the ball. There are LEDs to light up each base as well as a scoreboard containing two seven-segment displays and LEDs for outs. &lt;br /&gt;
&lt;br /&gt;
This page will describe the mechanical design, electrical design, and code for the project.&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~8ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~3ft&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
[[Image:Baseball_Scoreboard_Circuitry.jpg|left|Scoreboard circuitry, two seven-segment displays and two LEDs for outs|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
[[media:baseball3.c|Link to full code]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;General outline of code:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Detect switch on pitching mechanism to enable bat&lt;br /&gt;
# Detect ball dropping through sensors&lt;br /&gt;
# Call appropriate function (single, double, triple, home run, or out)&lt;br /&gt;
# Update position of baserunners and light up base LEDs&lt;br /&gt;
# Display updated score and outs on scoreboard &lt;br /&gt;
# Switch teams at three outs&lt;br /&gt;
# End game after three innings &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Main function for baseball game:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   &lt;br /&gt;
   setup_adc_ports(AN0_TO_AN5);&lt;br /&gt;
   setup_adc(ADC_CLOCK_INTERNAL);&lt;br /&gt;
		&lt;br /&gt;
   while(TRUE){ &lt;br /&gt;
&lt;br /&gt;
      while(innings&amp;lt;3){     &lt;br /&gt;
&lt;br /&gt;
         while(team1==1) {  &lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      //time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   //need to check appropriate threshold&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
&lt;br /&gt;
        while(team2==1) {  &lt;br /&gt;
    &lt;br /&gt;
	    set_adc_channel(5);		&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    stopswitch = read_adc();&lt;br /&gt;
      &lt;br /&gt;
	    if (stopswitch&amp;gt;200){&lt;br /&gt;
		output_high(BATSWITCH);&lt;br /&gt;
		delay_ms(500);      //time for player to swing&lt;br /&gt;
		output_low(BATSWITCH);&lt;br /&gt;
	    }&lt;br /&gt;
      &lt;br /&gt;
	    set_adc_channel(0);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
            singlesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(1);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    doublesensor = read_adc();&lt;br /&gt;
	    set_adc_channel(2);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
	    triplesensor = read_adc();&lt;br /&gt;
            set_adc_channel(3);&lt;br /&gt;
	    delay_us(10);&lt;br /&gt;
	    hrsensor = read_adc();&lt;br /&gt;
            set_adc_channel(4);&lt;br /&gt;
            delay_us(10);&lt;br /&gt;
            outsensor = read_adc();&lt;br /&gt;
      &lt;br /&gt;
            if (singlesensor &amp;gt; 100) {   //need to check appropriate threshold&lt;br /&gt;
               singlehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (doublesensor &amp;gt; 100) {&lt;br /&gt;
               doublehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (triplesensor &amp;gt; 100) {&lt;br /&gt;
               triplehit();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (hrsensor &amp;gt; 100) {&lt;br /&gt;
               homerun();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
            if (outsensor &amp;gt; 100) {&lt;br /&gt;
               out();&lt;br /&gt;
               delay_ms(1000);&lt;br /&gt;
            }&lt;br /&gt;
           &lt;br /&gt;
            displayscore();&lt;br /&gt;
      &lt;br /&gt;
         }&lt;br /&gt;
   &lt;br /&gt;
      innings=innings+1;&lt;br /&gt;
   &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   team1score=0;&lt;br /&gt;
   team2score=0;&lt;br /&gt;
   bases=0;&lt;br /&gt;
   innings=0;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions for single, double, triple, home run, and out:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Single:&amp;lt;/u&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void singlehit(){                &lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
   &lt;br /&gt;
   runsadded = singleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=singleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Double:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void doublehit() {         &lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = doubleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=doubleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Triple:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void triplehit() {&lt;br /&gt;
  &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
          &lt;br /&gt;
   runsadded = tripleadvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=tripleadvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Home run:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void homerun() {&lt;br /&gt;
   &lt;br /&gt;
   int runsadded, basetemp;&lt;br /&gt;
     &lt;br /&gt;
   runsadded = hradvance[bases]&amp;gt;&amp;gt;3;&lt;br /&gt;
   basetemp=hradvance[bases]&amp;lt;&amp;lt;5;&lt;br /&gt;
   bases=basetemp&amp;gt;&amp;gt;5;&lt;br /&gt;
   &lt;br /&gt;
   output_C(bases);&lt;br /&gt;
&lt;br /&gt;
   if(team1==1){&lt;br /&gt;
      team1score=team1score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   if(team2==1){&lt;br /&gt;
      team2score=team2score+runsadded;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Out:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void out() {&lt;br /&gt;
&lt;br /&gt;
   outs=outs+1;   &lt;br /&gt;
   &lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team1==1){     //switch team2 at bat&lt;br /&gt;
      team1=0;&lt;br /&gt;
      team2=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
     &lt;br /&gt;
   }&lt;br /&gt;
   if (outs==3 &amp;amp;&amp;amp; team2==1){     //switch team1 at bat&lt;br /&gt;
      team2=0;&lt;br /&gt;
      team1=1;&lt;br /&gt;
      outs=0;&lt;br /&gt;
      bases=0;&lt;br /&gt;
      output_low(FIRSTBASE);&lt;br /&gt;
      output_low(SECONDBASE);&lt;br /&gt;
      output_low(THIRDBASE);&lt;br /&gt;
       &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Function for scoreboard display:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void displayscore() {&lt;br /&gt;
  &lt;br /&gt;
      remainder1 = team1score % 10;&lt;br /&gt;
      tensdigit1 = (team1score - remainder1)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_b(remainder1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_b(tensdigit1 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_B5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
  &lt;br /&gt;
      remainder2 = team2score % 10;&lt;br /&gt;
      tensdigit2 = (team2score - remainder2)/10;&lt;br /&gt;
   &lt;br /&gt;
      output_d(remainder2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D4);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
      output_d(tensdigit2 &amp;amp; 15);&lt;br /&gt;
      output_high(PIN_D5);&lt;br /&gt;
      delay_ms(2);&lt;br /&gt;
   &lt;br /&gt;
      if (outs==0 || outs==3){      //turn on LEDs on scoreboard&lt;br /&gt;
      output_low(OUT1);&lt;br /&gt;
      output_low(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==1) {&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
      }&lt;br /&gt;
      if (outs==2){&lt;br /&gt;
         output_high(OUT1);&lt;br /&gt;
         output_high(OUT2);&lt;br /&gt;
      }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;br /&gt;
&lt;br /&gt;
Overall, our baseball project was successful, the bat performed reliably and with its range of motion it was possible to hit all four targets. The pitching mechanism was effective; however, we did have a few cases where the lever arm would get stuck or the ball would drop out. To improve this the lever arm could be smoothed out and a piece of tubing could replace the metal sheet. This should make the pitching more reliable.&lt;br /&gt;
&lt;br /&gt;
The base LEDs and the scoreboard functioned properly. The four sensors for single, double, triple and home run detected the ball consistently and advanced the baserunners correctly. One major problem we found was that occasionally the program missed reading an out. This is due to the timing of the program, so that when the ball fell through the out sensor the program would not be reading from the analog input at that time. We tried to adjust the 500ms delay when the player can swing (see Code), but the program would still miss reading the sensor. One possible way to fix this is to use an [http://hades.mech.northwestern.edu/wiki/index.php/Interrupts interrupt] triggered by a digital input pin. &lt;br /&gt;
&lt;br /&gt;
Originally we intended for the game to pitch automatically using another relay circuit to the pitching motor. The program would then activate the pitching mechanism at random times. We ended up using a button for the pitching because it would be more interactive and allow two people to play against each other.&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7970</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7970"/>
		<updated>2008-03-20T00:04:07Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Part&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Quantity&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Plywood&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~4ft^2&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Wood Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;21&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Set Screws&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;Acrylic Board&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;~2ft^2&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7969</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7969"/>
		<updated>2008-03-19T23:58:11Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat Relay */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay &amp;amp; Power Supplies===&lt;br /&gt;
In order to power our solenoid and motor we needed external power. We used the 9.6V rechargeable batteries found in the lab kits. The first battery is permanently connected to the pitching motor as well as in series with the second battery. The two batteries in series are connected to the solenoid via a relay. When the PIC sends a high pulse to activate the coil the user can then activate the solenoid with the bat button. The PIC only sends a .5 second pulse, which is a little more time then is needed to pitch the ball. The PIC is activated to send this pulse when the pitching arm hits the lever switch located on the stopping bar in the back of the game (See pitching above).&lt;br /&gt;
&lt;br /&gt;
Ideally, when the pitch button is activated it will turn the arm upwards and both activate the switch and pitch the ball. The relay will come on allowing the player to complete the loop on the solenoid with the bat button. Once the half second delay ends the relay closes, which means the user can no longer activate the bat. This way only one swing is allowed per pitch.&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Relay.jpg&amp;diff=7937</id>
		<title>File:Baseball Relay.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Relay.jpg&amp;diff=7937"/>
		<updated>2008-03-19T23:38:18Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7936</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7936"/>
		<updated>2008-03-19T23:38:03Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat Relay */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Relay.jpg|left|The Relay to Control the Bat|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7934</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7934"/>
		<updated>2008-03-19T23:37:02Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Photodiode/Phototransistor Sensor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|left|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7933</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7933"/>
		<updated>2008-03-19T23:36:50Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Photodiode/Phototransistor Sensor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|right|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Sensor.jpg&amp;diff=7932</id>
		<title>File:Baseball Sensor.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Sensor.jpg&amp;diff=7932"/>
		<updated>2008-03-19T23:36:14Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7930</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7930"/>
		<updated>2008-03-19T23:35:56Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Photodiode/Phototransistor Sensor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
An IR optical sensor was used to detect the ball falling through a hole. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Sensor.jpg|right|One of the Sensors Used to Detect the Ball|thumb|300px]]&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7928</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7928"/>
		<updated>2008-03-19T23:33:30Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Pitcher */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. Attached to the bar is a lever switch which sends a pulse to the PIC telling it that a pitch has been thrown. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7927</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7927"/>
		<updated>2008-03-19T23:32:18Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Pitcher */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|left|Pitching Apparatus with Activate Button|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7926</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7926"/>
		<updated>2008-03-19T23:32:04Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Pitcher */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. The motor was hooked up to a single rechargeable  battery found in the kits. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|Pitching Apparatus with Activate Button|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7925</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7925"/>
		<updated>2008-03-19T23:31:01Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|Bat with Actuation Arrows|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7924</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7924"/>
		<updated>2008-03-19T23:30:33Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Bat */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|left|thumb|300px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7923</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7923"/>
		<updated>2008-03-19T23:30:12Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|left|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7922</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7922"/>
		<updated>2008-03-19T23:29:59Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|left|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|right|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7921</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7921"/>
		<updated>2008-03-19T23:29:48Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|right|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Single.jpg&amp;diff=7920</id>
		<title>File:Baseball Single.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Single.jpg&amp;diff=7920"/>
		<updated>2008-03-19T23:29:28Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7919</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7919"/>
		<updated>2008-03-19T23:29:17Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Single.jpg|middle|A Single Target|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|right|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7918</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7918"/>
		<updated>2008-03-19T23:28:38Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|Baseball Play Field|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|right|Baseball Recess|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7917</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7917"/>
		<updated>2008-03-19T23:26:25Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Play Field and Housing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|left|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Pitcher.jpg&amp;diff=7916</id>
		<title>File:Baseball Pitcher.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Pitcher.jpg&amp;diff=7916"/>
		<updated>2008-03-19T23:25:51Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Bat.jpg&amp;diff=7915</id>
		<title>File:Baseball Bat.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Bat.jpg&amp;diff=7915"/>
		<updated>2008-03-19T23:25:21Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Recess.jpg&amp;diff=7914</id>
		<title>File:Baseball Recess.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Baseball_Recess.jpg&amp;diff=7914"/>
		<updated>2008-03-19T23:24:56Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7913</id>
		<title>Baseball</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Baseball&amp;diff=7913"/>
		<updated>2008-03-19T23:24:19Z</updated>

		<summary type="html">&lt;p&gt;JeremyKlem: /* Mechanical Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ming Lee Chow:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Biomedical Engineering Class of 2009&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Jeremy Klem:&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;Mechanical Engineering Class of 2008&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
&lt;br /&gt;
===Play Field and Housing===&lt;br /&gt;
&lt;br /&gt;
The general concept is to have a slanted surface similar to a pinball machine. The ball will roll down and the user will try to hit it back up into a single, double, triple or homerun. These &amp;quot;hits&amp;quot; have dampening backstops and milled down grooves to channel the ball into a hole where a sensor is placed. If none of these are hit then the ball rolls back down towards the bat and into an out hole. This was done to limit the number of holes and sensor we would need to create. There are rails along the play field so the ball will not fly off. Underneath, there is a recess, which is an oppositely slanted board to channel the ball back to the pitching apparatus. The housing has sides to mount the bat button and keep the ball from sliding out of the recess. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|right|thumb|200px]]&lt;br /&gt;
[[Image:Baseball_Recess.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bat===&lt;br /&gt;
&lt;br /&gt;
The Bat was fashioned out of wood on the band saw and sanded to a finish. Two holes were drilled: one to act as an anchoring pivot point and the other to be attached to an actuator. A solenoid, run on the two rechargeable batteries in each kit, was used with a compression spring to actuate the bat. The user interface was a simple push button usually stocked in the lab. This button was located on the right side of the game similar to where pinball buttons are located. &lt;br /&gt;
&lt;br /&gt;
In order to make the game more like baseball we set up a system to only allow the user to swing during a pitched ball. To learn more about this look below to &amp;#039;&amp;#039;&amp;#039;Bat Relay&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Bat.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pitcher===&lt;br /&gt;
To actuate the ball up to a position to be &amp;quot;pitched&amp;quot; a motor and scooping arm were used. Once activated the arm turns upwards until hitting a static bar. The momentum of the ball would shoot it out of the scoop where a curved ramp would project it onto the play field. The motor is attached to a simple push button so another player can pitch creating a more interactive game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Pitcher.jpg|right|thumb|200px]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
&lt;br /&gt;
===PIC Schematic===&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
===Photodiode/Phototransistor Sensor===&lt;br /&gt;
&lt;br /&gt;
===Bat Relay===&lt;br /&gt;
&lt;br /&gt;
===Seven Segment Displays===&lt;br /&gt;
&lt;br /&gt;
==PIC Code==&lt;br /&gt;
&lt;br /&gt;
==Results and Reflections==&lt;/div&gt;</summary>
		<author><name>JeremyKlem</name></author>
	</entry>
</feed>