' =========================================================================
'
' File...... music player.bs2
' Purpose... control MDFLY AU5018
' Author.... Timothy Ewing
' E-mail.... time2dive@hawaii.rr.com
' Started... 14 NOV 2019
' Updated... 16 NOV 2019
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' Discussion from EFX-Tek board:
' http://www.efx-tek.com/php/smf/index.php?topic=2400.0
'
' Ported from Prop-1 (Basic Stamp 1) to Prop-2 (Basic Stamp 2).
' This version uses serial control for the MDFly/Tenda board.
' Connect a servo cable from R/B/W header on Pin 7 to VCC, GND, and Pin 16 on MP3 board.
' Then use pins 17, 18, and GND on the MP3 board for the headphone jack.
' Name the MP3s like this:
' 001 Firstsound.mp3
' 002 Secondsound.mp3
'
' Name the files like this, make a folder on the SD card named 001,
' then copy the MP3s into the folder the SD card.
'
' Then sort the FAT on the SD card using a utility like DriveSort:
' http://www.anerty.net/software/file/DriveSort/?lang=en
' This makes sure the MP3 player sees "001 Firstsound.mp3" as the actual first sound!
' -----[ Program Description ]---------------------------------------------
' audio board controller
' input PIR
' output to MP3 player via serial
' output lights
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
Sio PIN 15 ' SETUP = out; no ULN
PIR PIN 14 ' SETUP = DN
MP3 PIN 7 ' Connect to Tenda MP3 board on Pin7 header.
LIGHT1 PIN 1 ' light 1
' -----[ Constants ]-------------------------------------------------------
IsOn CON 1 ' for active-high in/out
IsOff CON 0
#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
Open CON $8000
Baud CON Open + T38K4 ' B/R jumper installed
' -----[ Variables ]-------------------------------------------------------
timer VAR Word
PIRWarmup VAR Byte
WarmupTime VAR Byte
WarmupTime = 30 ' This may need to be as long as 60 for a reliable PIR response. 30 = 30 seconds.
' -----[ Initialization ]--------------------------------------------------
Reset:
OUTH = %00000000 : OUTL = %00000000 ' preset IOs
DIRH = %00000000 : DIRL = %10000010 ' set outputs (1s)
SEROUT MP3, 188, [239] 'STOP MP3 module before doing anything
FOR PIRWarmup = 1 TO WarmupTime ' Define loop for PIR calibration time
PAUSE 500 ' Wait 0.5 seconds
DEBUG "." ' Visual feedback in DEBUG window
PAUSE 500 ' Wait 0.5 seconds
NEXT
' -----[ Program Code ]----------------------------------------------------
Startup:
' light1 = IsOff ' light 1 off
PAUSE 1000
SEROUT MP3, 188, [01] ' Play SFX 1
PAUSE 1000 ' wait
SEROUT MP3, 188, [239] ' Stop playing
SEROUT MP3, 188, [06] ' Play repeat (assumes repeat is named 006 repeat.mp3)
PAUSE 1000 ' pause
SEROUT MP3, 188, [239] ' Stop playing
PAUSE 4500 ' wait 4.5 seconds
Main:
timer = 0 ' reset PIR debounce timer
DEBUG CR, "Ready", CR
Check_Trigger:
DO WHILE (timer < 100) ' wait for 0.1 sec input
PAUSE 5 ' loop pad
timer = (timer + 5) * PIR ' update timer
LOOP
DEBUG CR, "Triggered", CR
LIGHT1 = IsOn ' turn on light
SEROUT MP3, 188, [02] ' Play SFX 2
PAUSE 4500 ' wait
SEROUT MP3, 188, [239] ' Stop playing
SEROUT MP3, 188, [03] ' Play SFX 3
PAUSE 4500 ' wait
SEROUT MP3, 188, [239] ' Stop playing
LIGHT1 = IsOff ' light 1 off
SEROUT MP3, 188, [01] ' Play SFX 1
PAUSE 1000 ' wait
SEROUT MP3, 188, [239] ' Stop playing
SEROUT MP3, 188, [06] ' Play SFX 6 (repeat sound)
PAUSE 1000 ' wait
SEROUT MP3, 188, [239] ' Stop playing
GOTO Main
' =========================================================================
'
' File...... music player.bs1
' Purpose... control MDFLY AU5018
' Author.... Timothy Ewing
' E-mail.... time2dive@hawaii.rr.com
' Started... 14 NOV 2019
' Updated...
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' audio board controller
' input PIR
' output relay controls
' output lights
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Sio = 7 ' SETUP = out; no ULN
SYMBOL trigger = PIN6 ' SETUP = DN
SYMBOL play = PIN0 ' play
SYMBOL track1 = PIN1 ' track 1
SYMBOL track2 = PIN2 ' track 2
SYMBOL track3 = PIN3 ' track 3
SYMBOL repeat = PIN4 ' repeat
SYMBOL light1 = PIN5 ' light 1
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1 ' for active-high input
SYMBOL IsOff = 0
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000 ' clear all
DIRS = %00111111 ' make P0-P5 outputs
' -----[ Program Code ]----------------------------------------------------
Startup:
PAUSE 1000
play = IsOn ' play mp3
PAUSE 1000 ' wait
play = IsOff ' play off
repeat = IsOn ' repeat on
PAUSE 1000 ' pause
repeat = IsOff ' repeat off
PAUSE 4500 ' play track 1 for 45 seconds
Main:
Check_Trigger:
PAUSE 5 ' loop pad
timer = timer + 5 * Trigger ' update timer
IF timer < 100 THEN Check_Trigger ' wait for 0.1 sec input
light1 = IsOn ' turn on light
track2 = IsOn ' track 2 on
PAUSE 1000 ' pause
track2 = IsOff ' track 2 off
PAUSE 4500 ' wait while track 2 plays
track3 = IsOn ' track 3 on
PAUSE 1000 ' wait
track3 = IsOff ' track 3 off
PAUSE 4500 ' play track 3 for 45 seconds
light1 = IsOff ' light 1 off
track1 = IsOn ' track 1 on
PAUSE 1000 ' wait
track1 = IsOff ' track 1 off
repeat = IsOn ' repeat on
PAUSE 1000 ' wait
repeat = IsOff ' repeat off
GOTO Main