November 23, 2024, 11:21:49 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.


Blinking eyes

Started by davisgraveyard, September 07, 2009, 09:59:29 AM

Previous topic - Next topic

davisgraveyard

September 07, 2009, 09:59:29 AM Last Edit: September 07, 2009, 10:03:13 AM by davisgraveyard
So I was working on a LED eyes program for the prop1 the other day that randomly fades LED's and also randomly chooses to either blink or fade them.   The blink was being acomplished with a HIGH PAUSE LOW sequence but it looked more like a flashing lights than a blink.  So I did a little research.  

The average human eye blinks at 300-400ms every 5 seconds.    A blink consists of the eyelid moving down then back up again.  Or in LED terms  On then Off again.   When watching and waiting for blinks 5 seconds is a long time so I figured evil eyes blinked a little more often.  The other issue is that bright LED's are a little too bright (almost laser beam bright) so you don't want to use the HIGH LOW way of lighting them but rather something that will only bring them up to about 70%.

The PWM command will bring the LED up to a certain brightness without going to full.  It also has a duration parameter which on the  Prop1 is 5ms per value.  Since I was going for a 350ms blink I needed a value of 70 (5x70-350ms) but since a blink is down and then up I had to divide that in half so I set the value to 35 (5x35=175ms). 

So, using the PWM command  I did the following

PWM 180, theLED, 35
PWM  0,  theLED, 35
PAUSE  3000

For one blink.  I repeated this twice to blink a couple of times.  looks VERY real.


Jeff



JonnyMac

September 07, 2009, 02:21:21 PM #1 Last Edit: September 07, 2009, 03:01:24 PM by JonnyMac
Here's program I came up with that agrees with Jeff's premise: "blinking" LED eyes looks better by ramping down the brightness (close eye) then ramping it back up (open eye).  The program is Prop-1 Trainer friendly:

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


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


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


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


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  idx             = B0                    ' loop controller
SYMBOL  eye             = B1                    ' active "eye"
SYMBOL  last            = B2                    ' last eye blinked
SYMBOL  mask            = B3                    ' bit mask for eye
SYMBOL  playlist        = B4                    ' eyes that have blinked
SYMBOL  result          = B5
SYMBOL  blinks          = B6                    ' #blinks
SYMBOL  speed           = B7                    ' speed of blink
SYMBOL  level           = B8                    ' for PWM

SYMBOL  delay           = W5
SYMBOL  lottery         = W6                    ' W6 okay with NO GOSUBs


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

Reset:
  PINS = %00111111                              ' all eyes one
  DIRS = %00111111                              ' define output pins

  lottery = 1031

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

Main:
  FOR idx = 1 TO 3                              ' big stir
    RANDOM lottery
  NEXT

Select_Eye:
  RANDOM lottery
  eye = lottery // 6                            ' select P0..P5
  IF eye = last THEN Select_Eye                 ' don't repeat eye
    last = eye                                  ' save for next cycle

  READ eye, mask                                ' get bitmask for eye
  result = playlist & mask                      ' check playlist
  IF result > 0 THEN Select_Eye                 ' try again if run this cycle
    playlist = playlist | mask                  ' mark
    IF playlist <> %00111111 THEN Set_Blinks
      playlist = %00000000

Set_Blinks:
  RANDOM lottery
  blinks = lottery // 2 + 1                     ' 1 or 2 "blinks"

Set_Speed:
  RANDOM lottery
  speed = lottery // 10 + 5                     ' set blink speed

Blink_Baby:
  FOR level = 255 TO 0 STEP -speed              ' close eye
    PWM eye, level, 1
  NEXT
  FOR level = 0 TO 255 STEP speed               ' open eye
    PWM eye, level, 1
  NEXT
  HIGH eye
  blinks = blinks - 1
  IF blinks > 0 THEN Blink_Baby

  RANDOM lottery
  delay = lottery // 1001 + 1000                ' 1s to 2s delay
  PAUSE delay

  GOTO Main


' -----[ User Data ]-------------------------------------------------------

Bit_Masks:
  EEPROM (%00000001)
  EEPROM (%00000010)
  EEPROM (%00000100)
  EEPROM (%00001000)
  EEPROM (%00010000)
  EEPROM (%00100000)
Jon McPhalen
EFX-TEK Hollywood Office

davisgraveyard

Not exactly what I was doing but close.

2 things.

1.  Since the eyes are not seen most of the time they have to come on then appear to blink and then go away.  So you can't have them on all the time.  My effect is trying to have a blinking eye appear and then disapear.  So it has to be Low to begin with and then High.  But going to high is only half the blink the other half is going low again.

2.  I don't want to go to full brightness since the LED's are too bright.  So I only go to about a level of 180 which is about 70%.

My original post was wrong

code looks like

PWM theLamp, 170,  35
PWM theLamp, 0 , 35
PAUSE 3000

PWM theLamp, 170,  35
PWM theLamp, 0 , 35
GOTO Main

This will take the LED to 70 percent for 175 ms and then take it to 0% ffor 175 ms and then wait 3 seconds and do it again.





Jeff Haas

Will this code work on a Prop-2?  I know it's kind of overkill but I've got one that's not in use.

davisgraveyard

The units of duration for the PWM command in a Prop2 is 1ms instead of 5ms so the values would have to be 175 instead of 35 but other than that it should work the same.