mario trivia gumball machine -...

34
1 Mario Trivia Gumball Machine May 6, 2011 MECH 307 Mechatronics Colorado State University Ed Brinkhoff Ethan Franck Brent Mackenzie Taylor Steinbaugh

Upload: lykhanh

Post on 27-Feb-2019

224 views

Category:

Documents


0 download

TRANSCRIPT

1

Mario Trivia Gumball Machine

May 6, 2011

MECH 307 Mechatronics

Colorado State University

Ed Brinkhoff Ethan Franck

Brent Mackenzie Taylor Steinbaugh

2

Table of Contents 1 Design Summary ................................................................................................................................... 3

2 System Details ....................................................................................................................................... 5

2.1 Description .......................................................................................................................................... 5

2.1.1 User Interface........................................................................................................................ 5

2.1.2 Dispenser/Elevator/Cannon/Music ...................................................................................... 6

2.1.2 Teleporter and Photogate ................................................................................................... 10

2.2 Wiring Diagrams ................................................................................................................................ 11

2.2.1 Overall Circuit Diagram .............................................................................................................. 11

2.2.2 LCD1 ........................................................................................................................................... 12

2.2.3 LCD2 ........................................................................................................................................... 13

2.2.4 Thermistor .................................................................................................................................. 14

2.2.5 Dispenser/Elevator/Music/Cannon ........................................................................................... 15

2.2.6 Teleporter/Photogate ................................................................................................................ 16

3 Parts List ................................................................................................. Error! Bookmark not defined.

4 PicBasic Pro Code ................................................................................................................................ 17

4.1 LCD1 PIC code: .................................................................................................................................. 17

4.2 LCD2 PIC code: .................................................................................................................................. 22

4.3 Dispenser PIC code:........................................................................................................................... 25

4.4 Thermistor PIC code: ......................................................................................................................... 31

4.5 Teleporter PIC code: ......................................................................................................................... 33

3

1 Design Summary

Our project is a machine that asks the user some trivia questions. Once the user has answered

the three questions that the machine prompts, the machine will dispense one of three gumballs

according to the number of questions the user answered correctly.

To start the machine the user will flip a master switch will turn on two LCDs, one of which has a

touch screen placed on top of it. The top LCD will instruct the user to place their hand on the hand

“scanner” which will then change what is displayed on the LCDs. The LCD will then prompt the user to

answer three questions, each question leading to different sets of questions depending on whether the

user answers the questions correct or incorrect. Once the user has answered all the questions, the LCDs

will display the number of answers the user got correct, a dispensing/loading screen, end credits and

then a blank screen.

If the user answers no questions correctly a blue gumball will be released and it will go into a

piranha plant which is featured in Mario games and the user will not receive a gumball. The gumball will

then be released to the back of the machine so that the owner of the machine may retrieve the

gumballs that the users do not get.

If the user were to answer questions one or two questions correctly, a green gumball will be

released onto a track. The gumball will go down a spiral track into a cannon. The cannon will then shot

the gumball where it will then go down a series of slides to the bottom of the machine. The gumball will

then be elevated by an elevator to the top the machine to where the user can retrieve the gumball.

When the user answers all the questions correctly, a red gumball will be released and it will do

the same thing that the green gumball does with the edition of a transporter at the beginning of its

track. The gumball will be released onto a track and rest in front of a door in the back panel of the

machine. The door will be opened and the gumball will roll onto a track that is behind the machine. At

the same time another door on the other side of the machine will open where another similar red

gumball will roll out of giving the appearance that the red gumball was transported.

4

User Interface

Piranha Plant

Cannon

Elevator

Teleporter

Ladder

Dispenser

Unit

5

2 System Details

2.1 Description

2.1.1 User Interface

The user will first have to flip the master switch to turn on power to the breadboards, overhead

lights and components of the gumball machine. Then the user will place his/her hand on the “hand

scanner” where a thermistor will be placed under. The thermistor will detect the change in temperature

due to the higher temperature of a person’s hand. This Triggers a sequence in the interface pic that

flashes a series of LED’s imbedded in the scanner under the fingertips. This will then trigger the two

LCDs to light up and give a greeting and instructions on what the user needs to do next. The top LCD will

ask the user questions while the bottom LCD will show the multiple choice answers to the question. A

touch screen will be placed on top of the second LCD so all the user has to do is push on their answer to

