May 15, 2024, 12:22:22 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.


2010 Hellevator Simulator

Started by Ryanm0085, July 25, 2010, 12:36:37 PM

Previous topic - Next topic

bsnut

As I said Ryan here is your basic program without the sound in it. If you have any problems with the program let me know and I will help you out. Give me a day or two and we can add the sound to this program after you test this code.
'   File.......Hellevator
'   Purpose....
'   Author.....
'   E-mail.....
'   Started....7/7/2010
'   Updated....
' {$STAMP BS2}
' {$PBASIC 2.5}
'INPUTS
'--------------------------------------------------------------------
Call     PIN 0  'INPUT 1 (Elevator Call BUTTON)
Floorsel PIN 1  'INPUT 2 (Floor SELECT BUTTON)
Reset    PIN 2  'INPUT 3 (Reset BUTTON)

'OUTPUTS
'--------------------------------------------------------------------
Lights        PIN 3  'Elevator Lights (NC Contacts. Lights are ON when no signal sent)
Lightsel      PIN 4  'Elevator Light TOGGLE (Toggles between flourescent lights AND black lights)
OutsideLight  PIN 5  'Outside Light TOGGLE (Toggles between HIGH hats AND strobe lights)
AirBagsUp     PIN 6  'Air Bags Up
AirBagsDown   PIN 7  'Air Bags Down (NC Contact.  Valve is always open with no signal sent)
Relief        PIN 8  'Relief Valve
UpArrow       PIN 9  'Up Arrow
Doorsel       PIN 10 'Door TOGGLE (ON a circuit so when no signal, the door is open.  When a signal is sent, the door will close)

'RC-4/AP-8 SERIAL I/O
'--------------------------------------------------------------------
Sio     PIN 7
uMP3RX  PIN 13
uMP3TX  PIN 13
'CONSTANTS
'--------------------------------------------------------------------
#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            ' fast baud for accessories
dis1            CON     %10000100
dis2            CON     %11010011
dis3            CON     %11010110
dis4            CON     %10110100
dis5            CON     %01110110
dis6            CON     %01110111
dis7            CON     %11000100
dis8            CON     %11110111
dis9            CON     %11110110


'VARIABLES
'--------------------------------------------------------------------
segindex  VAR Byte
thePin    VAR Byte
floor     VAR Byte
delay     VAR Byte

'EEPROM DATA
'--------------------------------------------------------------------

'INITIALIZATION
'--------------------------------------------------------------------
  HIGH Lights
  HIGH AirBagsDown
  SEROUT Sio, Baud, ["!DC16", %00, "zr", 1, 100]
  LOW Lights
  HIGH Lightsel
  PAUSE 1000
  LOW Lightsel
  HIGH OutsideLight
  PAUSE 1000
  LOW OutsideLight
  LOW Lights
  HIGH Doorsel
  PAUSE 1000
  LOW Doorsel
  HIGH AirBagsDown
  PAUSE 1000
  LOW AirBagsDown
  HIGH Doorsel


'PROGRAM CODE
'--------------------------------------------------------------------
Main:
  DO
   IF Reset = 1 THEN Prop_Reset
   IF Call = 1 THEN Call_Elevator
  LOOP

Call_Elevator:
  PAUSE 2000                                  'Pause 1 second
  LOW Lights
  LOW Lightsel
  HIGH UpArrow                                'Up Arrow outside car on
  SEROUT Sio, Baud, ["!DC16", %00, "P", 8, 1] 'Up Arrow in car on
  PAUSE 1000
  DO
   IF Floorsel = 1 THEN Floor_Selected
  LOOP

Floor_Selected:
  PAUSE 2000
  HIGH Doorsel
  LOW UpArrow                                 'Up Arrow outside car off
  SEROUT Sio, Baud, ["!DC16", %00, "P", 8, 0] 'Up Arrow in car off
  PAUSE 2000
  LOW AirBagsUp
  DO
   GOSUB Floor_display
   PAUSE 10
   delay = delay + 1
  LOOP UNTIL (delay >=200)
  LOW AirBagsDown
  PAUSE 1000
  HIGH Lights
  HIGH Lightsel
  PAUSE 2000
  LOW Lights
  SEROUT Sio, Baud, ["!DC16", %00, "x"]  'Clears display
  PAUSE 3000
  HIGH OutsideLight
  LOW Doorsel
  DO
   IF Reset = 1 THEN Prop_Reset
  LOOP

