November 22, 2024, 04:45:11 AM

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.


Newbie at Coding "Need Help"

Started by Lotus, August 29, 2007, 06:59:41 PM

Previous topic - Next topic

Lotus

August 29, 2007, 06:59:41 PM Last Edit: August 29, 2007, 07:06:21 PM by Lotus
I was wondering if I am doing this correctly this is my first time, but this is what I wanted it to do.

When the sensor is trigger I want to fogger to fill my coffin up with fog. so I tested how long it take which is 10 seconds. After 10 seconds I want the fogger to stop. This is when the audio begins and coffin lid pops up and the red leds turn on the the lid goes down and the yellow leds turn on. this repeats for 9 times. Then goes into an idel time for 3 minutes so that people don't set the prop off everytime it stops.
' =========================================================================
'
'   File...... Coffin.BS1
'   Purpose...
'   Author.... Lotus
'   E-mail.... Joey7252@yahoo.com
'   Started... Aug. 29, 2007
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'  This is for controlling my thrashing coffin prop to controll the sound, lighting, and soleniods.

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


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

SYMBOL  Trigger          = PIN6                 '
SYMBOL  Fogger          = PIN4                 '
SYMBOL  Audio            = PIN3                 '
SYMBOL  LEDSR           = PIN2                 '
SYMBOL  LEDSY           = PIN1                 '
SYMBOL  Coffin            = PIN0                 '


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff            = 0

SYMBOL  IsUp             = 1
SYMBOL  IsDown         = 0

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

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

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

Main:
  IF Trigger = IsOff THEN Main                  ' wait for trigger

  Fogger = IsOn                                 ' fogger is on for 10 seconds
  PAUSE 10000                                  ' Pause 10 Seconds
  Fogger = ISOff                                ' fogger is off
  Audio  = IsOn                                 ' audio are on
  LEDSR  = IsOn                                ' LEDs Red are on
  Coffin = IsUp                                  ' Coffin Lid is up
  PAUSE 2000                                   ' Pause 2 seconds
  LEDSR  = IsOff                                ' LEDs Red are off
  LEDSY  = IsON                                ' LEDs Yellow are on
  Coffin = IsDown                               ' Coffin Lid down
  PAUSE 2000                                    ' Pause 2 seconds
  LEDSR  = IsOn                                 ' LEDs Red are on
  LEDSY  = IsOff                                ' LEDs Yellow are off
  Coffin = IsUp                                   ' Coffin Lid is up
  PAUSE 2000                                    ' Pause 2 seconds
  LEDSR  = IsOff                                ' LEDs Red are on
  LEDSY  = IsON                                 ' LEDs Yellow are off
  Coffin = IsDown                               ' Coffin Lid is down
  PAUSE 2000                                    ' Pause 2 seconds
  LEDSR  = IsOn                                 ' LEDs Red are on
  LEDSY  = IsOff                                ' LEDs Yellow are off
  Coffin = IsUp                                 ' Coffin Lid is up
  PAUSE 2000                                    ' Pause 2 seconds
  LEDSR  = IsOff                                ' LEDs Red are off
  LEDSY  = IsON                                 ' LEDs Yellow are on
  Coffin = IsDown                               ' Coffin Lid is down
  PAUSE 2000                                    ' Pause 2 seconds
  LEDSR  = IsOn                                 ' LEDs Red are on
  LEDSY  = IsOff                                ' LEDs Yellow are off
  Coffin = IsUp                                 ' Coffin Lid is up
  PAUSE 2000                                    ' Pause 2 seconds
  LEDSR  = IsOff                                ' LEDs Red are Off
  LEDSY  = IsON                                 ' LEDs Yellow are on
  Coffin = IsDown                               ' Coffin Lid is Down
  PAUSE 2000                                    ' Pause 2 seconds
  Audio  = IsOff                                ' Audio is Off
  LEDSR  = IsOff                                ' LEDs Red is Off
  LEDSY  = IsOff                                ' LEDs Yellow is Off

Long_Delay:
  PAUSE 60000                                   ' one minute
  PAUSE 60000                                   ' one minute

  GOTO Main


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


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


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

