November 23, 2024, 05:51:08 AM

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.


Code Request: Magic '8' Pumpkin

Started by wseay, October 24, 2008, 02:53:13 PM

Previous topic - Next topic

wseay

At the hospital where I work, I have been conscripted into our departments entry for a Pumpkin Carving contest.  Having EFX-TEK parts around, why not a Magic '8' Pumpkin?

Hardware:
Prop-1, FC-1, AP-8, PIR

Overview:
When triggered by PIR, Magic '8' Pumpkin will randomly announce one of 8 phrases.  Each phrase will have one of three lights associated.  Four positive phrases are green,  two negative are red, & two neutral are orange.

Flow:
Wave hand over PIR in Pumpkins head to trigger Prop
Code selects one of 8 random phrases
AP-8 begins playing phrase
FC-1 Fades up light associated with phrase (Green, Red, Orange)
When phrase is complete, light fades out
Wait for next Trigger

I'll post a video of how it turns out.

JonnyMac

Here you go.  This will say all the phrases (randomly) before repeating, and won't say the same phrase twice in a row.  You'll need to update the delay table to match the length of each phrase (minus two seconds for the fade-up and fade-down timing).

' =========================================================================
'
'   File...... Magic8_Pumpkin.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... 25 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


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  timer           = B0

SYMBOL  idx             = B1
SYMBOL  last            = B2
SYMBOL  mask            = B3
SYMBOL  check           = B4
SYMBOL  playList        = B5

SYMBOL  chan            = B6
SYMBOL  delay           = W4

SYMBOL  lottery         = W5


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

Reset:
  SEROUT Sio, Baud, ("!!!!!AP8", %00, "X", "!FC4", %00, "X")


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

Main:
  timer = 0                                     ' reset timer

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

Select_Phrase:
  RANDOM lottery                                ' re-stir
  idx = lottery // 8                            ' randomize, 0-7
  IF idx = last THEN Select_Phrase              ' no repeats
    last = idx                                  ' save for next time
  READ idx, mask                                ' create bit mask
  check = playList & mask                       ' played?
  IF check > %00000000 THEN Select_Phrase       ' if yes, try again
    playList = playList | mask                  ' if no, mark now

Play_It:
  SEROUT Sio, Baud, ("!AP8", %00, "P", idx)

Fade_Up:
  LOOKUP idx, (1, 1, 1, 1, 2, 2, 3, 3), chan
  SEROUT Sio, Baud, ("!FC4", %00, "F", chan, 0, 255, 4)

Audio_Delay:
  LOOKUP idx, (1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000), delay
  PAUSE delay

Fade_Out:
  SEROUT Sio, Baud, ("!FC4", %00, "F", chan, 255, 0, 4)

Check_PlayList:
  IF playList <> %11111111 THEN Main
    playList = %00000000
    GOTO Main


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


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


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

Bit_Mask:
  EEPROM (%00000001, %00000010, %00000100, %00001000)
  EEPROM (%00010000, %00100000, %01000000, %10000000)
Jon McPhalen
EFX-TEK Hollywood Office

wseay

Thanks Jon!

I carve the prototype today.  Wire tomorrow.  Then build, debug, & submit Wednesday.

I'll keep you all posted...

wseay

Howdy all!

Our Pumpkin was a hit!  But for some odd reason it was not included in the judging.  :(  But the team was proud of their work and has already begun musing for next year.

As with most team projects, initial scope and final product differ quite a bit.  I will create a post in 'Completed Projects' to share how it all came together.

I must stop and thank Jon & John for all of their excellent support!  The variety of products, the DOCUMENTATION, Code Samples, and the near real-time response to forum posts is truly remarkable. 

Did I mention that the documentation and samples are very complete?  In my job I code and design around various vendor specs.  You will not believe how much is left out (pay no attention that I work in Health Care)!

Again, thanks!

Walter...