Prop_Reset:
  LOW OutsideLight
  LOW Lightsel
  HIGH Lights
  HIGH 10
  SEROUT Sio, Baud, ["!DC16", %00, "x"]  'Clears display
  GOTO Main


'SUBROUTINES
'--------------------------------------------------------------------
Floor_display:
segindex = segindex + 1
LOOKUP segindex, [dis1, dis2, dis3, dis4, dis5, dis6, dis7, dis8, dis9], floor
SEROUT Sio, Baud, ["!DC16", %00, "L", floor]
RETURN
William Stefan
The Basic Stamp Nut

JonnyMac

I would suggest a debounce subroutine for the buttons.  If the controller happens to be on a simple input line when someone keys up a radio, or there is some other radiated energy that makes it onto the line you can get a false start (ask me how I know....).  You could do this and call it from areas of the the code that need it.

Check_Buttons:
 state = %00000111
 FOR idx = 1 TO 50
   PAUSE 1
   state = state & INL
 NEXT


The first line arms the inputs (for P0..P2, which are on INL).  The loop ensures that the button is pressed -- and stays pressed -- at least 50ms.  On returning, the bits in state will have the debounced inputs.

Here's how you can use the subroutine:

Main:
 GOSUB Check_Buttons
 IF state.LOWBIT(2) = Yes THEN Prop_Reset
 IF state.LOWBIT(0) = Yes THEN Call_Elevator
 GOTO Main


If you change the three PIN definitions to CON you can make the code easier to read:

Main:
 GOSUB Check_Buttons
 IF state.LOWBIT(Reset) = Yes THEN Prop_Reset
 IF state.LOWBIT(Call) = Yes THEN Call_Elevator
 GOTO Main

Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

Hey once again thanks guys and sorry for the lack in details.  I am a fan of Jonny's idea regarding the inputs becasue we operate 2-way radios all night and i would hate a fasle triggering.  I will attempt to insert this code into the main program.  Waiting for the uMP3 code is fine too.  I am gonna try and tackle it  the program myself and see if i can make it work using the examples...

JonnyMac

In my September Nuts & Volts column I talk about the logic for incremental, step-by-step development.  When we developed the AP-16+ is was made up of several subsystems that were individually prototyped and tested.  John B developed the amplifier while I worked on the code for playing back a WAV from an SD card.  The start circuitry was a known (taken right from the EZ-8) and the AUX inputs were also know circuits. That said, we had to develop code (in a new language) to make sure that all individual pieces worked.

When JB sent me the first prototype I created a test program, one section at a time.  I tested the digital inputs, then the pots, the relay output, the bi-color LED (also new code for the new chip), and, finally, playing a WAV.  We didn't order a big (expensive) production run until the prototype had be electrically evaluated.  That program serves as our production test today.

So... again, I encourage you to understand the big picture, but build and test your program one section at a time.  Yes, this seems tedious, but I know from nearly 40 years (yes, I started in utero) of experimenting and circuit development that this is in fact the shortest path to a successful project.  

BTW, last year I programmed a "hellavator" on site and it was tricky due to the use of air bags.  If you can add limit switches to your code that will simplify things and prevent over-inflation.  We didn't have them and it took me a few hours to tune to code so that we never had that problem.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

Thanks for your prospective on this. Do you have video, like you did for your former bosses ;D. It's not bad  program for not having the hardware in front of me. The only thing I left out was the denounced inputs and I  thank-you Jon for showing it.

I normally write my programs in small chunks and then test it. I only have the BS2 and Carrier board and BS2 Homework board by Jon's former bosses. As I said beforehand I didn't get time to go to MW Haunters trade show to get the Prop2 and DC16 from Jon. Was ridding my roller coasters ;D at Cedar Point.

I love to write programs for anyone who wants one and I'm glad that Ryan give me chance to write his program. Now I, got a chance to tease Jon's world and I thank-you for saying in the background on this one.
William Stefan
The Basic Stamp Nut

Ryanm0085

