November 21, 2024, 08:02:28 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Fading running lights Etc for prop 2

Started by imagineerdan, November 08, 2007, 04:16:35 PM

Previous topic - Next topic

imagineerdan

November 08, 2007, 04:16:35 PM Last Edit: November 08, 2007, 04:20:33 PM by imagineerdan
I am using the attchaed program which was modified from a prop one code. I am tryig to make pins 0-6 fade in and out randomly and then when pin 15 is closed, then pins 7-14 will do a fading running light routine, how would I alter this code. I am finally diving into the wonderful world of the prop 2!



' {$STAMP BS2}



' -----[ I/O Definitions ]-------------------------------------------------



' -----[ Constants ]-------------------------------------------------------


' -----[ Variables ]-------------------------------------------------------

theLamp          VAR  B2                           ' lamp to brighten or dim
last             VAR  B3                           ' last lamp adjusted
level            VAR  Byte                          ' output level (for PWM)
mask             VAR  B5                           ' bit mask test
temp             VAR  B6
speed            VAR  B7                           ' adjustment speed
lottery          VAR  W5                           ' random value




' -----[ Initialization ]--------------------------------------------------

Reset:
INS =  15

OUTS = 0
OUTS = 1
OUTS = 2
OUTS = 3
OUTS = 4
OUTS = 5
OUTS = 6
OUTS = 7
OUTS = 8
OUTS = 9
OUTS = 10
OUTS = 11
OUTS = 12
OUTS = 13
OUTS = 14

lottery = 1031                                ' seed random value


' -----[ Program Code ]----------------------------------------------------

Main:
IF IN15=1 THEN Main2:

  RANDOM lottery                                ' tumble random value
  theLamp = lottery // 8                        ' select a lamp, 0 - 8
  IF theLamp = last THEN Main                   ' no repeats
    last = theLamp

  READ theLamp, mask                            ' get bit for that lamp
  temp = OUTL & mask                            ' test selected lamp
  IF temp = 0 THEN Brighten

DIMMER:
  RANDOM lottery
  speed = lottery // 11 + 10                    ' set speed, 10 to 20
  FOR level = 255 TO 0 STEP -speed              ' decrease output level
    PWM theLamp, level, 1
  NEXT
  LOW theLamp                                   ' lamp fully off
  GOTO Main

Brighten:
  RANDOM lottery
  speed = lottery // 11 + 10                    ' set speed, 10 to 20
  FOR level = 0 TO 255 STEP speed               ' increase output level
    PWM theLamp, level, 1
  NEXT
  HIGH theLamp                                  ' lamp fully on
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------
Main2:

pinNum          VAR B2



' -----[ Initialization ]--------------------------------------------------



' -----[ Program Code ]----------------------------------------------------


  FOR pinNum = 7 TO 14                           ' loop through outputs
    FOR level = 255 TO 0 STEP -8                ' bright to dark
      PWM pinNum, level, 2
    NEXT
  NEXT
  GOTO Main



JonnyMac

November 08, 2007, 05:16:40 PM #1 Last Edit: November 13, 2007, 04:45:39 PM by JonnyMac
As they say here in Hollywood... for your consideration.  This version follows my "PBASIC Programming with Style" guidelines and takes advantage of PBASIC 2.0/2.5 features that are not unavailable in PBASIC 1.0.

Note that I moved your random lamps to the upper group (8..14) as you're only using seven (you need the other for the trigger); the chaser lamps have been moved to the lower group.

UPDATED: 13 NOV 2007

' {$STAMP BS2}
' {$PBASIC 2.5}


' -----[ I/O Definitions ]-------------------------------------------------

Trigger         PIN     15                      ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0


' -----[ Variables ]-------------------------------------------------------

theLamp         VAR     Byte                    ' lamp to brighten or dim
last            VAR     Byte                    ' last lamp adjusted
speed           VAR     Byte                    ' adjustment speed
level           VAR     Byte                    ' output level (for PWM)
lottery         VAR     Word                    ' random value


' -----[ Initialization ]--------------------------------------------------

Reset:
  lottery = 1031                                ' seed random value


' -----[ Program Code ]----------------------------------------------------

Main:
  RANDOM lottery
  IF (Trigger = Pressed) THEN Chaser

Select_Lamp:
  RANDOM lottery                                ' tumble random value
  theLamp = lottery // 7 + 8                    ' select a lamp, 8 - 14
  IF (theLamp = last) THEN Select_Lamp          ' no repeats
    last = theLamp

Check_Lamp:
  IF (OUTS.LOWBIT(theLamp) = 0) THEN Brighten   ' test lamp state

Dimmer:
  RANDOM lottery
  speed = lottery // 6 + 5                      ' set speed, 5 to 10
  FOR level = 255 TO 0 STEP -speed              ' decrease output level
    PWM theLamp, level, 5
  NEXT
  LOW theLamp                                   ' lamp fully off
  GOTO Main

