Ok, I tried to follow the thread of converting variables from P1-P2 and got lost. I have to give credit to Jumblo and Upier for this Prop1 program. I guess that is why I don't know what I am doing. I think the smaller ones I could convert (but then again, I wouldn't have too would I?) The program below, Is for a coffin thrasher. the right arm, left arm, left leg, right leg all thrash up and down, and there is a pump that spurts blood. I am switching to a Prop2 simply because this thing really doesn't thrash as much as we would like. ALSO, I have added a crow that pecks at the guts of the body.
That said, could someone look at this, help me finish the conversion, and add the crow? I also ask is the method used the most efficient way of programming this? I seriously thank you!! I am in TX but can test once I return home Monday. ' =========================================================================
'
' File....... THRASHER.BS2
' Purpose....
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
BloodPump = PIN0 ' Pump blood
LeftArm = PIN1 ' left arm
RightArm = PIN2 ' right arm
LeftLeg = PIN3 ' left leg
RightLeg = PIN4 ' right leg
Audio = PIN5 ' scream
Crow = PIN6
Trigger = PIN7 ' active-high input
' -----[ Constants ]-------------------------------------------------------
IsOn con 1 ' active high
IsOff con 0
' -----[ Variables ]-------------------------------------------------------
SYMBOL secs = B2
' -----[ EEPROM Data ]-----------------------------------------------------
' -----[ Initialization ]--------------------------------------------------
Reset:
DIRS = %00011111
' -----[ Program Code ]----------------------------------------------------
DEBUG "Warming up", CR
secs = 2
GOSUB Timer ' wait for PIR to warm up
Main:
DEBUG "Waiting", CR
IF Trigger = IsOff THEN Main ' wait for trigger
Sequence:
'DEBUG "Trigger Audio", CR
'Audio = IsOn 'Start the scream
'PAUSE 200
'Audio = IsOff 'Start the scream
GOSUB ThrashSmall ' Thrash just a little
secs = 3
GOSUB Timer ' wait before the next run
GOSUB ThrashBig ' Go nuts
GOSUB ThrashBig ' Go nuts
GOSUB ThrashBig ' Go nuts
secs = 3
GOSUB Timer ' wait before the next run
GOSUB ThrashSmall ' Thrash just a little
secs = 10
GOSUB Timer ' Wait to reactivate
Release:
IF Trigger = IsOn THEN Release ' force trigger release
GOTO Main
' -----[ Subroutines ]-----------------------------------------------------
' Put number or seconds in "secs" before calling
' -- secs is modified by this subroutine
' -- maximum delay is 255 second (4 mins, 15 seconds)
Timer:
' DEBUG "Sleep ",secs, CR
IF secs = 0 THEN Timer_Done
PAUSE 1000
secs = secs - 1
GOTO Timer
Timer_Done:
RETURN
'-------------------------------------------------------------
' Just wiggle a little to get thier attention
'-------------------------------------------------------------
ThrashSmall:
LeftArm = IsOn ' pop the left arm
RightArm = IsOn ' pop the right arm
PAUSE 300
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOn ' Bleed a little
PAUSE 500
LeftArm = IsOn ' pop the left arm
PAUSE 300
LeftArm = IsOff ' bring the left arm back
RightArm = IsOn ' pop the right arm
LeftArm = IsOn ' pop the left arm
PAUSE 300
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOff ' stop blood
PAUSE 100
RightLeg = IsOn ' pop the right leg
LeftLeg = IsOn ' pop the left leg
PAUSE 300
LeftArm = IsOn ' pop the left arm
RightLeg = IsOff ' bring the right leg back
BloodPump = IsOn ' Bleed a little
PAUSE 500
LeftArm = IsOff ' bring the left arm back
Leftleg = IsOff ' bring the left arm back
PAUSE 200
BloodPump = IsOff ' stop blood
PAUSE 100
RightLeg = IsOn ' pop the right leg
LeftLeg = IsOn ' pop the left leg
PAUSE 300
BloodPump = IsOn ' Bleed a little
LeftArm = IsOn ' pop the left arm
RightLeg = IsOff ' bring the right leg back
PAUSE 300
BloodPump = IsOff ' stop blood
RETURN
'-------------------------------------------------------------
' Just lose it!
'-------------------------------------------------------------
ThrashBig:
LeftArm = IsOn ' pop the left arm
RightLeg = IsOn ' pop the right leg
BloodPump = IsOn ' Bleed a little
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightLeg = IsOff ' bring the right leg back
PAUSE 300
LeftArm = IsOn ' pop the left arm
RightArm = IsOn ' pop the right arm
LeftLeg = IsOn ' pop the left leg
RightLeg = IsOn ' pop the right leg
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOff ' stop blood
PAUSE 300
BloodPump = IsOn ' Bleed a little
RightLeg = IsOff
LeftLeg = IsOff ' bring the right leg back
RightArm = IsOn ' pop the right arm
PAUSE 100
LeftArm = IsOn ' pop the left arm
RightLeg = IsOn ' pop the right leg
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightLeg = IsOff ' bring the right leg back
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOff ' stop blood
LeftArm = IsOn ' pop the left arm
RightLeg = IsOn ' pop the right leg
BloodPump = IsOn ' Bleed a little
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightLeg = IsOff ' bring the right leg back
RETURN
I've converted your program and "upgraded" to PBASIC 2.5 features where it is helpful. Note that I moved your trigger to P14 as this has a SETUP jumper that can pull the pin low (DN position) when the trigger is open.
' =========================================================================
'
' File....... THRASHER.BS2
' Purpose....
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
BloodPump PIN 0 ' Pump blood
LeftArm PIN 1 ' left arm
RightArm PIN 2 ' right arm
LeftLeg PIN 3 ' left leg
RightLeg PIN 4 ' right leg
Audio PIN 5 ' scream
Crow PIN 6
Trigger PIN 14 ' SETUP = DN
' -----[ Constants ]-------------------------------------------------------
IsOn CON 1 ' active high
IsOff CON 0
' -----[ Variables ]-------------------------------------------------------
secs VAR Byte
idx VAR Byte
' -----[ Initialization ]--------------------------------------------------
Reset:
OUTL = %00000000 ' clear P0..P7
DIRL = %01111111 ' configure output pins
' -----[ Program Code ]----------------------------------------------------
DEBUG "Warming up", CR
secs = 2
GOSUB Timer ' wait for PIR to warm up
Main:
DO WHILE (Trigger = IsOff) ' wait for trigger
DEBUG "Waiting", CR
LOOP
Sequence:
'DEBUG "Trigger Audio", CR
'Audio = IsOn 'Start the scream
'PAUSE 200
'Audio = IsOff 'Start the scream
GOSUB ThrashSmall ' Thrash just a little
secs = 3
GOSUB Timer ' wait before the next run
FOR idx = 1 TO 3
GOSUB ThrashBig ' Go nuts
NEXT
secs = 3
GOSUB Timer ' wait before the next run
GOSUB ThrashSmall ' Thrash just a little
secs = 10
GOSUB Timer ' Wait to reactivate
Release:
DO WHILE (Trigger = IsOn) ' force trigger release
LOOP
' -----[ Subroutines ]-----------------------------------------------------
' Put number or seconds in "secs" before calling
' -- secs is modified by this subroutine
' -- maximum delay is 255 second (4 mins, 15 seconds)
Timer:
DO WHILE (secs > 0)
PAUSE 1000
secs = secs - 1
LOOP
RETURN
'-------------------------------------------------------------
' Just wiggle a little to get thier attention
'-------------------------------------------------------------
ThrashSmall:
LeftArm = IsOn ' pop the left arm
RightArm = IsOn ' pop the right arm
PAUSE 300
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOn ' Bleed a little
PAUSE 500
LeftArm = IsOn ' pop the left arm
PAUSE 300
LeftArm = IsOff ' bring the left arm back
RightArm = IsOn ' pop the right arm
LeftArm = IsOn ' pop the left arm
PAUSE 300
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOff ' stop blood
PAUSE 100
RightLeg = IsOn ' pop the right leg
LeftLeg = IsOn ' pop the left leg
PAUSE 300
LeftArm = IsOn ' pop the left arm
RightLeg = IsOff ' bring the right leg back
BloodPump = IsOn ' Bleed a little
PAUSE 500
LeftArm = IsOff ' bring the left arm back
Leftleg = IsOff ' bring the left arm back
PAUSE 200
BloodPump = IsOff ' stop blood
PAUSE 100
RightLeg = IsOn ' pop the right leg
LeftLeg = IsOn ' pop the left leg
PAUSE 300
BloodPump = IsOn ' Bleed a little
LeftArm = IsOn ' pop the left arm
RightLeg = IsOff ' bring the right leg back
PAUSE 300
BloodPump = IsOff ' stop blood
RETURN
'-------------------------------------------------------------
' Just lose it!
'-------------------------------------------------------------
ThrashBig:
LeftArm = IsOn ' pop the left arm
RightLeg = IsOn ' pop the right leg
BloodPump = IsOn ' Bleed a little
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightLeg = IsOff ' bring the right leg back
PAUSE 300
LeftArm = IsOn ' pop the left arm
RightArm = IsOn ' pop the right arm
LeftLeg = IsOn ' pop the left leg
RightLeg = IsOn ' pop the right leg
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOff ' stop blood
PAUSE 300
BloodPump = IsOn ' Bleed a little
RightLeg = IsOff
LeftLeg = IsOff ' bring the right leg back
RightArm = IsOn ' pop the right arm
PAUSE 100
LeftArm = IsOn ' pop the left arm
RightLeg = IsOn ' pop the right leg
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightLeg = IsOff ' bring the right leg back
LeftArm = IsOff ' bring the left arm back
RightArm = IsOff ' bring the right arm back
BloodPump = IsOff ' stop blood
LeftArm = IsOn ' pop the left arm
RightLeg = IsOn ' pop the right leg
BloodPump = IsOn ' Bleed a little
PAUSE 100
LeftArm = IsOff ' bring the left arm back
RightLeg = IsOff ' bring the right leg back
RETURN
' -----[ EEPROM Data ]-----------------------------------------------------
Thanks Jon, I got lost here:
' -----[ Variables ]-------------------------------------------------------
secs VAR Byte
idx VAR Byte
I guess I still don't understand the Byte command or the idx.
Per your statement here: Note that I moved your trigger to P14 as this has a SETUP jumper that can pull the pin low (DN position) when the trigger is open.
Does that mean that I need to change the jumper?
Now with more available. memory, I can create additional sub-routines and make it thrash more, add the crow, whatever. That said, are the sub-routines the best method for working a program like this?
Jon, really, thanks again. I am so behind this year, plus this week was a horrible time for a vacation!
Toby
In both programs you have a variable value called 'secs' -- in the Prop-1 we define it like this:
SYMBOL secs = B2
This means use a byte value (hence the B) at location 2. One of the responsibilities we have with the Prop-1 is manually mapping the variables into the available RAM space. This is not the case with the Prop-2 as the compiler will do that for us based on the variable's size. So the Prop-2 definition becomes:
secs VAR Byte
I added the 'idx' variable to the program as you had a section that repeats three times. When we do the same thing three or more times in a row it is most efficient to do it within a loop. So this:
GOSUB ThrashBig
GOSUB ThrashBig
GOSUB ThrashBig
becomes:
FOR idx = 1 TO 3
GOSUB ThrashBig
NEXT
If you decide that you want to thrash five times you simply change the ending value -- it doesn't take any more code space to do that. You could also randomize the ending value so that your prop behaved a little differently each time.
Technically, if you're using a active-high input, you can use any pin that has the ULN still attached as the input to the ULN circuit pulls the I/O pin low (this is why it interferes with SEROUT and POT). We tend, however, to want hard pull-up/pull-down resistors, and those are on P6/P7 of the Prop-1, and P12-P15 of the Prop-2.
I just wanted to say "THANKS". I downloaded the program to the prop 2 on Sunday, and finished up the prop repair Monday night. Though it still needs some help, the program works GREAT. I added my crow pecking, added some more movements, but then realized I have a bum cylinder...damn water got inside....So, it sits till Sat when the new one arrives via friend....
Thanks again!
You're welcome -- we feel successful when your props are successful.