My goal after Octbober this year is going to be to build a test board with 16 leds and 16 momentary push buttons, one for each channel.  Not that i would ever need that many inputs but this will allow me to test anything i want. Then i will order another Prop-2 and pair them.  Then im going to sit down and really concentrate on the Basic Language.  Once again, awesome support from your guys.  It is greatly appreciated...

bsnut

Thanks, that's what we are here for :D.

Here is DC16 test code to tests the displays in your Hellevator car. To preform this test, make sure that the power switch is set position "1" and the ULN2803A pin1 is not in it's socket (remove or cut), then you can download this test code to the prop2. When this test code works out, then insert it into your program where you need it. The Out8 and Out16 are for your arrows. You will need replace the line of code that I use for the Up Arrows in the car.
'   File.......7segment display test
'   Purpose....Tests the DC16 7-segment displays
'   Author.....W. Stefan
'   E-mail.....williamstefan@hotmail.com
'   Started....8/13/2010
'   Updated....
' {$STAMP BS2}
' {$PBASIC 2.5}
'INPUTS
'--------------------------------------------------------------------


'OUTPUTS
'--------------------------------------------------------------------


'RC-4/AP-8 SERIAL I/O
'--------------------------------------------------------------------
Sio             PIN 7
'CONSTANTS
'--------------------------------------------------------------------
#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            '9600 baud rate for accessories
dis0            CON     %11101110
dis1            CON     %10001000
dis2            CON     %11010110
dis3            CON     %11011100
dis4            CON     %10111000
dis5            CON     %01111100
dis6            CON     %01111110
dis7            CON     %11001000
dis8            CON     %11111110
dis9            CON     %11111100

'VARIABLES
'--------------------------------------------------------------------
floor           VAR     Byte
segindex        VAR     Byte
'EEPROM DATA
'--------------------------------------------------------------------

'INITIALIZATION
'--------------------------------------------------------------------


'PROGRAM CODE
'--------------------------------------------------------------------
FOR segindex = 0 TO 8  'First 7-segment display on the right
LOOKUP segindex, [dis1, dis2, dis3, dis4, dis5, dis6, dis7, dis8, dis9], floor
SEROUT Sio, Baud, ["!DC16", %00, "L", floor]
PAUSE 100
NEXT
FOR segindex = 0 TO 3  'Second 7-segment display on the left
LOOKUP segindex, [dis0, dis1, dis2, dis3],floor
SEROUT Sio, Baud, ["!DC16", %00, "S", dis1, floor]
PAUSE 100
NEXT
'SUBROUTINES
'--------------------------------------------------------------------


I will have your sound test code later on tonight or tomorrow.

William Stefan
The Basic Stamp Nut

bsnut

I am going to pull one from one of the posts that Jon made for the sound code. You can have one line of code like this

SEROUT TX, Baud, ["PC F /firefly.mp3", CR]

or like this, Jon did.

'   File....... uMP3_Demo_BS2.BS2
'   Purpose....
'   Author..... Jon Williams, EFX-TEK
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated....
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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


Sio             PIN     15                      ' for DC-16, RC-4; no ULN
TX              PIN     14                      ' to UMP3.R; no ULN
RX              PIN     13                      ' to UMP3.T; no ULN
Trigger         PIN     12                      ' SETUP = DN


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

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
#ENDSELECT

Inverted        CON     $4000
Open            CON     $8000
EfxBaud         CON     Open | T38K4            ' for DC-16, RC-4
uMP3Baud        CON     Open | T2400            ' for uMP3 player

Yes             CON     1
No              CON     0


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

char            VAR     Byte                    ' character value
theMP3          VAR     Byte                    ' MP3 file pointer
eePntr          VAR     Word                    ' EEPROM memory pointer
pos             VAR     Word                    ' uMP3 file position
loopNum         VAR     Byte                    ' file loop # in cycle
lottery         VAR     Word                    ' random value


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

Reset:
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  DO
    SEROUT TX, uMP3Baud, [CR]                   ' send CR
    SERIN  RX, uMP3Baud, [char]                 ' get response
  LOOP UNTIL (char = ">")                       ' wait for ">"


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

