Mario Trivia Gumball Machine

Transcription

Mario Trivia Gumball Machine
Mario Trivia Gumball Machine
May 6, 2011
MECH 307
Mechatronics
Colorado State University
Ed Brinkhoff
Ethan Franck
Brent Mackenzie
Taylor Steinbaugh
1
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
2
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.
3
Dispenser
Unit
User Interface
Teleporter
Ladder
Piranha Plant
Elevator
Cannon
4
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.
Contrast
Dial
Master
Power
Switch
LCD Display &
Touchscreen
Magnetic
Stylus
5
Thermistor
2.1.2
Dispenser/Elevator/Cannon/Music
Main Controller Breadboard
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.
Gumball
Storage Tube
Control Leads
(from PIC)
Speaker
12V DC Motor
Leads from
PIC
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.
6
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.
Catching Funnel
Barrel
Compressed
Air
12V Solenoid
Valve
Donkey Kong
Ladder
7
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.
Tube from Ladder
Elevator Base
Gumball Guide
Gumball Retrieval
Unit
12V DC Motor
If the user answers only 1 or 2 questions correctly, the gumball will skip the teleporter and
proceed directly to the cannon.
8
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.
Top View of Piranha Plant
Gumball Storage on back of machine
This is Nick.
9
2.1.2
Teleporter and Photogate
Guide Rail
12V Linear
Actuator
Photogate
“Tube”
Entrance
Back Of
Trap Door
Entrance
Return
Band
Exit
10
2.2 Wiring Diagrams
2.2.1 Overall Circuit Diagram
20 X 4 LCD character display
20 X 4 LCD character display
1
2
3
4
1
5V
2
3
4
11
5 6
12 13
14 15
1
16
2
3
4
11
5 6
12 13
14 15
16
12 V
Elevator
Motor
5
6
5V
5V
1 RA2
Pot
2
5V
5V
5V
3
4
5
6
7
PIC16F88
RA1
RA3
RA0
RA4
RA7
RA5
Vss
LCD 2
PIC
RB0
CLKO
Vdd
RB7
RB1
RB6
RB2
RB5
9 RB3
RB4
8
5V
Pot
18
1 RA2
17
2
16
3
5V
15
4
5V
14
5
13
6
0.1 µF
12
PIC16F88
RA1
RA3
RA0
RA4
RA7
RA5
Vss
LCD 1
PIC
CLKO
Vdd
RB0
RB7
RB1
RB6
RB2
RB5
9 RB3
RB4
7
11
8
10
NTC 103
Thermistor
0.1 µF
13
1
7
330Ω
9
PIC16F88
1
2
18
RA2
RA1
RA3
RA0
3
RA4
RA7
RA5
CLKO
5
Vss
RB0
Dispenser
PIC
330Ω
15
14
5V
Infrared
emitter
Vdd
RB7
7
13
12
RB1
RB6
RB2
RB5
8
9
5V
16
4
6
Infrared
detector
17
5V
0.1 µF
11
RB3
RB4
10
11
RA0
RA4
RA7
RA5
CLKO
Vss
Dispenser
PIC
Vdd
RB0
RB7
RB1
RB6
RB2
RB5
RB3
0.1 µF
11
Touch screen
voltage input
10
8
0.1 µF
0.1 µF
5V
1kΩ
12
330Ω
0.1 µF
RA3
RB4
14
6
12 V
RA1
Disp 2/Red
gumball dispenser
motor
12 V
15
5
Linear
actuator/
Door 1/
Entrance
Door
9
16
4
Linear
actuator/
Door 2/Exit
Door
8
Disp 3/Blue
gumball dispenser
motor
17
2
330Ω
7
18
3
12 V
0.1 µF
PIC16F88
RA2
PIC16F88
RA2
RA1
RA3
RA0
RA4
RA7
RA5
Vss
CLKO
Thermistor
PIC
Vdd
RB0
RB7
RB1
RB6
RB2
RB5
RB3
RB4
18
17
16
0.1 µF
15
14
5V
13
12
330Ω
11
330Ω
10
12 V
18
Speaker
17
16
15
0.1 µF
5V
14
13
Solenoid valve
for cannon
12 V
12
11
0.1 µF
10
Disp 1/Green
gumball dispenser
motor
0.1 µF
12 V
2.2.2 LCD1
20 X 4 LCD character display
Vss Vcc Vee RS R/W E
1
2
3
4
5
DB4 DB5 DB6 DB7
11
6
12
13
14
15
16
5V
5V
5V
Pot
PIC16F88
1
2
18
RA2
RA1
RA3
RA0
RA4
RA7
RA5
CLKO
Vss
Vdd
RB0
RB7
RB1
RB6
RB2
RB5
RB3
RB4
3
5V
16
4
5
To LCD2 PIC for
serial
communication
6
15
14
7
13
1kΩ
5V
12
8
9
17
11
Touch
screen
voltage
input
10
Output to
Dispenser PIC
Input from
Thermistor PIC
12
2.2.3 LCD2
20 X 4 LCD character display
Vss Vcc Vee RS R/W E
1
2
3
4
5
DB4 DB5 DB6 DB7
11
6
12
13
14
15
16
5V
5V
5V
Pot
PIC16F88
1
2
18
RA2
RA1
RA3
RA0
RA4
RA7
RA5
CLKO
Vss
Vdd
RB0
RB7
3
5V
16
4
5
From LCD1 PIC
for serial
communication
6
15
14
7
13
12
RB1
RB6
RB2
RB5
RB3
RB4
8
9
17
11
13
10
5V
0.1 µF
2.2.4 Thermistor
NTC 103
Thermistor
0.1 µF
PIC16F88
1
2
18
RA2
RA1
RA3
RA0
RA4
RA7
RA5
CLKO
Vss
Vdd
RB0
RB7
RB1
RB6
3
5
330Ω
330Ω
7
0.1 µF
5V
13
12
8
9
15
14
11
RB2
330Ω
17
16
4
6
To LCD1 PIC
330Ω
RB5
RB3
RB4
14
10
330Ω
2.2.5 Dispenser/Elevator/Music/Cannon
Speaker
PIC16F88
1
2
18
RA2
RA1
RA3
RA0
RA4
RA7
RA5
CLKO
Vss
Vdd
RB0
RB7
RB1
RB6
RB2
RB5
RB3
RB4
3
5
12 V
0.1 µF
6
7
12 V
0.1 µF
9
15
0.1 µF
14
13
12
8
Disp 3/Blue
gumball
dispenser
motor
17
16
4
Elevator
Motor
Input from
LCD1 PIC
11
Disp 2/Red
gumball
dispenser
motor
12 V
Solenoid
valve for
Cannon
5V
12 V
0.1 µF
10
Disp 1/Green
gumball
dispenser
motor
0.1 µF
0.1 µF
15
12 V
2.2.6 Teleporter/Photogate
12 V
Linear
actuator/
Door 1/
Entrance
Door
Linear
actuator/
Door 2/Exit
Door
12 V
0.1 µF
0.1 µF
PIC16F88
1
2
18
RA1
RA2
RA3
RA0
RA4
RA7
3
RA5
CLKO
Vss
Vdd
5
330Ω
15
14
RB0
RB7
7
13
12
RB1
RB6
RB2
RB5
RB3
RB4
8
9
5V
16
4
6
Infrared
detector
17
11
16
10
5V
Infrared
emitter
5V
0.1 µF
3 PicBasic Pro Code
3.1 LCD1 PIC code:
Code
Include "modedefs.bas"
Comments
Needed for serial communication between PICs
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
Define A/D converter pin
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
Define variables
Low DISP1
Low DISP2
Low DISP3
Make dispenser pins initially low
LCDOUT $FE,1," Please place your "
LCDOUT $FE,$C0,"hand on the scanner"
LCDOUT $FE,$94," to your right"
Display first set of instructions
Therm1:
If (Therm = 1) Then
Goto main
Else
Goto Therm1
Endif
Wait for a high signal from thermistor PIC
main:
Val = 10
LCDOUT $FE, 1, " Please answer the "
LCDOUT $FE,$C0,"following questions "
PAUSE 5000
Display second set of instructions after thermistor
temperature has been raised due to a hand on the
thermistor.
17
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]
Serial out a value of 10 to the LCD2 PIC so that it
can display the multiple choice answers to
question 1
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
Display question 1
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
Display question 2
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
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
18
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
Display question 3
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
Display question 4
Question_5:
LCDOUT $FE, 1, " How many different"
Display question 5
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
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
19
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
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
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
Display question 6
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'?"
Display question 7
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
20
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, "
LCDOUT $FE,$C0, "
LCDOUT $FE,$94, "
Pause 10000
Low DISP2
Goto Final
Green1:
High DISP1
LCDOUT $FE, 1, "
LCDOUT $FE,$C0, "
LCDOUT $FE,$94, "
Pause 10000
Low DISP1
Goto Final
Green2:
High DISP1
LCDOUT $FE, 1, "
LCDOUT $FE,$C0, "
LCDOUT $FE,$94, "
Pause 10000
Low DISP1
Goto Final
Blue1:
High DISP3
LCDOUT $FE, 1, "
You got"
3 out of 3"
correct"
You got"
1 out of 3"
correct"
You got"
2 out of 3"
correct"
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
21
LCDOUT $FE,$C0, "
LCDOUT $FE,$94, "
Pause 10000
Low DISP3
Goto Final
0 out of 3"
correct"
Final:
LCDOUT $FE, 1, " Thank you"
LCDOUT $FE,$C0," for playing."
LCDOUT $FE,$D4," Project made by"
Pause 10000
Goto Blank
Display Thank You and end credits on LCD1 and
LCD2
Blank:
LCDOUT $FE, 1, " "
Pause 1000
Goto Blank
Leave LCD blank until PIC is reset
3.2 LCD2 PIC code:
Code
Include "modedefs.bas"
Comments
Needed for serial communication between LCD2
PIC and LCD1 PIC
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
Define variables
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
Display Mario
Wait for a serial out from LCD1 PIC and go to
Question_X loop when value X0 is received
22
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
Display multiple choice answers to question 1 on
LCD2 if a value of 10 is received in the serial out
from LCD1 PIC
Question_2:
LCDOUT $FE, 1, " A: Yellow"
LCDOUT $FE,$C0,"B: Red"
LCDOUT $FE,$94,"C: Blue"
LCDOUT $FE,$D4,"D: Orange"
Return
Display multiple choice answers to question 2 on
LCD2 if a value of 20 is received in the serial out
from LCD1 PIC
Question_3:
LCDOUT $FE, 1, " A: Mario"
LCDOUT $FE,$C0,"B: Bowser"
LCDOUT $FE,$94,"C: Luigi"
LCDOUT $FE,$D4,"D: Toad"
Return
Display multiple choice answers to question 3 on
LCD2 if a value of 30 is received in the serial out
from LCD1 PIC
Question_4:
LCDOUT $FE, 1, " A: 21"
LCDOUT $FE,$C0,"B: 12"
Display multiple choice answers to question 4 on
LCD2 if a value of 40 is received in the serial out
from LCD1 PIC
23
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
Display multiple choice answers to question 5 on
LCD2 if a value of 50 is received in the serial out
from LCD1 PIC
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
Display multiple choice answers to question 6 on
LCD2 if a value of 60 is received in the serial out
from LCD1 PIC
Question_7:
LCDOUT $FE, 1, " A: Toad"
LCDOUT $FE,$C0,"B: Yoshi"
LCDOUT $FE,$94,"C: Luigi"
LCDOUT $FE,$D4,"D: Princess Peach"
Return
Display multiple choice answers to question 7 on
LCD2 if a value of 70 is received in the serial out
from LCD1 PIC
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"
Run through dispensing loop display if a value of
80 is received in the serial out from LCD1 PIC
24
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
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
loop2:
LCDOUT $FE, 1, "
Goto loop2
"
3.3 Dispenser PIC code:
Code
DEFINE OSC 8
OSCCON.4 = 1
OSCCON.5 = 1
OSCCON.6 = 1
ANSEL = 0
Comments
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
25
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
26
x CON 48
TRISA = %10000001
TRISB = %10000000
Set I/O pins
''''''''''''''''INPUTS''''''''''''''''''
Green
Var
Blue
Var
Red
Var
PORTA.0
PORTA.7
PORTB.7
''''''''''''''''OUTPUTS''''''''''''''''''
DISP1
Var
DISP2
Var
DISP3
Var
Cannon
Var
ElevatorMotor
Var
PORTB.5
PORTB.2
PORTB.3
PORTB.6
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
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
three:
High DISP1
Pause 500
Low DISP1
Pause 10
Gosub UnderGround1
Gosub UnderGround2
High Cannon
Pause 300
Low Cannon
Gosub UnderGround3
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
27
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
Turn on motor to dispense a green gumball from
storage tube
zero:
Turn on motor to dispense a blue gumball from
storage tube
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
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 run elevator to send gumball to
user
Flagpole song
28
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
Turn elevator motor off
Return
Under ground song part 1
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
29
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
Under ground song part 2
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
Under ground song part 3
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
30
freqout PortA.1, th, bf4
freqout PortA.1, th, a4
freqout PortA.1, th, af4
Return
3.4 Thermistor PIC code:
Code
DEFINE OSC 8
OSCCON.4 = 1
OSCCON.5 = 1
OSCCON.6 = 1
ANSEL = 0
Comments
pot_pin Var PORTA.2
SCALE Con 255
pot_val Var BYTE
pot_valo Var BYTE
Define variables
Define I/O pins
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
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.
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
Run LED array and send a high signal to LCD1 PIC
through PORTA.1
31
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
32
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
DEFINE OSC 8
OSCCON.4 = 1
OSCCON.5 = 1
OSCCON.6 = 1
Comment
TRISA = %10000001
TRISB = %00000000
Define I/O pins
''''''''''PORT A'''''''''''''
Photogate
Var PORTA.0
Door1
Var PORTA.1
Door2
Var PORTA.2
Low Door1
Low Door2
Pause 500
Define variables
Set ports initially low
loop:
If (Photogate == 0) Then
gosub power
Else
Goto loop
Endif
Goto loop
Read the Photo Gate Value
power:
High Door1
Pause 1000
Raise and lower Door1 and Door2/Entrance and
Exit Doors for teleporter
33
Low Door1
Pause 100
High Door2
Pause 1000
Low Door2
Pause 2000
Return
End
34

Similar documents