JonnyMac

Great first effort!

A couple notes:
-- make your SYMBOLs even more verbose so that you don't have to use comments
-- when you have redundant sections of code, you can repeat it in a loop with FOR-NEXT, like this:

FOR idx = 1 TO 3
  RedLeds = IsOn
  YesllowLeds = IsOff
  Coffin = IsUp
  PAUSE 2000

  RedLeds = IsOff
  YesllowLeds = IsOn
  Coffin = IsDown
  PAUSE 2000
NEXT
Jon McPhalen
EFX-TEK Hollywood Office

Lotus

Quote from: JonnyMac on August 30, 2007, 12:16:44 AM
Great first effort!

A couple notes:
-- make your SYMBOLs even more verbose so that you don't have to use comments
-- when you have redundant sections of code, you can repeat it in a loop with FOR-NEXT, like this:

FOR idx = 1 TO 3
  RedLeds = IsOn
  YesllowLeds = IsOff
  Coffin = IsUp
  PAUSE 2000

  RedLeds = IsOff
  YesllowLeds = IsOn
  Coffin = IsDown
  PAUSE 2000
NEXT


I am a bit confused but I think I understand so the (For idx = 1 to 3) does that mean to repeat the 2 steps three times?

JonnyMac

Yes.  Have a look at FOR-NEXT in the help file of the Parallax editor for details.  It's also explained in our basic programming overview document:

-- http://www.efx-tek.com/downloads/prop-1_programming_basics.pdf
Jon McPhalen
EFX-TEK Hollywood Office

Lotus


Lotus

When I type the code in what should my symbol be for it, and do I need to add any variables

JonnyMac

In the variables section add this line:

SYMBOL  idx             = B2                    ' loop controller

Your program should look something like this when done:

' =========================================================================
'
'   File...... Coffin.BS1
'   Purpose...
'   Author.... Lotus (updated by Jon Williams)
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Fogger          = PIN4
SYMBOL  Audio           = PIN3
SYMBOL  RedLeds         = PIN2
SYMBOL  YellowLeds      = PIN1
SYMBOL  Coffin          = PIN0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0


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

SYMBOL  idx             = B2                    ' loop controller


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

Reset:
  DIRS = %00011111                              ' set output pins


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

Main:
  IF Trigger = IsOff THEN Main                  ' wait for trigger

  Fogger = IsOn
  PAUSE 10000
  Fogger = ISOff
  Audio = IsOn
  RedLeds = IsOn
  Coffin = IsUp
  PAUSE 2000

  FOR idx = 1 TO 3
    RedLeds = IsOff
    YellowLeds = IsOn
    Coffin = IsDown
    PAUSE 2000
    RedLeds = IsOn
    YellowLeds = IsOff
    Coffin = IsUp
    PAUSE 2000
  NEXT

  RedLeds = IsOff
  YellowLeds = IsOn
  Coffin = IsDown
  PAUSE 2000

  Audio = IsOff
  YellowLeds = IsOff

Long_Delay:
  FOR idx = 1 TO 2
    PAUSE 60000                                 ' one minute
  NEXT
  GOTO Main


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


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


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

Jon McPhalen
EFX-TEK Hollywood Office

Lotus


Lotus

Also my soleniod needs 24VDC but my hack I did on my fog machine needs 12 VDC is there a way to just send 12 VDC to the fogger and 24 to the soleniod?

menehune

I would use a 12v relay in the 24vdc power line to the solenoid.  The prop will then turn the 24vdc on and off.

There are other approaches (voltage dividers, power regulators, etc.) but they will require more engineering and parts.

JonnyMac

Really?  Your fog machine needs 12 volts?  Most fog machines have a remote that is has a normally-open button for activation -- you just drop a set of relay contacts across this button and you can operate it by hand or by remote control.  Let me suggest that you look into that and then stick with one voltage (use 24 if that's what your solenoid requires).

In the future, please start a new thread when you have a new question; changing the topic of a thread mid-stream makes searching by thread title really tough.
Jon McPhalen
EFX-TEK Hollywood Office