Main:
  RANDOM lottery
  IF (Trigger = No) THEN Main

  theMP3 = lottery // 3                         ' make 0 - 2
  GOSUB Play_MP3                                ' play it

  PAUSE 5000
  GOTO Main


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

' Put file # to play in "theMP3"
' -- add DATA label entries to LOOKUP as required

Play_MP3:
  LOOKUP theMP3, [SFX0, SFX1, SFX2,
                  SFX3, SFX4, SFX5], eePntr     ' get base address

Send_Play_Cmd:
  SEROUT TX, uMP3Baud, ["PC F /"]               ' start play command

Send_Name:                                      ' send file title
  DO
    READ eePntr, char
    eePntr = eePntr + 1
    IF char = 0 THEN EXIT
    SEROUT TX, uMP3Baud, [char]
  LOOP

Finish_Cmd:
  SEROUT TX, uMP3Baud, [".MP3", CR]             ' send extention + CR

Wait_For_Stop:                                  ' let song finish
  DO
    GOSUB Get_Status
  LOOP UNTIL (char = "S")
  RETURN

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

' Gets status from uMP3
' -- "P" = playing, "D" = paused, "S" = stopped
' -- also gets file position and loop number of play cycle

Get_Status:
  SEROUT TX, uMP3Baud, ["PC Z", CR]
  SERIN  RX, uMP3Baud, [char, DEC pos, DEC loopNum]
  RETURN


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

' MP3 files are stored in root of SD card
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

SFX0            DATA    "Hello", 0
SFX1            DATA    "Wolf", 0
SFX2            DATA    "Scream", 0
SFX3            DATA    "Chuckie", 0
SFX4            DATA    "Exorcist", 0
SFX5            DATA    "Lightning", 0

The second one that Jon did would be the one I would put in your program and this is where I found it at
http://www.efx-tek.com/php/smf/index.php?topic=748.0 for future reference. It gives you better control over your player for what you want to do.

I will redo your program for you and post it here later on. I love helping others as you can see ;D.
William Stefan
The Basic Stamp Nut

bsnut

August 16, 2010, 03:34:30 AM #38 Last Edit: August 17, 2010, 09:42:28 PM by bsnut
Here is your redone program for you. I hope you like it.

'   File.......Hellevator
'   Purpose....
'   Author.....
'   E-mail.....
'   Started....7/7/2010
'   Updated....
' {$STAMP BS2}
' {$PBASIC 2.5}
'INPUTS
'--------------------------------------------------------------------
Call          CON 0    'INPUT 1 (Elevator Call BUTTON on Pin 0)
Floorsel      CON 1    'INPUT 2 (Floor SELECT BUTTON)
Reset         CON 2    'INPUT 3 (Reset BUTTON on Pin 2)
state         VAR Byte 'Holds the button state for the input scan

'OUTPUTS
'--------------------------------------------------------------------
Lights        PIN 3  'Elevator Lights (NC Contacts. Lights are ON when no signal sent)
Lightsel      PIN 4  'Elevator Light TOGGLE (Toggles between flourescent lights AND black lights)
OutsideLight  PIN 5  'Outside Light TOGGLE (Toggles between HIGH hats AND strobe lights)
AirBagsUp     PIN 6  'Air Bags Up
AirBagsDown   PIN 7  'Air Bags Down (NC Contact.  Valve is always open with no signal sent)
Relief        PIN 8  'Relief Valve
UpArrow       PIN 9  'Up Arrow
Doorsel       PIN 10 'Door TOGGLE (ON a circuit so when no signal, the door is open.
                     'When a signal is sent, the door will close)

'RC-4/AP-8 SERIAL I/O
'--------------------------------------------------------------------
Sio     PIN 15       'serial to DC16; no ULN
uMP3RX  PIN 14       'to UMP3.R; no ULN
uMP3TX  PIN 13       'to UMP3.T; no ULN
'CONSTANTS
'--------------------------------------------------------------------
#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open | T38K4            '9600 baud rate for accessories
uMP3Baud        CON     Open | T2400            'for uMP3 player

'The follow connections are for both 7-Segment Displays in the car.
'Left 7-Segment Display in car (connections to DC16)
'                        ___
'                        "A" = DC16 OUT1
'       "F" = DC16 OUT6 |   |"B" = DC16 OUT2
'                        ___
'                        "G" = DC16 OUT7
'       "E" = DC16 OUT5 |   |"C" = DC16 OUT3
'                        ___
'                        "D" = DC16 OUT4

