Melanie's Bouncing Ball
===================
Example of what we've been talking about... No - I've not had a
sex-change! Everyone does Cylons or Knight Rider as an example
(boring - that's for kid's)... we'll be different (adult, grown-up,
X-rated version)... there I was all dressed up in my tight leather
catwoman outfit with chromed spikes, playing with someone's ball (*see
note at end) the other day and watching it bounce...
' MelsBall.bas
' Melanie's Bouncing Ball
' ----------------
' No wise cracks!
' 8 LED's on PORTB, connected Anode to PIC
' all Cathodes commoned and via a single
' 270R Resistor to Vss. since no two LED's
' will be on at a time, we can be economical
' with the Resistors... they're expensive...
'
' PIC Defines
' -----------
@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic16F628, WDT_ON
' Watchdog Timer
@ DEVICE pic16F628, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic16F628, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F628, PROTECT_OFF
' Program Code Protection
'
' Software Defines
' ----------------
PortBPin var byte
DecayBounce var byte
GravityDelay var word
'
' Initialise Hardware
' -------------------
CMCON=%00000111
TRISA=%00000000
TRISB=$00000000
PORTB=0 ' All LED's OFF
' Ground Level = PORTB.0
' Highest Bounce point = PORTB.7
'
' Main Program Loop
' -----------------
DoAgain:
'
' Drop Ball
' ---------
DecayBounce=7
DecayLoop:
GravityDelay=256
For PortBPin=DecayBounce to 0 step -1
High PortBPin
Gosub Accelerate
Low PortBPin
Next PortBPin
'
' Rebound
' -------
DecayBounce=DecayBounce-1
For PortBPin=0 to DecayBounce
High PortBPin
Gosub Decelerate
Low PortBPin
Next PortBPin
'
' New Apex
' --------
If DecayBounce=0 then
High 0
Pause 1500
Low 0
Pause 1500
Goto DoAgain
endif
Goto DecayLoop
'
' Subroutine Accelerates Ball
' ---------------------------
Accelerate:
GravityDelay=GravityDelay/2
Pause GravityDelay
Return
'
' Subroutine Decelerates Ball
' ---------------------------
Decelerate:
GravityDelay=GravityDelay*2
Pause GravityDelay
Return
end
Die-hard's will tell me it's not the formula for gravitational
acceleration - I don't care... it looks good and what do you expect
for a five-minute bit of code and eight LED's. If you got time to
burn, tweak your own formula's...
* Note - Tennis Ball *smiles*
Melanie
Bookmarks