go to the next question and eventually release a gumball. The potentiometer is used in order to change

the contrast of the two LCDs.

Thermistor

Magnetic

Stylus

Contrast

Dial

LCD Display &

Touchscreen

Master

Power

Switch

6

2.1.2 Dispenser/Elevator/Cannon/Music

When the user has answered all of the questions, the LCD PIC microcontroller will send a high

signal to one of three output ports depending on the number of correct answers. This causes the main

controller pic to dispense a gumball by powering one of the 3 12V dc dispenser motors through a

transistor for .5 seconds.

The main controller also plays the Super Mario “underground theme” in 1-bit format via picbasic

freqout command. The audio is played through a speaker with built in amplifier.

When the user has answered all the questions correctly the gumball will roll to the “teleporter”.

The gumball trips an infrared emitter / detector pair that make up a photogate at the entrance to the

teleporter. This activates the teleport sequence on a separate pic (to allow music to be played

throughout this sequence). Then the controller sequentially activates and deactivates two 12V linear

actuators, causing the gumball to move behind the back of the machine and appear to travel through a

lengthy green tube as in the old Mario games.

Main Controller Breadboard

12V DC Motor

Control Leads

(from PIC) Gumball

Storage Tube Speaker

Leads from

PIC

7

The gumball then travels to the “Cannon,” which is comprised of a pvc barrel attached to a 12V

pneumatic solenoid valve. The gumball is shot across the machine to the top of a Donkey Kong themed

ladder, and rolls down to the base of the elevator.

Barrel

Compressed

Air

12V Solenoid

Valve

Catching Funnel

Donkey Kong

Ladder

8

The elevator is comprised of a base unit that positions the gumball for retrieval, a belt and a

carrier. This mechanism carries the Gumball to a dispenser at the top as Mario’s flagpole theme plays.

If the user answers only 1 or 2 questions correctly, the gumball will skip the teleporter and

proceed directly to the cannon.

Gumball Retrieval

Unit

Tube from Ladder

Elevator Base

12V DC Motor

Gumball Guide

9

If the user fails to answer any question correctly, the gumball will dispense directly into the

mouth of a “piranha plant” and will exit the machine out the back through a series of PVC tubes. The

gumball can then be retrieved without removing one of the glass panels, but is not dispensed directly to

the user.

This is Nick.

Gumball Storage on back of machine

Top View of Piranha Plant

10

2.1.2 Teleporter and Photogate

Photogate

Guide Rail

“Tube”

Entrance

12V Linear

Actuator

Back Of

Trap Door

Return

Band

Exit

Entrance

11

2.2 Wiring Diagrams

2.2.1 Overall Circuit Diagram

3

20 X 4 LCD character display

5 V

5 V

Pot

1 2 3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss5 V

5 V

4 5 6 11 12 13 14

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

5 V

15 16

3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V

0.1 µF

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

NTC 103Thermistor

0.1 µF

330Ω

330Ω 330Ω

330Ω

330Ω

Touch screen voltage input

1kΩ

3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V0.1 µF

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

12 V

0.1 µF

Solenoid valve for cannon

12 V

0.1 µF

Elevator Motor

12 V

0.1 µF

Disp 3/Blue gumball dispenser

motor

12 V0.1 µF

Disp 1/Green gumball dispenser

motor

12 V0.1 µF

Disp 2/Red gumball dispenser

motor

3

20 X 4 LCD character display

5 V5 V

Pot

1 2 3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V

0.1 µF

5 V

4 5 6 11 12 13 14

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

5 V

15 16

Speaker

Dispenser PIC

ThermistorPIC

LCD 1PIC

LCD 2PIC

3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V

0.1 µF

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

5 V

330Ω 5 V

Infrared detector

Infrared emitter

12 V

0.1 µF

Linear actuator/Door 1/

Entrance Door

12 V

0.1 µF

Linear actuator/

Door 2/Exit Door

Dispenser PIC

12

2.2.2 LCD1

3

Vss Vcc Vee RS R/W E DB4 DB5 DB6 DB7

20 X 4 LCD character display

5 V

5 V

Pot

1 2 3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V

5 V

4 5 6 11 12 13 14

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

5 V

15 16

To LCD2 PIC for serial

communication

Touch screen voltage input

1kΩ

Output to Dispenser PIC

Input from Thermistor PIC

