Ping Pong - The Remix

We finally got the Paddle to work wirelessly, and we have figured out how we will be strapping the paddles. What we have decided so far is to mount the breadboard and having these velcro straps wrap around them We hope to get everything done by this weekend so we will be able to do some userbility testing and be able to video tape the users in action! Below is the code we did.
‘****************************************************************
‘* Name : PP-PADDLE
‘* Author : Steven Jackson / Fazreen Kuhiri
‘* Notice : Copyright (c) 2005
‘* : All Rights Reserved
‘* Date : 12/1/2005
‘* Version : 1.0
‘* Notes : sending serial out (transmitter) from paddle
‘****************************************************************
define osc 4
‘ Define ADCIN parameters
DEFINE ADC_BITS 10 ‘ Set number of bits in result
DEFINE ADC_CLOCK 3 ‘ Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 20 ‘ Set sampling time in uS
PeakValue var word
SensorValue var word
LastSensorValue var word
Threshold var word
Noise var word
Threshold = 50 ‘ set your own value based on your sensors
PeakValue = 0 ‘ initialize peakValue
noise = 5 ‘ set a noise value based on your particular sensor
‘ Set PORTA to all input
TRISA = %11111111
‘ Set up ADCON1
ADCON1 = %10000010
inv2400 con 16780
thisByte var byte
adcVar var word
blink var byte
output portd.1
output portd.2
OUTPUt portd.3
input portb.0
i var byte
pause 500
main:
‘ read sensor on pin RA0:
ADCin 3, sensorValue
‘ check to see that it’s above the threshold:
If sensorValue >= threshold + noise then
‘ if it’s greater than the last reading,
‘ then make it our current peak:
If sensorValue >= lastSensorValue + Noise then
PeakValue = sensorValue
endif
‘ if the sensorValue is not above the threshold,
‘ then the last peak value we got would be the actual peak:
Else
If peakValue >= threshold then
‘ this is the final peak value; take action
thisByte = 1
for i = 0 to 5 step 1
serout2 portd.3, inv2400, [65, dec thisbyte]
next i
’serout2 portd.3, inv2400, [83, DEC thisByte, 10]
high portd.1
pause 200
low portd.1
pause 200
endif
‘ reset peakValue, since we’ve finished with this peak:
peakValue = 0
Endif
‘ store the current sensor value for the next loop:
lastSensorValue = sensorValue
goto main
‘****************************************************************
‘* Name : PP-RECEIVER_BOX
‘* Author : Steven Jackson / Fazreen Kuhiri
‘* Notice : Copyright (c) 2005
‘* : All Rights Reserved
‘* Date : 12/1/2005
‘* Version : 1.0
‘* Notes : sending serial out (transmitter) from paddle
‘*
‘****************************************************************
inbyte var byte ‘ incoming string
inbyte2 VAR BYTE
output portb.1 ‘ status LED
output portc.6 ‘ serial out to PC
input portc.7 ‘ serial in from receiver
n_2400 con 16780 ‘ baud mode for serin2 (2400-8-N-1 inverted)
n_9600 con 16468 ‘ baud mode for serin2 (9600-8-N-1 inverted)
i var byte ‘ loop counter
RFSerialIn var portc.7
PCSerialOut VAR portc.6
StatusLED var portb.1
PingPong VAR WORD
PingPong = 420
‘ flash status LED to start:
high StatusLED
pause 500
low StatusLED
main:
‘ this serial call does nothing until it gets bytes:
serin2 RFserialIn, n_2400, [wait(65), inbyte]
serout2 pcserialout, n_9600, [inbyte]
goto main