'Right 7-Segment Display in car (connections to DC16)
'                        ___
'                        "A" = DC16 OUT9
'      "F" = DC16 OUT14 |   |"B" = DC16 OUT10
'                        ___
'                        "G" = DC16 OUT15
'      "E" = DC16 OUT13 |   |"C" = DC16 OUT11
'                        ___
'                        "D" = DC16 OUT12

'The following constants are for the 7-Segment Display
'Up Arrow = DC16 OUT8 or OUT16 +
'                              |
'                              |GFEDCBA <= This pattern controls the above connections on the DC16
dis0            CON           %00111111
dis1            CON           %00000110
dis2            CON           %01011011
dis3            CON           %01001111
dis4            CON           %01100110
dis5            CON           %01101101
dis6            CON           %01111101
dis7            CON           %00000111
dis8            CON           %01111111
dis9            CON           %01100111


Yes             CON           1
No              CON           0

incrementdelay  CON           100               'Increment delay miliseconds

'VARIABLES
'--------------------------------------------------------------------
idx             VAR     Byte                    'For/Next index for the debounce subroutine

segindex        VAR     Byte                    'For/Next index for the 7-segment display subroutine

floor           VAR     Byte                    'LOOKUP pointer uesd in the 7-segment display subroutine


char            VAR     Byte                    ' character value for the uMP3
theMP3          VAR     Byte                    ' MP3 file pointer for the uMP3
eePntr          VAR     Word                    ' EEPROM memory pointer for the uMP3
pos             VAR     Word                    ' uMP3 file position
loopNum         VAR     Byte                    ' file loop # in cycle for the uMP3

'EEPROM DATA
'--------------------------------------------------------------------

'INITIALIZATION
'--------------------------------------------------------------------

  PAUSE 2000                            ' let uMP3 start

Prod_uMP3:
  DO
    SEROUT uMP3TX, uMP3Baud, [CR]       ' send CR
    SERIN  uMP3RX, uMP3Baud, [char]     ' get response
  LOOP UNTIL (char = ">")               ' wait for ">"

Test_Show:
  HIGH Lights
  HIGH AirBagsDown
  SEROUT Sio, Baud, ["!DC16", %00, "ZF", 1, 100] '"zip" through outputs in forward
  LOW Lights
  HIGH Lightsel
  PAUSE 1000
  LOW Lightsel
  HIGH OutsideLight
  PAUSE 1000
  LOW OutsideLight
  LOW Lights
  HIGH Doorsel
  PAUSE 1000
  LOW Doorsel
  HIGH AirBagsDown
  PAUSE 1000
  LOW AirBagsDown
  theMP3 = 0
  GOSUB Play_MP3
  HIGH Doorsel


'PROGRAM CODE
'--------------------------------------------------------------------
Main:
  GOSUB Check_Buttons                        'Goto Pushbutton debounce subroutine
  IF state.LOWBIT(Reset) = Yes THEN Prop_Reset
  IF state.LOWBIT(Call) = Yes THEN Call_Elevator
  GOTO Main

Call_Elevator:
  theMP3 = 1
  GOSUB Play_MP3
  PAUSE 2000                                  'Pause 2 second
  LOW Lights
  LOW Lightsel
  HIGH UpArrow                                'Up Arrow outside car on
  SEROUT Sio, Baud, ["!DC16", %00, "P", 8, 1] 'Up Arrow in car on
  PAUSE 1000
  DO
   GOSUB Check_Buttons                        'Goto Pushbutton debounce subroutine
   IF state.LOWBIT(Floorsel) = Yes THEN Floor_Selected
  LOOP

Floor_Selected:
  PAUSE 2000
  HIGH Doorsel
  LOW UpArrow                                 'Up Arrow outside car off
  SEROUT Sio, Baud, ["!DC16", %00, "P", 8, 0] 'Up Arrow in car off
  PAUSE 2000
  LOW AirBagsUp
  GOSUB Floor_display
  LOW AirBagsDown
  PAUSE 1000
  HIGH Lights
  HIGH Lightsel
  PAUSE 2000
  LOW Lights
  SEROUT Sio, Baud, ["!DC16", %00, "x"]       'Clears display
  PAUSE 3000
  HIGH OutsideLight
  LOW Doorsel
  GOSUB Relief_Valve_Control
  GOTO Main