13

2.2.3 LCD2

3

Vss Vcc Vee RS R/W E DB4 DB5 DB6 DB7

20 X 4 LCD character display

5 V

5 V

Pot

1 2 3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V

0.1 µF

5 V

4 5 6 11 12 13 14

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

5 V

15 16

From LCD1 PIC for serial

communication

14

2.2.4 Thermistor

3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V

0.1 µF

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

NTC 103Thermistor

0.1 µF

To LCD1 PIC

330Ω

330Ω

330Ω

330Ω

330Ω

15

2.2.5 Dispenser/Elevator/Music/Cannon

3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V0.1 µF

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

Input from LCD1 PIC

12 V

0.1 µF

Solenoid valve for Cannon

12 V

0.1 µF

Elevator Motor

12 V

0.1 µF

Disp 3/Blue gumball

dispenser motor

12 V

0.1 µF

Disp 1/Green gumball

dispenser motor

12 V

0.1 µF

Disp 2/Red gumball

dispenser motor

Speaker

16

2.2.6 Teleporter/Photogate

3

PIC16F88

RA2

RA3

RA4

RA5

RB0

RB1

RB2

RB3 RB4

RA1

RA0

RA7

CLKO

RB7

RB6

RB5

VddVss

5 V

0.1 µF

1

2

4

5

6

7

18

17

16

15

14

13

12

8 11

9 10

5 V

330Ω 5 V

Infrared detector

Infrared emitter

12 V

0.1 µF

Linear actuator/Door 1/

Entrance Door

12 V

0.1 µF

Linear actuator/

Door 2/Exit Door

17

3 PicBasic Pro Code

3.1 LCD1 PIC code:

Code Comments

Include "modedefs.bas" DEFINE OSC 8 OSCCON.4 = 1 OSCCON.5 = 1 OSCCON.6 = 1 ANSEL = 0 ANSEL.6 = 1 TRISB.7 = 1 ADCON1.7 = 0 DEFINE ADC_BITS 10 TS_Value Var Word Val Var BYTE LCD2 Var PORTB.0 DISP2 Var PORTA.7 DISP1 Var PORTB.4 DISP3 Var PORTB.5 Therm Var PORTB.6 TRISB.6 = 1 mode con 2 Low DISP1 Low DISP2 Low DISP3 LCDOUT $FE,1," Please place your " LCDOUT $FE,$C0,"hand on the scanner" LCDOUT $FE,$94," to your right" Therm1: If (Therm = 1) Then Goto main Else Goto Therm1 Endif main: Val = 10 LCDOUT $FE, 1, " Please answer the " LCDOUT $FE,$C0,"following questions " PAUSE 5000

Needed for serial communication between PICs Define A/D converter pin Define variables Make dispenser pins initially low Display first set of instructions Wait for a high signal from thermistor PIC Display second set of instructions after thermistor temperature has been raised due to a hand on the thermistor.

18

LCDOUT $FE, 1, " On the screen below" LCDOUT $FE,$C0,"press on your answer" LCDOUT $FE,$94," with the stylus" PAUSE 5000 SEROUT LCD2, mode, [Val] Question_1: LCDOUT $FE, 1, " What was Mario's" LCDOUT $FE,$C0,"original profession" LCDOUT $FE,$94,"before 'Super Mario" LCDOUT $FE,$D4,"Bros.'?" loop: Pause 100 ADCIN 6, TS_Value If (TS_Value>10500) && (TS_Value<13500) Then Val = 20 SEROUT LCD2, mode, [Val] Goto Question_2 Endif If (TS_Value>8000) && (TS_Value<10500) OR (TS_Value>13500) && (TS_Value<18000) Then Val = 30 SEROUT LCD2, mode, [Val] Goto Question_3 Endif Goto loop Question_2: LCDOUT $FE, 1, " Besides green, Koopa" LCDOUT $FE,$C0,"Troopas come in what" LCDOUT $FE,$94,"other color?" Pause 2000 loop1: Pause 100 ADCIN 6, TS_Value If (13500<TS_Value) && (TS_Value<16000) Then Val = 40 SEROUT LCD2, mode, [Val] Goto Question_4 Endif If (TS_Value>8000) && (TS_Value<13500) OR (TS_Value>16000) && (TS_Value<18000) Then Val = 50 SEROUT LCD2, mode, [Val] Goto Question_5

