spoiledgumballmachine.com
documentation
http://spoiledgumball.blogspot.com/
‘****************************************************************
‘* Name : gumball121205.BAS *
‘* Author : gumball group *
‘* Notice : Copyright (c) 2004 [select VIEW...EDITOR OPTIONS] *
‘* : All Rights Reserved *
‘* Date : 12/12/2005 *
‘* Version : 1.0 *
‘* Notes : *
‘* : *
‘****************************************************************
DEFINE OSC 4
start:
INCLUDE “modedefs.bas”
‘ Define ADCIN parameters
‘ Set number of bits in result
DEFINE ADC_BITS 10
‘ Set clock source (3=rc)
DEFINE ADC_CLOCK 3
‘ Set sampling time in microseconds
DEFINE ADC_SAMPLEUS 10
‘ Set PORTA to all input
TRISA = %11111111
‘ Set up ADCON1 analog and right justify the result
adcon1 = %10000010
pause 500
‘define inputs and outputs
‘test
output PORTD.0
‘LEDs for testing
OUTPUT PORTD.1
‘play
OUTPUT PORTD.2
’stop
OUTPUT PORTD.3
‘FF
OUTPUT PORTC.4
‘RW
OUTPUT PORTC.5
’solenoids
OUTPUT PORTC.1
OUTPUT PORTC.2
OUTPUT PORTC.3
‘LEDs
OUTPUT PORTB.0
‘PIEZO from other board
INPUT PORTB.6
‘beginning switch
Input PORTB.7
’set all the input ports low
LOW PORTD.0
LOW PORTD.1
LOW PORTD.2
LOW PORTD.3
LOW PORTC.4
LOW PORTC.5
LOW PORTB.5
LOW PORTB.6
LOW PORTB.7
LOW PORTC.1
LOW PORTC.2
LOW PORTC.3
LOW PORTB.0
pause 500
‘define adc vars
adcVar1 VAR WORD ‘PIEZO(move)
adcVar2 VAR WORD ‘MIC(sound)
adcVar3 VAR WORD ‘FSR(touch)
’set vars
theStage var byte
trackPlayed VAR BYTE
jumpLevel var WORD
whisperLevel var WORD
touchLevel var WORD
startup var byte
counter VAR WORD
countEval var byte
petCounter VAR BYTE
’set your acceptable params here
jumpLevel = 500
whisperLevel = 300
touchLevel = 600
counter = 0
petCounter = 0
’set your booleans here
theStage = 0
trackPlayed =0
startup = 1
countEval =0
‘test out the start with LED blinking
HIGH PORTD.1
pause 200
LOW PORTD.1
pAUSE 200
HIGH PORTD.1
pause 200
LOW PORTD.1
pAUSE 200
HIGH PORTD.1
pause 200
LOW PORTD.1
pAUSE 200
”test out the start with Solenoid moving
‘HIGH PORTB.5
‘pause 500
‘LOW PORTB.5
‘pAUSE 500
‘HIGH PORTB.5
‘pause 500
‘LOW PORTB.5
‘pAUSE 500
‘prep the cd
IF startup = 1 Then
’start the CD player
HIGH PORTD.2
pause 500
low PORTD.2
pause 7000 ‘heating up time
‘pause the CD player
HIGH PORTD.2
pause 500
low PORTD.2
startup = 0
EndIf
main:
‘initiating cycle
if theStage = 0 then
‘if the user has turned the handle start the program
if PORTB.7 = 1 then
‘play the first track and pause cd player(#1)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 6500 ‘time of intro song
‘light up the LEDs
HIGH PORTB.0
PAUSE 7000
LOW PORTB.0
‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
theStage = 1
endIF
endIF
‘jump
if theStage = 1 then
‘make sure serial communicator has Baudrate of 9600!
‘trigger this with a boolean
if trackPlayed = 0 then
‘play the first track and pause cd player(#2)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 5500 ‘time of task one track
‘light up the LEDs
HIGH PORTB.0
PAUSE 6000
LOW PORTB.0
‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
trackPlayed = 1
endIF
‘we need to give some time test ppl’s jumping;
‘what if we have blank sound after the voice in a track
‘to give time to test instead of pausing??
‘make sure serial communicator has Baudrate of 9600!
test1
ADCIN 1, adcVar1
serout2 portc.6, 16468, [DEC adcVar1,10,13]
counter = counter + 1
‘light up the LEDs
IF adcVar1 >= jumplevel then
‘forward to the proper track
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
‘play the proper track(#4)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 2500 ‘time of third track
‘light up the LEDs
HIGH PORTB.0
PAUSE 3000
LOW PORTB.0
‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘open first solenoid
HIGH PORTC.1
PAUSE 2000
LOW PORTC.1
PAUSE 250
theStage = 2
trackPlayed = 0
countEval=1
ENDIF
‘not enough
IF counter = 1000 and countEval = 0 THEN
‘play the proper track(#3)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 5000 ‘time of third track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5500
LOW PORTB.0
‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘rewind the track
HIGH PORTC.5
PAUSE 500
LOW PORTC.5
PAUSE 500
counter = 0
GOTO test1
endIF
endIF
‘touch
if theStage = 2 then
‘trigger this with a boolean
if trackPlayed = 0 then
countEval = 0
counter = 0
‘play the second challenge track and pause cd player(#5)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 6500 ‘time of fourth track
‘light up the LEDs
HIGH PORTB.0
PAUSE 7000
LOW PORTB.0
‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
trackPlayed = 1
endIF
test2
ADCIN 2, adcVar2
serout2 portc.6, 16468, [ DEC adcVar2,10,13]
‘ petCounter = petCounter + 1
counter = counter + 1
if adcVar2 >= touchLevel then
petCounter = petCounter + 1
if petCounter = 200 then
‘forward to the proper track
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
‘play the proper track(#7)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 4500 ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5000
LOW PORTB.0
‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘open second solenoid
HIGH PORTC.2
PAUSE 2000
LOW PORTC.2
PAUSE 250
theStage = 3
trackPlayed = 0
countEval = 1
endif
endIF
‘not enough
IF counter = 1000 and countEval = 0 THEN
‘play the proper track(#6)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 8000 ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 8500
LOW PORTB.0
‘Pause CD player
High PORTD.2
PAUSE 250
LOW PORTD.2
PAUSE 250
‘rewind the track
HIGH PORTC.5
PAUSE 500
LOW PORTC.5
PAUSE 500
counter=0
GOTO test2
endIF
endIF
‘whisper
if theStage = 3 then
‘trigger this with a boolean
if trackPlayed = 0 then
countEval = 0
counter = 0
‘play the third challenge track and pause cd player(#8)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 8500 ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 9000
LOW PORTB.0
‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
trackPlayed = 1
endIF
test3
ADCIN 3, adcVar3
serout2 portc.6, 16468, [ DEC adcVar3,10,13]
counter = counter + 1
if adcVar3 >= whisperLevel then
‘forward to the proper track
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
‘play the proper track(#10)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 4500 ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5000
LOW PORTB.0
‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
theStage = 4
trackPlayed = 0
countEval = 1
endIF
‘not enough
IF counter = 1000 and countEval = 0 THEN
‘play the proper track(#9)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
pause 4500 ‘time of the track
‘light up the LEDs
HIGH PORTB.0
PAUSE 5000
LOW PORTB.0
‘Pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘rewind the track
HIGH PORTC.5
PAUSE 500
LOW PORTC.5
PAUSE 500
counter=0
GOTO test3
endIF
endif
‘celebration of achievement
if theStage = 4 then
‘trigger this with a boolean
if trackPlayed = 0 then
‘play the congratulations and reset cd player(#11)
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
Pause 8000 ‘time of final:good-bye track
‘light up the LEDs
HIGH PORTB.0
PAUSE 8500
LOW PORTB.0
‘pause CD player
High PORTD.2
PAUSE 500
LOW PORTD.2
PAUSE 250
‘ ‘open third solenoid
HIGH PORTC.3
PAUSE 2000
LOW PORTC.3
PAUSE 250
trackPlayed = 1
endIF
theStage = 5
trackPlayed = 0
endif
IF theStage = 5 THEN
‘reset the CD player (forward to the first track and wait)
HIGH PORTC.4
PAUSE 500
LOW PORTC.4
PAUSE 500
theStage = 0
LOW PORTB.7
ENDIF
goto main