Escape Room Puzzle Cube David Long and Timothy Blondin

advertisement
Escape Room Puzzle Cube
David Long and Timothy Blondin
Overview
●
●
Goals
Design
○
○
○
○
●
Coding approach
○
●
●
Physical structure
Simon game
Breakbeam box
Servo laser
Interrupts!
Challenges
End product
Goals
●
●
●
Implement concepts used in lab
to create a challenging escape
room puzzle
Challenge ourselves
Present a working product to a
potential client
Design - State Diagram
Design - Structure
●
●
●
●
●
●
●
●
●
3x photo-proximity sensors
3x photo-break-beam sensors + 1x prox
LCD panel + trimpot
laser diode + photocell
piezo buzzer
fixed-rotation servo + potentiometer
momentary push button switch
HCS12 microcontroller + SSMI board
24 VDC NiMH battery
Stage 1: Simon Game
●
●
●
most difficult to program
optoelectronic proximity
sensors instead of buttons
same sequence of 3 tones
○
●
Easy to randomize if desired
output compare, input capture
Stage 2: Laser Grid
●
●
Using Hokuyo PB1-FN and PB1-E
IR break beam sensors
Must maneuver around 4
sensors
○
○
●
Button!
Button on opposite end sends to
stage 3
Failure sends back to stage 1
Polling approach
m
a
Be
o’
D
th
ea
!
Bag o’ Goodies!
Stage 3: Servo laser
●
●
●
Like the servomotor lab, only with
interrupts!
A positive signal from a
photodetector wins the game
Anticipating trouble with ambient
light conditions
Coding Approach
●
●
●
●
Primarily interrupt-driven
High resolution in all parts
Pin limitations on HCS12
State Machine
○
○
○
○
State 1: Simon
State 2: Breakbeams
State 3: Servo Laser
State 4: Win/Disarmed
Pseudocode - initialization
include necessary libraries
global char array to hold LCD string (updated between states)
global servo duty, buzzer period, state variable, failure boolean
simon says goal tone/input durations, user input duration variable
Pseudocode - necessary functions
delay function (accepts milliseconds)
initialize phase locked loop clock adjustment for standalone operation
writeNibbleToLCD, writeByteToLCD, InitializeLCD, printLCD
Pseudocode - Interrupt Service Routines
●
●
●
TOVISR - Timer overflow, must keep track of overflows for user input times
OC6ISR - Speaker half-period toggling to generate buzzer square wave
IC0ISR,IC1ISR,IC2ISR - simon challenge interrupts on pins PT0-2.
○
●
●
Inside each, catch falling edge when sensor is obscured, then catch rising edge when sensor
is uncovered. Also keep track of time covered. Also play tone when covered.
IC3ISR,IC5ISR not required b/c laser grid box will be polled
OC4ISR - will control servo during state 3
○
Pulse high for duty cycle duration. Pulse low for remainder of 20 ms.
Pseudocode - main() - initialization
loop variables
initialize phase-locked loop
specify ports as input/output
initialize A/D converter for AD2 and AD3
initialize LCD
enable interrupts
Pseudocode - main() - switch state 1
print “level 1” and prompt to the LCD screen
set OC prescaler, trigger high
play a series of three tones by enabling buzzer (OC6) for durations, then silence
wait for user input….meanwhile ISR’s 0-2 handle all timing, calculation
when IC2 is passed correctly - it changes “state” to 2, which breaks through state
1
Pseudocode - main() - switch state 2
print “level 2” and prompt to the LCD screen
rapidly poll both PT3 and PT5 to see which is triggered first
If PT3 is pulled low, the break-beam was broken, sound alarm, reset to state 1
Else if PT5 is pulled low, the switch was pressed, disable system, state=3
else, just do nothing until user makes an error or succeeds
Pseudocode - main() - switch state 3
print “level 3” and prompt to the LCD screen
set OC prescaler for servo control
poll analog potentiometer - map to servo duty cycle
OC6 handles servo output based on set duty cycle
continuously poll CdS photocell for change in voltage which is held for duration
once held for duration, disable system, progress to state 4
Pseudocode - main() - switch state 4
print “congratulations” and whatever else to the LCD screen
idle forever
Timing Diagram - Simon
Challenges
●
Simon game coding
○
●
●
●
●
●
●
Far more complicated than anticipated
choosing bias resistors to convert from approx. 24 V to 5 V
so many wiring bundles
old capacitive sensors (and other hardware) failed
time
creative puzzles
debugging interrupt service routines
Conclusion
●
●
●
Anticipating success
Access to good hardware is beneficial
Interrupts are great, but brain-bending
Questions?
Wiring Diagram
Download