Serial out a value of 10 to the LCD2 PIC so that it can display the multiple choice answers to question 1 Display question 1 Read a user input If user answers question right (c) serial out a value of 20 to LCD2 PIC and display question 2 on LCD1 If user answers question wrong (not c) serial out a value of 30 to LCD2 PIC and display question 3 on LCD1 Display question 2 Read a user input If user answers question right (b) serial out a value of 40 to LCD2 PIC and display question 4 on LCD1 If user answers question wrong (not b) serial out a value of 50 to LCD2 PIC and display question 5 on LCD1

19

Endif Goto loop1 Question_3: LCDOUT $FE, 1, " What Nintendo hero" LCDOUT $FE,$C0,"is more recognizable" LCDOUT $FE,$94,"to kids than Mickey" LCDOUT $FE,$D4,"Mouse or Bugs Bunny?" Pause 2000 loop2: Pause 100 ADCIN 6, TS_Value If (16000<TS_Value) && (TS_Value<18000) Then Val = 60 SEROUT LCD2, mode, [Val] Goto Question_6 Endif If (TS_Value>8000) && (TS_Value<16000) Then Val = 70 SEROUT LCD2, mode, [Val] Goto Question_7 Endif Goto loop2 Question_4: LCDOUT $FE, 1, " How many unique" LCDOUT $FE,$C0,"levels are there in" LCDOUT $FE,$94,"'Super Mario" LCDOUT $FE,$D4,"Brothers'?" Pause 2000 loop3: Pause 100 ADCIN 6, TS_Value If (8000<TS_Value) && (TS_Value<10500) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Red1 Endif If (TS_Value>10500) && (TS_Value<18000) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Green2 Endif Goto loop3 Question_5: LCDOUT $FE, 1, " How many different"

Display question 3 Read a user input If user answers question right (a) serial out a value of 60 to LCD2 PIC and display question 6 on LCD1 If user answers question wrong (not a) serial out a value of 70 to LCD2 PIC and display question 7 on LCD1 Display question 4 Read a user input If user answers question right (d) serial out a value of 80 to LCD2 PIC and go to Red1 loop If user answers question wrong (not d) serial out a value of 80 to LCD2 PIC and go to Green2 loop Display question 5

20

LCDOUT $FE,$C0,"controllers can you" LCDOUT $FE,$94,"play 'Mario Kart" LCDOUT $FE,$D4,"Wii' with?" Pause 2000 loop4: Pause 100 ADCIN 6, TS_Value If (13500<TS_Value) && (TS_Value<16000) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Green2 Endif If (TS_Value>8000) && (TS_Value<13500) OR (TS_Value>16000)&&(TS_Value<18000) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Green1 Endif Goto loop4 Question_6: LCDOUT $FE, 1, " In the beginning of" LCDOUT $FE,$C0,"'Super Mario 64,'" LCDOUT $FE,$94,"what gift does Peach" LCDOUT $FE,$D4,"offer to Mario?" Pause 2000 loop5: Pause 100 ADCIN 6, TS_Value If (10500<TS_Value) && (TS_Value<13500) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Green2 Endif If (TS_Value>8000) && (TS_Value<10500) OR (TS_Value>13500) && (TS_Value<18000) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Green1 Endif Goto loop5 Question_7: LCDOUT $FE, 1, " What character can" LCDOUT $FE,$C0,"you not choose to be" LCDOUT $FE,$94,"in 'Super Mario" LCDOUT $FE,$D4,"Brothers 2'?"

Read a user input If user answers question right (b) serial out a value of 80 to LCD2 PIC and go to Green2 loop If user answers question wrong (not b) serial out a value of 80 to LCD2 PIC and go to Green1 loop Display question 6 Read a user input If user answers question right (c) serial out a value of 80 to LCD2 PIC and go to Green2 loop If user answers question wrong (not c) serial out a value of 80 to LCD2 PIC and go to Green1 loop Display question 7

21

