Problem with my BS2 Code
haunteddansion
Posts: 68
I am using the code below which when triggered all the pins (1-14)·except pin 15 and pin 0 fade off sequentially. Then what is supposed to happen after than is pin 0 goes high for .5 seconds then shuts off.
What is seeming to happen, which is tripping me up is pins 0-14, not 1-14 start out high, then the sequence goes then pin 0 goes high at the end (which is what I want it to do)
is my OUTS wrong in which pins its declaring to start out high (I want pins 1-14) to start out high, but it seems like maybe 0-14 are? Please inform alter the code or whatever you think I can do to make this work right. Thanks soo much
Trigger········ PIN···· 15····················· ' SETUP = DN
Relay·········· PIN···· 0
'
[noparse][[/noparse] Constants ]
IsOn··········· CON···· 1
IsOff·········· CON···· 0
Pressed········ CON···· 1
NotPressed····· CON···· 0
'
[noparse][[/noparse] Variables ]
theLamp········ VAR···· Byte··················· ' lamp to brighten or dim
speed·········· VAR···· Byte··················· ' adjustment speed
level·········· VAR···· Byte··················· ' output level (for PWM)
lottery········ VAR···· Word··················· ' random value
'
[noparse][[/noparse] Initialization ]
Reset:
· lottery = 1031······························· ' seed random value
'
[noparse][[/noparse] Program Code ]
Main:
· RANDOM lottery
· IF (Trigger = Pressed) THEN Main2:·········· '· De-bounce until trigger (pin 15) is pressed
· GOTO Main:
Main2:
· OUTS = %0111111111111110····················· ' all on
· PAUSE 500
Chaser:
· FOR theLamp = 0 TO 14························ ' loop through outputs
··· speed = lottery // 6 + 5
··· FOR level = 255 TO 0 STEP 8················ ' bright to dark
····· PWM theLamp, level, speed
··· NEXT
··· LOW theLamp
· NEXT
· Relay=IsOn··································· ' SSR trigger for second prop-2 board
· PAUSE 500···································· ' Pause for trigger
· Relay=IsOff
·GOTO Main:
What is seeming to happen, which is tripping me up is pins 0-14, not 1-14 start out high, then the sequence goes then pin 0 goes high at the end (which is what I want it to do)
is my OUTS wrong in which pins its declaring to start out high (I want pins 1-14) to start out high, but it seems like maybe 0-14 are? Please inform alter the code or whatever you think I can do to make this work right. Thanks soo much
Trigger········ PIN···· 15····················· ' SETUP = DN
Relay·········· PIN···· 0
'
[noparse][[/noparse] Constants ]
IsOn··········· CON···· 1
IsOff·········· CON···· 0
Pressed········ CON···· 1
NotPressed····· CON···· 0
'
[noparse][[/noparse] Variables ]
theLamp········ VAR···· Byte··················· ' lamp to brighten or dim
speed·········· VAR···· Byte··················· ' adjustment speed
level·········· VAR···· Byte··················· ' output level (for PWM)
lottery········ VAR···· Word··················· ' random value
'
[noparse][[/noparse] Initialization ]
Reset:
· lottery = 1031······························· ' seed random value
'
[noparse][[/noparse] Program Code ]
Main:
· RANDOM lottery
· IF (Trigger = Pressed) THEN Main2:·········· '· De-bounce until trigger (pin 15) is pressed
· GOTO Main:
Main2:
· OUTS = %0111111111111110····················· ' all on
· PAUSE 500
Chaser:
· FOR theLamp = 0 TO 14························ ' loop through outputs
··· speed = lottery // 6 + 5
··· FOR level = 255 TO 0 STEP 8················ ' bright to dark
····· PWM theLamp, level, speed
··· NEXT
··· LOW theLamp
· NEXT
· Relay=IsOn··································· ' SSR trigger for second prop-2 board
· PAUSE 500···································· ' Pause for trigger
· Relay=IsOff
·GOTO Main:
Comments
· FOR theLamp = 0 TO 14
Shouldn't that be --
Chaser:
· FOR theLamp =·1 TO 14
Where you have --
Chaser:
· FOR theLamp = 0 TO 14··········
··· speed = lottery // 6 + 5
··· FOR level = 255 TO 0 STEP 8··
····· PWM theLamp, level, speed··'when theLamp = 0, it gets PWM'd
··· NEXT
··· LOW theLamp
· NEXT
When theLamp is "0 to 14" then it'll go through 0-14 and when it's·"1 to 14" then it'll go through 1-14 (the latter·is what you want, right?)
Post Edit --
Hang on a minute.· Engage brain.· [noparse]:)[/noparse]
OUTS = %0111111111111110.· So, that's a WORD (16 bits).
So theLamp needs to be theLamp VAR Word
To go through each theLamp sequentially, then, it's theLamp = 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384
FOR theLamp = 2 TO 16384
··· speed = lottery // 6 + 5
··· FOR level = 255 TO 0 STEP 8··
····· PWM theLamp, level, speed
····· theLamp = theLamp * 2
····· NEXT
····· LOW theLamp
Skip all that, too smart by half, because with "PWM" the variable is for the Physical Pin.· So what I wrote·first is where it's at, definitely.
Doesn't using "PWM" make the pin associated an output by default?· [noparse][[/noparse]That'd make a DIRS unnecessary.]
Post Edited (PJ Allen) : 12/9/2007 11:26:36 PM GMT