November 22, 2024, 04:00:12 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.


Connecting A Cheap mp3 to Prop1

Started by brad g, March 25, 2007, 08:52:39 PM

Previous topic - Next topic

Clad In Shadows

cool , thanks Jon. I will give it a go as soon as time is on my side and get the board done.
And since I don't know much about programming , your "unprofessional" explanation sounds pretty professional to me  ;)

JonnyMac

After I finish my book for Parallax (on programming the SX chip with SX/B) I will start on a book for us called "Prop Programming for Everybody" -- I'll take you to knowing nothing about Prop-1 programming to being a pro in very short order.  There's no release date for that book yet, so please don't ask for one.
Jon McPhalen
EFX-TEK Hollywood Office

Clad In Shadows

Quote from: JonnyMac on April 05, 2007, 12:18:30 PM
I'll take you to knowing nothing about Prop-1 programming to being a pro in very short order. 

That sounds promising and looks like something some of us could use .
Thanks for the help and support , Jon.

brad g

OK, if I've got this straight, in order to start the mp3 through a 12v relay and run the 2min 30sec song I intend to use, the program (rough-n-dirty version) would look like this:

HIGH 0
PAUSE 2000
LOW 0

PAUSE 150000

HIGH 0
PAUSE 2000
LOW 0

END

and that would get it to start, play and stop. Now for the other routine I was intending to program ( "Blending Servo Motion"), would that be placed after the "END" command for the mp3, or placed in between the PAUSE 150000 and last HIGH 0. Sorry for the cross post, but for me, they are both tied together.

JonnyMac

The limit of values in the Prop-1 (and Prop-2 for that matter) is 65535 (16-bits, a word), so the PAUSE 150000 line will not work as you intend.  No worries, you can simply stack PAUSE routines:

  PAUSE 60000
  PAUSE 60000
  PAUSE 30000


This is, though, a little blunt force and a more elegant programming solution is a delay subroutine that lets us specify the number of seconds to wait.  The code looks like this on the Prop-1:

Delay_Secs:
  IF secs = 0 THEN Delay_Secs_Exit
    PAUSE 1000
    secs = secs - 1
    GOTO Delay_Secs

Delay_Secs_Exit
  RETURN


You also have to define a variable called 'secs.'  If this variable is a byte you can delay up to 255 seconds (four minutes, 15 seconds).  If you use a word you can delay up to  over 18 hours -- so abyte will probably do.  To use the subroutine in your program you can do this:

  secs = 150
  GOSUB Delay_Secs


If you've got a program that requires lots of long delays then this is the best solution.
Jon McPhalen
EFX-TEK Hollywood Office

Clad In Shadows

I got my mp3-player working . I added a relay in between the prop-1 and the mp3-player ( V+ and OUT0 ).
The prop is a Zoltar fortune teller . I have 14 fortunes on my mp3 player . The fortunes are the ones from the old Zoltan machine , so I need to record new ones for my prop.
Here's a link to the prop ( not standalone yet ).
http://s167.photobucket.com/albums/u145/cladinshadows2007/?action=view&current=Zoltar65.jpg

I used the pir code and the little code Jon wrote down and it works like a charm.
Now , the only thing I need to add is ; skipping audio files.
I'm gonna add another relay (V+ and OUT1 ) that will be connected to the mp3-player's "forward"button.
I'd like to skip 4 fortunes at a time . P.ex. fortune 1 will play , next time , fortune 5 will play , then message 9 ,....
That way that'll be a good mix.
How would you put that in code ?

This is what I have so far...

thank you in advance.

' =========================================================================
'
'   File...... Zoltar
'   Purpose... Talking Fortune Teller
'   Author....   Clad In Shadows
'   E-mail....
'   Started...  April 07 , 2007
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  PIR             = PIN7                  ' SETUP = DN


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  pirTimer        = B2


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

Reset:


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

