Project 2 - Marionette code
DEFINE OSC 20
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEuS 50
TRISA = %11111111
ADCON1 = %10000010
txPin var portc.6
blinkyled var portb.7
SWright var portd.0
SWfront var portd.1
SWleft var portc.1
SWmiddle var portc.2
SWback var portc.3
LEFT con 1
RIGHT CON 2
MIDDLE con 3
FRONT CON 4
BACK CON 5
SITTING CON 6
LEFT_LEG_UP con 7
RIGHT_LEG_UP con 8
HANDS_UP con 9
HANDS_DOWN con 10
STAND_STILL con 11
xVar var word
yVar var word
posStatus var byte
movStatus var byte
oldPosStatus var byte
oldMovStatus var byte
oldMovStatus = 99
oldPosStatus = 99
movStatus = 100
posStatus = 100
i var byte
FOR i=0 to 5
high blinkyled
pause 500
low blinkyled
pause 500
NEXT
main:
adcin 0, xVar
adcin 1, yVar
if swleft = 1 then
posStatus = LEFT
endif
if swright = 1 then
posStatus = RIGHT
endif
if swmiddle = 1 then
posStatus = MIDDLE
endif
if swfront = 1 then
posStatus = FRONT
endif
if swback = 1 then
posStatus = BACK
endif
if (swfront = 1 and swmiddle = 1) OR (swback = 1 and swmiddle = 1) then
posStatus = SITTING
endif
select case xVar
case is < 480
movStatus = hands_up
case is > 550
movStatus = hands_down
case else
select case yVar
case is > 600
movStatus = right_leg_up
case is < 530
movStatus = left_leg_up
case else
movStatus = stand_still
end select
end select
if (oldmovstatus != movstatus) or (posstatus != oldposstatus) then
serout2 txpin, 12, [144,oldposstatus,0]
oldmovstatus = movstatus
oldposstatus = posstatus
serout2 txpin, 12, [144,posstatus,movstatus]
posStatus = 100
endif
'serout2 txpin, 16468, ["movement =", dec movStatus, " x: " , dec xVar," y: " , dec yVar, " status:", dec posStatus, 13,10]
pause 250
goto main