Pause 2000 loop6: Pause 100 ADCIN 6, TS_Value If (13500<TS_Value) && (TS_Value<16000) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Green1 Endif If (TS_Value>8000) && (TS_Value<13500) OR (TS_Value>16000) && (TS_Value<18000) Then Val = 80 SEROUT LCD2, mode, [Val] Goto Blue1 Endif Goto loop6 Red1: High DISP2 LCDOUT $FE, 1, " You got" LCDOUT $FE,$C0, " 3 out of 3" LCDOUT $FE,$94, " correct" Pause 10000 Low DISP2 Goto Final Green1: High DISP1 LCDOUT $FE, 1, " You got" LCDOUT $FE,$C0, " 1 out of 3" LCDOUT $FE,$94, " correct" Pause 10000 Low DISP1 Goto Final Green2: High DISP1 LCDOUT $FE, 1, " You got" LCDOUT $FE,$C0, " 2 out of 3" LCDOUT $FE,$94, " correct" Pause 10000 Low DISP1 Goto Final Blue1: High DISP3 LCDOUT $FE, 1, " You got"

Read a user input If user answers question right (b) serial out a value of 80 to LCD2 PIC and go to Green1 loop If user answers question wrong (not b) serial out a value of 80 to LCD2 PIC and go to Blue1 loop Send a high signal to dispenser 2 on dispenser PIC, display number of correct answers (3) out of three and then go to Final loop Send a high signal to dispenser 1 on dispenser PIC, display number of correct answers (1) out of three and then go to Final loop Send a high signal to dispenser 1 on dispenser PIC, display number of correct answers (2) out of three and then go to Final loop Send a high signal to dispenser 3 on dispenser PIC, display number of correct answers (0) out of three and then go to Final loop

22

LCDOUT $FE,$C0, " 0 out of 3" LCDOUT $FE,$94, " correct" Pause 10000 Low DISP3 Goto Final Final: LCDOUT $FE, 1, " Thank you" LCDOUT $FE,$C0," for playing." LCDOUT $FE,$D4," Project made by" Pause 10000 Goto Blank Blank: LCDOUT $FE, 1, " " Pause 1000 Goto Blank

Display Thank You and end credits on LCD1 and LCD2 Leave LCD blank until PIC is reset

3.2 LCD2 PIC code:

Code Comments

Include "modedefs.bas" DEFINE OSC 8 OSCCON.4 = 1 OSCCON.5 = 1 OSCCON.6 = 1 ANSEL = 0 Val var Byte Loading Var Byte Loading = 0 Intro Var Byte Intro = 0 mode con 2 Mario: LCDOUT $FE, 1, " MARIOMARIOMARIO" LCDOUT $FE,$C0,"OMARIOMARIOMARI" LCDOUT $FE,$94,"IOMARIOMARIOMAR" LCDOUT $FE,$D4,"RIOMARIOMARIOMA" loop: SERIN PORTB.0, mode, Val If (Val = 10) Then Gosub Question_1 Endif If (Val = 20) Then

Needed for serial communication between LCD2 PIC and LCD1 PIC Define variables Display Mario Wait for a serial out from LCD1 PIC and go to Question_X loop when value X0 is received

23

Gosub Question_2 Endif If (Val = 30) Then Gosub Question_3 Endif If (Val = 40) Then Gosub Question_4 Endif If (Val = 50) Then Gosub Question_5 Endif If (Val = 60) Then Gosub Question_6 Endif If (Val = 70) Then Gosub Question_7 Endif If (Val = 80) Then Gosub Dispensing Endif Goto loop Question_1: LCDOUT $FE, 1, " A: Mechanic" LCDOUT $FE,$C0,"B: Plumber" LCDOUT $FE,$94,"C: Carpenter" LCDOUT $FE,$D4,"D: Painter" Return Question_2: LCDOUT $FE, 1, " A: Yellow" LCDOUT $FE,$C0,"B: Red" LCDOUT $FE,$94,"C: Blue" LCDOUT $FE,$D4,"D: Orange" Return Question_3: LCDOUT $FE, 1, " A: Mario" LCDOUT $FE,$C0,"B: Bowser" LCDOUT $FE,$94,"C: Luigi" LCDOUT $FE,$D4,"D: Toad" Return Question_4: LCDOUT $FE, 1, " A: 21" LCDOUT $FE,$C0,"B: 12"

Display multiple choice answers to question 1 on LCD2 if a value of 10 is received in the serial out from LCD1 PIC Display multiple choice answers to question 2 on LCD2 if a value of 20 is received in the serial out from LCD1 PIC Display multiple choice answers to question 3 on LCD2 if a value of 30 is received in the serial out from LCD1 PIC Display multiple choice answers to question 4 on LCD2 if a value of 40 is received in the serial out from LCD1 PIC