Main:
  pirTimer = pirTimer + PIR * PIR
  PAUSE 10
  IF pirTimer < 2 THEN Main



HIGH 0
  PAUSE 2000
  LOW 0

  PAUSE 52000

  HIGH 0
  PAUSE 2000
  LOW 0

  GOTO Main
  END




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


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


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


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


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


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


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

JonnyMac

How many fortunes do you want to include?  Also, I think your audio should have a few seconds of blank space after so that you have some "fudge factor" when dealing with them.  There are ways to keep track of which files have played so that you can do something randomly, but not have any repeats until all is done.  With the Prop-1 you can do this easily with eight files, with a bit more work you can do 16 (takes more code trickery).

In the meantime you should just experiment with the Forward button to get it working.  I think a PAUSE 100 value will work fine -- guess I better go pick up some relays myself....
Jon McPhalen
EFX-TEK Hollywood Office

Clad In Shadows

I currently have 14 fortunes from the old Zoltan machines ( for demo-ing) but I can live with 8 fortunes if that's less trouble.
I still need to record my own fortunes so it doesn't matter how many.
Since each of the fortunes are about 50 secs long , I added about 10 secs of blank space already and that for the reason you mentioned.

I will add the wires to the forward button probably tomorrow.

Thanks.

Clad In Shadows

Added a second relay to the mp3 player .
The added wire is located on the bottom left switch-leg of the fwd button , same as the connection on the play button.

Now , the mp3 player plays a different fortune eveytime the sensor is activated.
I had to mess around with the PAUSE command and also changed the fortunes. Instead of having 10 secs of silence after the fortune , I changed it to 5 secs before and 5 secs after. The reason for that is because I have the player go to the next fortune at the end of the playing  fortune . Otherwise it would start playing the next fortune right away.
So , a lot of PAUSE commands but it's working.
Thanks Jon for the help .
Once I recorded my new fortunes and have everything in place , I'll post some pics and videos online.
I might actually add another mp3-player to my Zoltar which will be operated through another sensor.
That mp3 player should run the opening line to draw the audience towards the machine.
I think it is possible to have two sensors running on 1 prop-1 controller , am I right?

Anyway ,the file as of now looks something like this :

' =========================================================================
'
'   File...... Zoltar
'   Purpose... Talking Fortune Teller
'   Author....   Clad In Shadows
'   E-mail.... Bluesjammer2004@aol.com
'   Started...  April 07 , 2007
'   Updated...  April 10 , 2007
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  PIR             = PIN7                  ' SETUP = DN
SYMBOL  forward     = 1                             ' forward is connected to P1

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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  pirTimer        = B2


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

Reset:


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

Main:
  pirTimer = pirTimer + PIR * PIR
  PAUSE 10
  IF pirTimer < 2 THEN Main

HIGH 0
  PAUSE 2000
  LOW 0

  PAUSE 58000

  HIGH 0
  PAUSE 1000
  LOW 0

  HIGH forward                                      ' turn forward on
  PAUSE 200                                     ' hold for 1/5 second
  LOW forward                                       ' turn forward off

  PAUSE 2000

   HIGH 0
  PAUSE 2000
  LOW 0

  GOTO Main
  END




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


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


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


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


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


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


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

JonnyMac

Yes, you can have multiple sensors -- deal with them like this:

Main:
  IF Trigger1 = IsOn THEN Show1
  IF Trigger2 = IsOn THEN Show2
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

bourno

April 12, 2007, 08:44:17 PM #25 Last Edit: April 12, 2007, 08:47:30 PM by bourno
I have updated a couple things on my MP3 hack page to include some of the suggestions from here.  I haven't used audio in my past projects and these little players should be fun to add in.

http://www.teambac.com/web_hall/MP3_player_hack.html

I am looking forward for your book Jon on using SX/B for the SX chips.  Past and future props that have needed control used the SX proto boards and I have been using really basic programming so far to control them.

Wes Bourn