November 24, 2024, 12:10:47 PM

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.


Haunted Mansion Inspired Clock

Started by ScaryTinker, August 13, 2014, 10:04:54 AM

Previous topic - Next topic

ScaryTinker

Hi,

Can you help with a program for a "haunted"  mantle clock?

Input: PIR
Output: 12 volt dc gear reduction motor for the hour hand (150ma)
Output: 4 LEDs to light the clock face wired in series. (1 output terminal)
Output: 2 LEDs to provide backlight.  Wired in parallel using the same output terminal
Output: 2 LEDs Eyes. Wired in parallel using the same output terminal

Behavior:  Clock is dormant until the PIR senses motion.  Backlight fades up to full brightness over one second.  Eyes fadeup to full brightness over second.  Clock face lights at full brightness.  Motor spins for 12 seconds.  All LEDS and motor are turned off (no fade) no retrigger for 30 seconds.

Thanks

JonnyMac

Using PWM with the Prop-1 means doing things sequentially -- I hope that's the behavior you're looking for. I also used PWm on the motor to ease the current load when starting up.

' =========================================================================
'
'   File...... scary_tinker_clock.bs1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 13 AUG 2014
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger        = PIN6                  ' SETUP = DN

SYMBOL  Motor          = 4

SYMBOL  ClockFace      = 2
SYMBOL  Eyes           = 1
SYMBOL  Backlight      = 0


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

SYMBOL  IS_ON          = 1                     ' for active-high in/out
SYMBOL  IS_OFF         = 0


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

SYMBOL  timer          = B2
SYMBOL  level          = B3


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

Reset:
  PINS = %00000000                             ' clear all outputs
  DIRS = %00111111                             ' make P0-P5 outputs

  PAUSE 30000                                  ' PIR 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

  ' fade up backlight

  FOR level = 1 TO 255                         ' off to on
    PWM Backlight, level, 1                    ' in 255 x 5ms = 1.275s
  NEXT
  HIGH Backlight                               ' keep it on

  ' fade up eyes

  FOR level = 1 TO 255
    PWM Eyes, level, 1
  NEXT
  HIGH Eyes

  ' fade up clock face

  FOR level = 1 TO 255
    PWM ClockFace, level, 1
  NEXT
  HIGH ClockFace

  ' reduce start-up surge with PWM

  FOR level = 1 TO 255 STEP 2
    PWM Motor, level, 1
  NEXT
  HIGH Motor

  PAUSE 11000

  FOR level = 255 TO 0 STEP -2
    PWM Motor, level, 1
  NEXT
  Low Motor

  GOTO Reset


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


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


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


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

JackMan

ScaryTinker,
    If you want the clockface to light up at full intensity (no fade up) just omit the "FOR, NEXT" commands in the clockface section.  ;)