24

LCDOUT $FE,$94,"C: 25" LCDOUT $FE,$D4,"D: 27" Return Question_5: LCDOUT $FE, 1, " A: 2" LCDOUT $FE,$C0,"B: 4" LCDOUT $FE,$94,"C: 3" LCDOUT $FE,$D4,"D: 6" Return Question_6: LCDOUT $FE, 1, " A: A Kiss" LCDOUT $FE,$C0,"B: A New Cap" LCDOUT $FE,$94,"C: A Cake" LCDOUT $FE,$D4,"D: A Stache Comb" Return Question_7: LCDOUT $FE, 1, " A: Toad" LCDOUT $FE,$C0,"B: Yoshi" LCDOUT $FE,$94,"C: Luigi" LCDOUT $FE,$D4,"D: Princess Peach" Return Dispensing: LCDOUT $FE, 1, " Dispensing" LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94," ." Pause 250 LCDOUT $FE, 1, " Dispensing" LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94," ..." Pause 250 LCDOUT $FE, 1, " Dispensing" LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94," ....." Pause 250 LCDOUT $FE, 1, " Dispensing" LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94," ......." Pause 250 LCDOUT $FE, 1, " Dispensing" LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94," ........." Pause 250 LCDOUT $FE, 1, " Dispensing"

Display multiple choice answers to question 5 on LCD2 if a value of 50 is received in the serial out from LCD1 PIC Display multiple choice answers to question 6 on LCD2 if a value of 60 is received in the serial out from LCD1 PIC Display multiple choice answers to question 7 on LCD2 if a value of 70 is received in the serial out from LCD1 PIC Run through dispensing loop display if a value of 80 is received in the serial out from LCD1 PIC

25

LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94," ..........." Pause 250 LCDOUT $FE, 1, " Dispensing" LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94," ............." Pause 250 LCDOUT $FE, 1, " Dispensing" LCDOUT $FE,$C0," Gumball" LCDOUT $FE,$94,"..............." Pause 250 If (Loading == 4) Then Goto Blank Else Loading = Loading + 1 Goto Dispensing Endif Blank: LCDOUT $FE, 1, " Eddy B." LCDOUT $FE, $C0, "Ethan F." LCDOUT $FE, $94, "Brent M." LCDOUT $FE, $D4, "Taylor S." Pause 50000 loop2: LCDOUT $FE, 1, " " Goto loop2

Go through the dispensing loop 4 times and then go to Blank loop Display end credits and then leave LCD2 blank until PIC is reset

3.3 Dispenser PIC code:

Code Comments

DEFINE OSC 8 OSCCON.4 = 1 OSCCON.5 = 1 OSCCON.6 = 1 ANSEL = 0 c2 CON 65 d2 CON 70 f2 CON 87 gf2 CON 93 g2 CON 98 af3 CON 104 a3 CON 110 b3 CON 123

Set frequencies for the notes used in songs

26

c3 CON 131 d3 CON 139 e3 CON 165 ef3 CON 156 f3 CON 175 gf3 CON 185 g3 CON 196 af4 CON 208 a4 CON 220 bf4 CON 233 b4 CON 247 c4 CON 262 df4 CON 277 d4 CON 294 ef4 CON 311 e4 CON 330 f4 CON 349 gf4 CON 370 g4 CON 392 af5 CON 415 a5 CON 440 bf5 CON 466 b5 CON 494 c5 CON 523 df5 CON 554 d5 CON 587 ef5 CON 622 e5 CON 659 f5 CON 698 gf5 CON 740 g5 CON 784 af6 CON 831 a6 CON 880 bf6 CON 932 b6 CON 988 c6 CON 1047 r CON 48 q CON 188 lq CON 200 t CON 125 h CON 375 th CON 250 w CON 750 s CON 15 z CON 10 i CON 95

Set time for the note lengths used in the songs

27