Brighten:
  RANDOM lottery
  speed = lottery // 6 + 5                      ' set speed, 5 to 10
  FOR level = 0 TO 255 STEP speed               ' increase output level
    PWM theLamp, level, 5
  NEXT
  HIGH theLamp                                  ' lamp fully on
  GOTO Main

Chaser:
  OUTH = %00000000                              ' randomized LEDs off
  FOR theLamp = 0 TO 7                          ' loop through low outputs
    FOR level = 255 TO 0 STEP 8                 ' bright to dark
      PWM theLamp, level, 10
    NEXT
  NEXT
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

1) I wanted to lighting to fade up and down randomly like in this bs1 code (pin0-7)
2) Then when pin15 is triggered pin8 through 14 follow a fading running light routine and the random pulsingm is off


' {$STAMP BS1}



' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Lamp7           = PIN7
SYMBOL  Lamp6           = PIN6
SYMBOL  Lamp5           = PIN5
SYMBOL  Lamp4           = PIN4
SYMBOL  Lamp3           = PIN3
SYMBOL  Lamp2           = PIN2
SYMBOL  Lamp1           = PIN1
SYMBOL  Lamp0           = PIN0


' -----[ Constants ]-------------------------------------------------------


' -----[ Variables ]-------------------------------------------------------

SYMBOL  theLamp         = B2                    ' lamp to brighten or dim
SYMBOL  last            = B3                    ' last lamp adjusted
SYMBOL  level           = B4                    ' output level (for PWM)
SYMBOL  mask            = B5                    ' bit mask test
SYMBOL  temp            = B6
SYMBOL  speed           = B7                    ' adjustment speed
SYMBOL  lottery         = W5                    ' random value


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRS = %11111111                              ' P0 - P7 are outs
  lottery = 1031                                ' seed random value


' -----[ Program Code ]----------------------------------------------------

Main:
  RANDOM lottery                                ' tumble random value
  theLamp = lottery // 8                        ' select a lamp, 0 - 8
  IF theLamp = last THEN Main                   ' no repeats
    last = theLamp

  READ theLamp, mask                            ' get bit for that lamp
  temp = PINS & mask                            ' test selected lamp
  IF temp = 0 THEN Brighten

Dim:
  RANDOM lottery
  speed = lottery // 11 + 10                    ' set speed, 10 to 20
  FOR level = 255 TO 0 STEP -speed              ' decrease output level
    PWM theLamp, level, 1
  NEXT
  LOW theLamp                                   ' lamp fully off
  GOTO Main

Brighten:
  RANDOM lottery
  speed = lottery // 11 + 10                    ' set speed, 10 to 20
  FOR level = 0 TO 255 STEP speed               ' increase output level
    PWM theLamp, level, 1
  NEXT
  HIGH theLamp                                  ' lamp fully on
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ EEPROM Data ]-----------------------------------------------------

Bit_Set:
  EEPROM (%00000001, %00000010, %00000100, %00001000)
  EEPROM (%00010000, %00100000, %01000000, %10000000)



Second code--------------

   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------


' -----[ Constants ]-------------------------------------------------------


' -----[ Variables ]-------------------------------------------------------

SYMBOL  pinNum          = B2
SYMBOL  level           = B3


' -----[ Initialization ]--------------------------------------------------

Reset:


' -----[ Program Code ]----------------------------------------------------

Main:
  FOR pinNum = 0 TO 7                           ' loop through outputs
    FOR level = 255 TO 0 STEP -8                ' bright to dark
      PWM pinNum, level, 2
    NEXT
  NEXT
  GOTO Main




JonnyMac

You can't fade two things at once -- PWM works on just one pin at a time.  You could have a chaser running when P15 is pressed, but to make it clean you would have to fix the fade-up and fade-down time of the random LEDs.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

I dont need two things to fade at once. I want to random program to run continunuously (pin0 - pin6) until pin 15 is triggered, and the fade up and down times can be the same, but when pin 15 is triggered the random fading shuts off and (pin7- pin14) do the pwm running light routine. is this possible?

JonnyMac

Yes, that's what the program I attached as my first response does.  I re-arranged the pins to make things a little cleaner, but it does exactly as you last post describes.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Hi Jon, thanks you are right but the fading flicker is going soo much faster than my bs1 verson, as is the fading running lights. Also it seems that the pin8 to pin14 set dont shut off when pin15 is triggered, which initiates pin0-pin7 to do the fading running lights routine. Im sorry if this is cryptic, but I am just trying to update the 2 old bs1 codes attached to BS2 and combine them into one, I really liked thier esthetic. Thanks for the help Jon.

JonnyMac

Okay, Dan, I think I got it -- or very close.  The PWM statements needed to be updated for the increased speed of the BS2 -- I ran a Prop-1 and Prop-2 side-by-side when making the adjustments.  You may need to do a little fine-tuning, but it shouldn't take much.
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

