November 22, 2024, 06:54:48 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.


Striking Python Program

Started by WolfManor, October 20, 2008, 09:39:39 PM

Previous topic - Next topic

WolfManor

Jon,

It has been a while.  I hope all is well with you.

I am looking to see if you can help with a program.  That is 'nice talk' ;D for you to whip something up for me.  I have a python snake that I want to make jump or strike at people as they walk near.  Here are the details.  Can you help me out?

One Cylinder (In / Out Movement for the Strike of the snake - OUT being the attack postion and IN being the rest position)
Prop 1 for Controller
LED(s) - 2 for Eyes

Start
PIR Sensor Picks up Signal
Light LED Eyes for 2 Seconds
Then send Cylinder OUT
Hold out for 1 Second
Return to Home/Reset
Pause for 5 Seconds
Look for PIR Sensor to Start Again
End


Let me know if you have questions.

Thanks!
Steve

JonnyMac

Okay, that one was pretty easy so I made it a bit more interesting by having the eyes fade up and down -- hope you don't mind.

' =========================================================================
'
'   File...... Python.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 20 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN (PIR)
SYMBOL  Snake           = PIN1                  ' V+/OUT1 (cylinder)
SYMBOL  Eyes            = 0                     ' V+/OUT0 (leds)


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  IsOut           = 1
SYMBOL  IsBack          = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  timer           = B2
SYMBOL  level           = B3


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  PAUSE 5000                                    ' warm-up/delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Eyes_On:
  FOR level = 1 TO 255                          ' fade up
    PWM Eyes, level, 1
  NEXT
  HIGH Eyes                                     ' keep on
  PAUSE 725                                     ' pad for 2 secs

Strike:
  Snake = IsOut
  PAUSE 1000
  Snake = IsBack

Eyes_Off:
  FOR level = 255 TO 0 STEP -1                  ' fade down
    PWM Eyes, level, 1
  NEXT

  GOTO Reset


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


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


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

WolfManor

Thanks Jon!

I was waiting for the 'I can do this with one arm tied behind my back' comment - LOL

The eyes will be a nice touch! 

I will give it a try this weekend.

Take Care!
Steve