Prop_Reset:
  GOSUB Relief_Valve_Control
  LOW OutsideLight
  LOW Lightsel
  HIGH Lights
  HIGH 10
  SEROUT Sio, Baud, ["!DC16", %00, "x"]  'Clears display
  GOTO Main


'SUBROUTINES
'--------------------------------------------------------------------
Check_Buttons:          'Pushbutton debounce subroutine
  state = %00000111
  FOR idx = 1 TO 50
    PAUSE 1
    state = state & INL
  NEXT
  RETURN

Floor_display:         '7-segment display subroutine
FOR segindex = 0 TO 8  'First 7-segment display on the left
LOOKUP segindex, [dis1, dis2, dis3, dis4, dis5, dis6, dis7, dis8, dis9], floor
SEROUT Sio, Baud, ["!DC16", %00, "L", floor]
PAUSE incrementdelay
NEXT
FOR segindex = 0 TO 3  'Second 7-segment display on the right
LOOKUP segindex, [dis0, dis1, dis2, dis3],floor
SEROUT Sio, Baud, ["!DC16", %00, "S", dis1, floor]
PAUSE incrementdelay
NEXT
RETURN

Relief_Valve_Control:
  PAUSE 1000
  HIGH Relief
  PAUSE 2000
  LOW Relief

' Put file # to play in "theMP3"
' -- add DATA label entries to LOOKUP as required

Play_MP3:
  LOOKUP theMP3, [SFX0, SFX1], eePntr           ' get base address

Send_Play_Cmd:
  SEROUT uMP3TX, uMP3Baud, ["PC F /"]           ' start play command

Send_Name:                                      ' send file title
  DO
    READ eePntr, char
    eePntr = eePntr + 1
    IF char = 0 THEN EXIT
    SEROUT uMP3TX, uMP3Baud, [char]
  LOOP

Finish_Cmd:
  SEROUT uMP3TX, uMP3Baud, [".MP3", CR]         ' send extention + CR

Wait_For_Stop:                                  ' let song finish
  DO
    GOSUB Get_Status
  LOOP UNTIL (char = "S")
  RETURN

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

' Gets status from uMP3
' -- "P" = playing, "D" = paused, "S" = stopped
' -- also gets file position and loop number of play cycle

Get_Status:
  SEROUT uMP3TX, uMP3Baud, ["PC Z", CR]
  SERIN  uMP3RX, uMP3Baud, [char, DEC pos, DEC loopNum]
  RETURN


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

' MP3 files are stored in root of SD card
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

SFX0            DATA    "One", 0
SFX1            DATA    "Two", 0


I show the connections to the DC16 in the program related to 7-segment display for you, but made some small changes for the 7-segment, that are shown in the program. These changes match a standard 7-segment display. I started with OUT1 and went clockwise starting at the top of the display and ended up in the middle of the display(OUT7), which means you may need to rewire your connections to the display. The arrows are connected as you stated(OUT8 or OUT16). I hope this is OK for you.

When testing this code you should comment sections or lines of the code out. It is done like this.
Code before commented out:

HIGH OutsideLight

Code after commented out:

'HIGH OutsideLight

Please let me know if you need any more help.
William Stefan
The Basic Stamp Nut

Ryanm0085

Okay i have installed this program and tried running it.  THe elevator initializes fine and the mp3 starts playing, but when the first input on P0 is pushed, nothing is happening.  My trigger is connected on the P0 pins between the R and the W pin...

bsnut

August 22, 2010, 10:16:26 PM #40 Last Edit: August 23, 2010, 04:32:57 AM by bsnut
I will try a test with the code that I written (Jon did the debounce code and I copied and paste it into your program) on my BS2 Homework board as early as of today and as late as this Thursday night into Friday morning when I am off of work. If you want to try changing the debounce time in the code to see if this works for you. The debounce time maybe to small and may need to be extended. We may need to do the standard Jon debounce code that he uses for the prop2 and prop1.

