November 21, 2024, 04:19:36 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Newbee stumped

Started by Shmedley, August 16, 2007, 03:24:02 PM

Previous topic - Next topic

Shmedley

Can you look at my script and let me know if there is someything i am blind to.  I am trying to trigger a PIR, if "on" move a servo to and fro.  if "off" blink leds.  My problem is with the PIR, I can't seem to get consistant results and feel my script covering "waiting for valid signal" may be inncorrect.....any suggestions would be awesome.....

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Servo           = 0
SYMBOL light1 =PIN1

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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  pirTimer        = B3
SYMBOL  pos             = B2

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

Reset:
  DEBUG "reset",CR
  LOW Servo

  PINS = %00000000                              ' clear everything
  DIRS = %00001111

  PAUSE 30000
  pirTimer = 0




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

Main:
PAUSE 10
DEBUG "main",CR
pirTimer = pirTimer + 10 * PIR                ' update PIR timer
IF pirTimer < 250 THEN Main                   ' wait for valid signal



DEBUG "off...",CR

IF PIR = isOff THEN blink
IF PIR = isOn  THEN HEAD
GOTO Main

blink:
DEBUG "blink...",CR
light1 =1
PAUSE 1000
light1 =0
PAUSE 1000
GOTO reset

HEAD:
DEBUG "ON....",CR
  light1 =1

  DEBUG "Servo to...", CR
  FOR pos = 55 TO 155
    PULSOUT Servo, pos                          ' move servo
    PAUSE 18                                    ' update delay
  NEXT

  DEBUG "Servo fro...", CR
  FOR pos = 155 TO 55 STEP -1
    PULSOUT Servo, pos                          ' move servo
    PAUSE 18                                    ' update delay
  NEXT

  GOTO reset


  END


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


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


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


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


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


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


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


Thanks ahead of time

JonnyMac

First... please do us a favor avoid using titles like "Newbee stumped" etc.  Whether you're new or an old hand, it doesn't matter -- use a descriptive thread title so that others with expertise can help out; many forum users ignore threads that have silly titles.  Okay, enough on that.

One thing to keep in mind is that the DEBUG statement in the BS1 (Prop-1 processor) is very ssssllllloooooowwwwwww and will not let you see things running in real-time, especially when you put them into loops like the PIR debouncer.  If you really need to use DEBUG, do something like this:

Main:
  DEBUG "Waiting...", CR

PIR_Wait:
  PAUSE 10
  pirTimer = pirTimer + 10 * PIR                ' update PIR timer
  IF pirTimer < 250 THEN PIR_Wait               ' wait for valid signal

  DEBUG "PIR Signal validated", CR


When the program drops through the loop the PIR is considered active, so I'm unsure why you're polling it again.  Perhaps you should state the intention of your program and allow me (and others to assist from there).  I also see that you're using 55 to 155 for your servo; the typical values would be 100 to 200 when using the Prop-1 -- can you elaborate on that as well.
Jon McPhalen
EFX-TEK Hollywood Office

Shmedley

OK let me start over, My intention with my program is to trip a PIR and have a animated skull move it's head, eyes light up and mini-spotlights changing colors as the bucky's mood changes to mad..... This particular script is just a start on the building block to achomplish the final product.  I figured once I had basic understanding of the script to trip a PIR and make something happen consistantly, I can build off of that.  half the fun of doing this in the first place is to say "you did it your self".

What I need this script to do:
If PIR is on go to sub routine "Head" and make a servo move to and fro.
If PIR is off go to sub routine "blink" and make the led eyes blink.
all without false triggers from the PIR

If I can get this working I think I will be un-stuck for a while :)

FYI the servo movement from 50 - 150 is due to how I have my servo installed into my buckey (don't ask) and thru trial and error 50-150 gets the servo arm to swing in a open area inside the skull...actually works great......

I appretiate the assistance

JonnyMac

August 16, 2007, 10:46:56 PM #3 Last Edit: August 16, 2007, 11:00:57 PM by JonnyMac
The difficulty with using servos with a simple controller like the Prop-1 is that you have to refresh them in your code -- so this means you can't do long delays, in fact, what you end up doing is using the servo refresh timing in a loop to create a long delay.  Study this program for a while; it approximates what you're doing but refreshes the servo about every 20 ms and randomizes the blinking.

' =========================================================================
'
'   File...... PIR_Head.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  PIR             = PIN6
SYMBOL  Eyes            = PIN1
SYMBOL  Servo           = 0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  pos             = B2                    ' servo state
SYMBOL  pirCount        = B3                    ' for PIR validation
SYMBOL  blinkCnt        = B4                    ' blink count
SYMBOL  idx             = B5                    ' loop controller
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear everything
  DIRS = %00000111                              ' set outputs

  pos = 105                                     ' center


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

Main:
  Eyes = IsOn
  pirCount = 0
  FOR idx = 1 TO 50                             ' 1 second test
    PULSOUT Servo, pos
    PAUSE 18
    pirCount = pirCount + 1 * PIR
    RANDOM lottery                              ' stir random value
  NEXT
  IF pirCount >= 10 THEN Move_Head
    blinkCnt = lottery // 4 + 1                 ' 1 to 4 blinks

Blink:
  Eyes = IsOff
  FOR idx = 1 TO 6
    PULSOUT Servo, pos
    PAUSE 18
  NEXT
  Eyes = IsOn
  FOR idx = 1 TO 6
    PULSOUT Servo, pos
    PAUSE 18
  NEXT
  blinkCnt = blinkCnt - 1
  IF blinkCnt > 0 THEN Blink
    GOTO Main


Move_Head:
  FOR pos = 105 TO 155                          ' center to one-side
    PULSOUT Servo, pos
    PAUSE 18
  NEXT
  FOR pos = 155 TO 55 STEP -1                   ' all the way back
    PULSOUT Servo, pos
    PAUSE 18
  NEXT
  FOR pos = 55 TO 105                           ' back to center
    PULSOUT Servo, pos
    PAUSE 18
  NEXT
  IF PIR = IsOn THEN Move_Head                  ' move until PIR off
    GOTO Main


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


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


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