x CON 48 TRISA = %10000001 TRISB = %10000000 ''''''''''''''''INPUTS'''''''''''''''''' Green Var PORTA.0 Blue Var PORTA.7 Red Var PORTB.7 ''''''''''''''''OUTPUTS'''''''''''''''''' DISP1 Var PORTB.5 DISP2 Var PORTB.2 DISP3 Var PORTB.3 Cannon Var PORTB.6 ElevatorMotor Var PORTB.1 Low DISP1 Low DISP2 Low DISP3 Low Cannon Low ElevatorMotor main: If (Red = 1) Then Gosub three Endif If (Green = 1) Then Gosub onetwo Endif If (Blue = 1) Then Gosub zero Endif Pause 10 Goto main three: High DISP1 Pause 500 Low DISP1 Pause 10 Gosub UnderGround1 Gosub UnderGround2 High Cannon Pause 300 Low Cannon Gosub UnderGround3

Set I/O pins Define variables Set ports initially low Wait for a high signal on the Red, Green or Blue ports form LCD1 to run three, onetwo, or zero loop respectively Turn on motor to dispense a red gumball from storage tube Go to UnderGround1 loop Go to UnderGround2 loop Trigger solenoid valve to fire cannon with gumball inside Go to UnderGround3 loop Go to Flagpole loop

28

Gosub Flagpole Return onetwo: High DISP2 Pause 500 Low DISP2 Pause 10 Gosub UnderGround1 Pause 500 High Cannon Pause 300 Low Cannon Gosub UnderGround2 Pause 500 Gosub Flagpole Return zero: High DISP3 Pause 500 Low DISP3 Return Flagpole: Pause 2000 High ElevatorMotor pause w freqout PortA.1, h, f2 freqout PortA.1, r, g2 freqout PortA.1, r, a3 freqout PortA.1, r, b3 freqout PortA.1, r, c3 freqout PortA.1, r, d3 freqout PortA.1, r, e3 freqout PortA.1, r, f3 freqout PortA.1, r, g3 freqout PortA.1, r, a4 freqout PortA.1, r, b4 freqout PortA.1, r, c4 freqout PortA.1, r, d4 freqout PortA.1, r, e4 freqout PortA.1, r, f4 freqout PortA.1, r, g4 freqout PortA.1, r, a5 freqout PortA.1, r, b5 freqout PortA.1, r, c5

Turn on motor to dispense a green gumball from storage tube Go to UnderGround1 loop Trigger solenoid valve to fire cannon with gumball inside Go to UnderGround2 loop Go to Flagpole loop Turn on motor to dispense a blue gumball from storage tube Turn on motor to run elevator to send gumball to user Flagpole song

29

freqout PortA.1, r, d5 freqout PortA.1, r, e5 freqout PortA.1, r, f5 freqout PortA.1, q, g5 pause w freqout PortA.1, lq, f2 freqout PortA.1, t, c3 freqout PortA.1, t, e3 freqout PortA.1, t, g3 freqout PortA.1, t, c4 freqout PortA.1, t, e4 freqout PortA.1, h, g4 freqout PortA.1, h, e4 freqout PortA.1, t, gf2 freqout PortA.1, t, c3 freqout PortA.1, t, ef3 freqout PortA.1, t, af4 freqout PortA.1, t, c4 freqout PortA.1, t, ef4 freqout PortA.1, h, af5 freqout PortA.1, h, ef4 freqout PortA.1, t, af3 freqout PortA.1, t, d3 freqout PortA.1, t, f3 freqout PortA.1, t, bf4 freqout PortA.1, t, d4 freqout PortA.1, t, f4 freqout PortA.1, h, bf5 pause s freqout PortA.1, t, bf5 pause s freqout PortA.1, t, bf5 pause s freqout PortA.1, t, bf5 pause s freqout PortA.1, w, c5 Pause 2000 Low ElevatorMotor Return UnderGround1: freqout PortA.1, q, c4 freqout PortA.1, q, c5 freqout PortA.1, q, a4 freqout PortA.1, q, a5 freqout PortA.1, q, bf4 freqout PortA.1, q, bf5

Turn elevator motor off Under ground song part 1

30

pause h pause w freqout PortA.1, q, c4 freqout PortA.1, q, c5 freqout PortA.1, q, a4 freqout PortA.1, q, a5 freqout PortA.1, q, bf4 freqout PortA.1, q, bf5 Return UnderGround2: freqout PortA.1, q, f3 freqout PortA.1, q, f4 freqout PortA.1, q, d3 freqout PortA.1, q, d4 freqout PortA.1, q, ef3 freqout PortA.1, q, ef4 pause h pause w freqout PortA.1, q, f3 freqout PortA.1, q, f4 freqout PortA.1, q, d3 freqout PortA.1, q, d4 freqout PortA.1, q, ef3 freqout PortA.1, q, ef4 Return UnderGround3: pause h freqout PortA.1, t, ef4 freqout PortA.1, t, d4 freqout PortA.1, t, df4 freqout PortA.1, h, c4 freqout PortA.1, h, ef4 freqout PortA.1, h, d4 freqout PortA.1, h, af4 freqout PortA.1, h, g3 freqout PortA.1, h, df4 freqout PortA.1, t, c4 freqout PortA.1, t, gf4 freqout PortA.1, t, f4 freqout PortA.1, t, e4 freqout PortA.1, t, bf5 freqout PortA.1, t, a5 freqout PortA.1, th, af5 freqout PortA.1, th, ef4 freqout PortA.1, th, b4

Under ground song part 2 Under ground song part 3

31

freqout PortA.1, th, bf4 freqout PortA.1, th, a4 freqout PortA.1, th, af4 Return

3.4 Thermistor PIC code:

Code Comments

DEFINE OSC 8 OSCCON.4 = 1 OSCCON.5 = 1 OSCCON.6 = 1 ANSEL = 0 pot_pin Var PORTA.2 SCALE Con 255 pot_val Var BYTE pot_valo Var BYTE TRISA = %10111101 TRISB = %00000000 PORTA = 0 PortB = 0 POT pot_pin,SCALE,pot_valo enter: POT pot_pin,SCALE,pot_val If (pot_val < pot_valo-5) Then goto go Else Low PORTA.1 Goto enter Endif go: HIGH PORTB.0 Pause 250 LOW PORTB.0 HIGH PORTB.1 Pause 250 LOW PORTB.1 HIGH PORTB.3 Pause 250 HIGH PORTB.4

Define variables Define I/O pins Read and store thermistor resistance at an initial temperature (ideally room temperature) Read thermistor resistance If thermistor resistance is smaller than the initial resistance, temperature has gone up. This means the code goes to the “go” loop. Otherwise it keeps reading the thermistor’s resistance. Run LED array and send a high signal to LCD1 PIC through PORTA.1

32

LOW PORTB.3 Pause 250 LOW PORTB.4 HIGH PORTB.5 Pause 250 LOW PORTB.5 Pause 250 HIGH PORTB.5 Pause 250 LOW PORTB.5 HIGH PORTB.4 Pause 250 LOW PORTB.4 HIGH PORTB.3 Pause 250 HIGH PORTB.2 LOW PORTB.3 Pause 250 LOW PORTB.1 HIGH PORTB.0 Pause 250 LOW PORTB.0 HIGH PORTA.1 Pause 250 Pause 500 HIGH PORTB.0 HIGH PORTB.1 HIGH PORTB.3 HIGH PORTB.4 HIGH PORTB.5 Pause 500 LOW PORTB.0 LOW PORTB.1 LOW PORTB.3 LOW PORTB.4 LOW PORTB.5 PAUSE 500 HIGH PORTB.0 HIGH PORTB.1 HIGH PORTB.3 HIGH PORTB.4 HIGH PORTB.5 Pause 500 LOW PORTB.0 LOW PORTB.1 LOW PORTB.3 LOW PORTB.4

33

LOW PORTB.5 PAUSE 500 HIGH PORTB.0 HIGH PORTB.1 HIGH PORTB.3 HIGH PORTB.4 HIGH PORTB.5 Pause 500 LOW PORTB.0 LOW PORTB.1 LOW PORTB.3 LOW PORTB.4 LOW PORTB.5 PAUSE 500 End

3.5 Teleporter PIC code:

Code Comment

DEFINE OSC 8 OSCCON.4 = 1 OSCCON.5 = 1 OSCCON.6 = 1 TRISA = %10000001 TRISB = %00000000 ''''''''''PORT A''''''''''''' Photogate Var PORTA.0 Door1 Var PORTA.1 Door2 Var PORTA.2 Low Door1 Low Door2 Pause 500 loop: If (Photogate == 0) Then gosub power Else Goto loop Endif Goto loop power: High Door1 Pause 1000

Define I/O pins Define variables Set ports initially low Read the Photo Gate Value Raise and lower Door1 and Door2/Entrance and Exit Doors for teleporter

34

Low Door1 Pause 100 High Door2 Pause 1000 Low Door2 Pause 2000 Return End