November 23, 2024, 01:56:02 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


PWM Driving two outputs at the same time

Started by bradbaum, May 18, 2008, 10:15:55 AM

Previous topic - Next topic

bradbaum

I have a prop with two color LED eyes, I have one eye's green LED hooked to pin 0, the red LED of the same eye hooked to pin 1, Pin 2 is the second eyes red LED and pin 3 is the second eye's greed LED.

This is a prop-1, and I am not triggering it, it just runs continuously, fading the eyes from one color to the next.

I copied a program using the PWM command from this forum and modified it to get it to work, but only one eye ever lights up (it lights up in both red and green).

What am I doing wrong?

FOR level = 0 TO 255
    PWM LeftEye1, level, 4
    PWM RightEye1, level, 4
  NEXT
  HIGH LeftEye1
  HIGH RightEye1
  PAUSE 1000
  FOR level = 255 TO 0 STEP -1
    PWM LeftEye1, level, 4
    PWM RightEye1, level, 4
  NEXT
  LOW LeftEye1
  LOW rightEye1
  PAUSE 1000
  FOR level = 0 TO 255
    PWM LeftEye2, level, 4
    PWM RightEye2, level, 4
  NEXT
  HIGH LeftEye2
  HIGH RightEye2
  PAUSE 1000
  FOR level = 255 TO 0 STEP -1
    PWM LeftEye2, level, 4
    PWM RightEye2, level, 4
  NEXT
  LOW LeftEye2
  LOW RightEye2
  RETURN

I left off all the SYMBOL commands and that stuff - That stuff all seems to be working due to the first eye lighting up.

Thanks in advance,

Brad
Thanks,

Brad Baum

JonnyMac

Since your left and right eye are always doing the same thing you should probably just connect both LEDs to the same pin.  This also helps get past the speed thing with the Prop-1; it's pretty slow and even though I fixed your code to work, there was an annoying pulsing of the LEDs due to instruction delays.

Here's an update using just two pins:

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


SYMBOL  Eyes1           = 0
SYMBOL  Eyes2           = 1

SYMBOL  level           = B2


Main:
  FOR level = 0 TO 255
    PWM Eyes1, level, 4
  NEXT
  HIGH Eyes1
  PAUSE 1000

  FOR level = 255 TO 0 STEP -1
    PWM Eyes1, level, 4
  NEXT
  LOW Eyes1
  PAUSE 1000

  FOR level = 0 TO 255
    PWM Eyes2, level, 4
  NEXT
  HIGH Eyes2
  PAUSE 1000

  FOR level = 255 TO 0 STEP -1
    PWM Eyes2, level, 4
  NEXT
  LOW Eyes2
  PAUSE 1000

  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

bradbaum

Sorry, I got busy and haven't replied to thank you, but your code of course worked fine.

now, as my haunt comes together, I want to use the remaining pins on the PROP-1 to run a couple of other props.

I have a flopping mummy and a striking snake I want to trigger seperatly off seperate beam brake sensors.

I want to bring the sensors in on pins 6 and 7 and drive pins 2 and 3, and I still want the shivering mummy code to run with minimal interruptions.
I hope this can be done, as of course I am runing out of money for the haunt.

The idea is:
Input on pin 7 (or 6) - Delay - output on pin 3 (or 2) - hold time - reset and wait for input on pin 7 (or 6)
I can adjust the delay and hold time by changing values in the code and reloading the prop-1.



Here is the final code for the shivering mummy:

' =========================================================================
'
'   File...... Shivering_Mummy.BS1
'   Purpose...
'   Author.... Brad Baum
'   E-mail.... baumbradleyl@yahoo.com
'   Started... 5/9/08
'   Updated... 5/18/08 w/ help of Jon from EFX-TEK
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' Turns shiver motor on and off repeatedly and changes eye color and brightness

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

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

SYMBOL  Motor1         = PIN5
SYMBOL  Motor2         = PIN4

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

SYMBOL  Eyes1           = 0
SYMBOL  Eyes2           = 1

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

SYMBOL  level           = B2                    ' output level (for PWM)
SYMBOL  Time            = B4

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

Reset:
  PINS = %00000000                              ' clear outputs
  DIRS = %11111111

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

Main:
  FOR Time = 0 TO 25
    Motor1 = 1
    Motor2 = 1
    GOSUB Eyes
    Motor1 = 0
    Motor2 = 0
    PAUSE 500
  NEXT
  PAUSE 5000
  GOTO Main


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

Eyes:
  FOR level = 0 TO 255
    PWM Eyes1, level, 4
  NEXT
  HIGH Eyes1
  PAUSE 500

  FOR level = 255 TO 0 STEP -1
    PWM Eyes1, level, 4
  NEXT
  LOW Eyes1
  PAUSE 500

  FOR level = 0 TO 255
    PWM Eyes2, level, 4
  NEXT
  HIGH Eyes2
  PAUSE 500

  FOR level = 255 TO 0 STEP -1
    PWM Eyes2, level, 4
  NEXT
  LOW Eyes2
  PAUSE 500
RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Thanks,

Brad Baum

JonnyMac

October 07, 2008, 03:35:26 PM #3 Last Edit: October 07, 2008, 04:31:00 PM by JonnyMac
Are you saying that the Prop-1 is so expensive that you want to run two completely independent props from one controller?  ;D

It can be done, but not easily, and you're probably going to have to allow one side to lock-out the other.  The involvement of your PWM code means that building a state-machine is not really doable which would let both props run simultaneously.  If you don't mind the lock-out of one side while the other is running I can write that code for you.
Jon McPhalen
EFX-TEK Hollywood Office

bradbaum

Yeah - I am cheap and lazy. LOL.

I started to work on writing it and was getting hung up on the same thing you mentioned.
Hopefully my stash of Prop-1's turns up durring the halloween unpack and I can do it on a seperate unit.

Thanks,

Brad
Thanks,

Brad Baum