November 13, 2007, 04:55:04 PM #8 Last Edit: November 13, 2007, 05:09:19 PM by imagineerdan
Ohh I see the modified example above, That really works well Jon, Thanks much


imagineerdan

I have a question on a modification on a code similar to the one above, I am posting it below. I am trying to get the leds to do the same action but never turn off completely, maybe just go to 100 rather than 0 (from 255 to 100)  how would I alter this code to do that, as well as have pin0-pin13 do this.

' -----[ I/O Definitions ]-------------------------------------------------

Trigger         PIN     15
Trigger2        PIN     14


' -----[ Constants ]-------------------------------------------------------
INS= 15
INS= 14

IsOn            CON     1
IsOff           CON     0

Pressed         CON     1
NotPressed      CON     0


' -----[ Variables ]-------------------------------------------------------

theLamp         VAR     Byte                    ' lamp to brighten or dim
last            VAR     Byte                    ' last lamp adjusted
speed           VAR     Byte                    ' adjustment speed
level           VAR     Byte                    ' output level (for PWM)
lottery         VAR     Word                    ' random value


' -----[ Initialization ]--------------------------------------------------

Reset:
  lottery = 1031                                ' seed random value


' -----[ Program Code ]----------------------------------------------------


Main:






Select_Lamp:
  RANDOM lottery                                ' tumble random value
  theLamp = lottery // 6 + 8                    ' select a lamp, 0 - 13
  IF (theLamp = last) THEN Select_Lamp          ' no repeats
    last = theLamp

Check_Lamp:
  IF (OUTS.LOWBIT(theLamp) = 0) THEN Brighten   ' test lamp state

Dimmer:
  RANDOM lottery
  speed = lottery // 6 + 5                      ' set speed, 5 to 10
  FOR level = 255 TO 0 STEP 10                  ' decrease output level
    PWM theLamp, level, 6
  NEXT
  LOW theLamp                                   ' lamp fully off
  GOTO Main

Brighten:
  RANDOM lottery
  speed = lottery // 6 + 5                      ' set speed, 5 to 10
  FOR level = 0 TO 255 STEP 10                  ' increase output level
    PWM theLamp, level, 6
  NEXT
  HIGH theLamp                                  ' lamp fully on

GOTO Main

JonnyMac

The rub with the BS2 is that PWM on works when it's running -- as soon as you move to the next program statement the LED will either be full off or full on.  Where there's a zero in a FOR-NEXT loop for level, you can change that to 100, but this will only shorten the loop and I don't think the program will give you the visual effect you're after. 

Dimmer:
  RANDOM lottery
  speed = lottery // 6 + 5                      ' set speed, 5 to 10
  FOR level = 255 TO 100 STEP 10                ' decrease output level
    PWM theLamp, level, 6
  NEXT
  LOW theLamp                                   ' lamp fully off
  GOTO Main


The Prop-SX can do "background" PWM (it takes a bit of code trickery, but we know to do that) so you can have one or more LEDs sit at any brightness level while the program is doing other things.

Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

how do I get pins 0 through 13 to work?

JonnyMac

Sorry, you have to put the pin selection back in:

Main:
  RANDOM lottery
  IF (Trigger = Pressed) THEN Chaser

Select_Lamp:
  RANDOM lottery                                ' tumble random value
  theLamp = lottery // 14                       ' select a lamp, 0 - 13
  IF (theLamp = last) THEN Select_Lamp          ' no repeats
    last = theLamp

Check_Lamp:
  IF (OUTS.LOWBIT(theLamp) = 0) THEN Brighten   ' test lamp state
Jon McPhalen
EFX-TEK Hollywood Office

imagineerdan

Ohh I just put the number to determine the outs, thats great, much easier than the bs1 in that sense.

One miore question, As you know I have been playing with the program below, and I want to try to make it not as uniform. To explain further, I am wanting the running lights progression of the program but I want the on and off times from pin 13 to pin 0 to be random like the above program. The leds would still do the running lights thing in order from one pin to the next, but the pwm on and off times would be random. What do you think? Thanks as usual for your help Jon!

JonnyMac

Well, somewhere along the line the variable being randomized (speed) stopped being used.  Try this:

Dimmer:
  RANDOM lottery
  speed = lottery // 6 + 5                      ' set speed, 5 to 10
  FOR level = 255 TO 0 STEP speed               ' decrease output level
    PWM theLamp, level, 6
  NEXT
  LOW theLamp                                   ' lamp fully off
  GOTO Main

Brighten:
  RANDOM lottery
  speed = lottery // 6 + 5                      ' set speed, 5 to 10
  FOR level = 0 TO 255 STEP speed               ' increase output level
    PWM theLamp, level, 6
  NEXT
  HIGH theLamp                                  ' lamp fully on


Jon McPhalen
EFX-TEK Hollywood Office