I would like you to try this line of code after you "comment out" existing line of code before you inserting this one. We will not use this, because it is not debouncing code, it just checking the code below Call_Elevator label.

IF PIN0 =0 THEN Call_Elevator
William Stefan
The Basic Stamp Nut

bsnut

August 23, 2010, 08:28:44 AM #41 Last Edit: August 23, 2010, 04:30:34 PM by bsnut
Ryan,
I tested the debounce code when I got home and found no problems with it. I think the problem you are having is with the outside world. Here is the test debounce code that I just tested, it was base on Jon's idea.

'   File.......
'   Purpose....To test and check the Pushbutton debounce subroutine
'   Author.....Redone by William Stefan (Based on Jon Williams code)
'   E-mail.....
'   Started....
'   Updated....
' {$STAMP BS2}
' {$PBASIC 2.5}
'INPUTS
'--------------------------------------------------------------------
Call          CON 0    'INPUT 1 (Elevator Call BUTTON on Pin 0)
Floorsel      CON 1    'INPUT 2 (Floor SELECT BUTTON on Pin 1)
Reset         CON 2    'INPUT 3 (Reset BUTTON on Pin 2)
state         VAR Byte 'Holds the button state for the input scan

'OUTPUTS
'--------------------------------------------------------------------


'RC-4/AP-8 SERIAL I/O
'--------------------------------------------------------------------

'CONSTANTS
'--------------------------------------------------------------------
Yes             CON           1
No              CON           0

'VARIABLES
'--------------------------------------------------------------------
idx           VAR Byte
'EEPROM DATA
'--------------------------------------------------------------------

'INITIALIZATION
'--------------------------------------------------------------------


'PROGRAM CODE
'--------------------------------------------------------------------
Main:
 GOSUB Check_Buttons                        'Goto Pushbutton debounce subroutine
 IF state.LOWBIT(Reset) = Yes THEN Prop_Reset
 IF state.LOWBIT(Call) = Yes THEN Call_Elevator
 IF state.LOWBIT(Floorsel) = Yes THEN Floor_Selected
 GOTO Main

Call_Elevator:
DEBUG "Called Elevator", CR
GOTO Main

Floor_Selected:
DEBUG "Floor is Selected", CR
GOTO Main

Prop_Reset:
DEBUG "Prop is Reset", CR
GOTO Main

'SUBROUTINES
'--------------------------------------------------------------------
Check_Buttons:          'Pushbutton debounce subroutine
 state = %00000111
 FOR idx = 1 TO 75
   PAUSE 1
   state = state & INL
 NEXT
 RETURN


What I would do is disconnect your current switch circuit that you have. Then you need to take a servo extender cable, which is going act as switch by placing a jumper or a switch between "R" red and the "W"white on the opposite end of the servo extender cable and the other end of the servo cable and plug it into the P0 on the Prop2 . Then you need to copy and then paste the above code into your Stamp Editor and run it. After you have downloaded this program the Debug Terminal window will pop up and when you close the switch or have the red and white jumped out, it will display in the Debug Terminal "Called Elevator" and when you plug the servo cable into P1 and do the same thing it will display in the Debug Terminal "Prop is Reset". Once you know this works, then you can try the program that I did for you. The goal of this test is to get the outside world into stamp's world, so it can show you what you told it to do.  

The best thing you can do is use the DEBUG instruction through out your code when you are testing and troubleshooting. It helps you troubleshoot problems like this.        
William Stefan
The Basic Stamp Nut

Ryanm0085

Alright i must have had a brain fart last night.  i came in today and tried the inputs and everything is working fine now.  Unfortunately i am having some problems with the uMP3 player now.  When i initially turn everything on, the elevator goes through its intialization sequence and does start the one.mp3.  However, it seems as if the program stops there.  It will not respond to the second input or the reset input.  I had to change the baud rate in the program to 9600 which im not sure if i did it right, but the uMP3 does play now, it just won't allow the program to advace. 

Ryanm0085

alright im not bragging but im getting somewhat better. i noticed the wait for stop command and removed it.  Now everthing seems to be working ok. 

bsnut

I am glad that the program is working for you. If you need any more help just say the word.
William Stefan
The Basic Stamp Nut