Help with a sound effect device
Quornes
Posts: 4
I'm a senior in highschool, and am working on my senior project, a sound effect device. My idea was to have it work by pushing a two button combination (out of four buttons) which would then play back a sound. I haven't done any real BASIC programming before, although I was learning Ruby when I started working on this. When it came time for me to test out my programming, it predictably didn't work. I was wondering if anyone had any advice for me on it, or suggestions. I know my code structure is probably very bad, and I might be using some of the wrong commands
.
Theres a link to my device schematic here
http://yfrog.com/4vseniorprojectschematicp
Im using the Board of Education development board, and the SOMO-14D Audio Sound Module.
This is the link to the sound module page, and its data sheet (which is in a pdf format)
www.4dsystems.com.au/prod.php?id=73
www.4dsystems.com.au/downloads/Audio-Sound-Modules/SOMO-14D/Docs/SOMO-14D-DS-rev3.pdf
And here is the code I wrote
Edited to include info on development board and sound module.
Second edit to include updated code
Post Edited (Quornes) : 5/10/2010 3:28:44 PM GMT
.
Theres a link to my device schematic here
http://yfrog.com/4vseniorprojectschematicp
Im using the Board of Education development board, and the SOMO-14D Audio Sound Module.
This is the link to the sound module page, and its data sheet (which is in a pdf format)
www.4dsystems.com.au/prod.php?id=73
www.4dsystems.com.au/downloads/Audio-Sound-Modules/SOMO-14D/Docs/SOMO-14D-DS-rev3.pdf
And here is the code I wrote
'{$STAMP BS2} 'Stamp directive '{$PBASIC 2.5} 'PBASIC directive DEBUG "Program Running" '----------{I/O}-------------------------------------------- Data1 PIN 1 Clock PIN 2 Reset PIN 3 Button_1 PIN 10 Button_2 PIN 11 Button_3 PIN 12 Button_4 PIN 13 '----------{SOHO 14D Audio Module Commands}----------------- 'Play/Pause FFFEh 'Stop FFFFh 'Volume FFF0h-FF7h (In terms of volume) 'Songs 0000h,0001h,0002h,0003h,0004h 'PIN 1 NEXT 'PIN 2 NC 'PIN 3 CLK 'PIN 4 DATA 'PIN 5 BUSY 'PIN 6 PLAY/STOP 'PIN 7 PREVIOUS 'PIN 8 VCC 'PIN 9 GND 'PIN 10 RESET 'PIN 11 SPK+ 'PIN 12 SPK- 'PIN 13 NC 'PIN 14 AUDIO '----------{Variables}-------------------------------------- volumechange VAR Byte songselect VAR Byte songplay VAR Byte btnwork VAR Byte Songfile VAR Word Play VAR Word Volume VAR Word Song VAR Word VolumeCheck VAR Word '----------{Constants}-------------------------------------- BAUD CON 9600 SongDelay CON 10000 '----------{Initialization}--------------------------------- DEBUG "Initialization" Songfile = 0 Play = 65534 Volume = 4087 Song = 0 VolumeCheck = 0 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]volumechange] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Volume] Restart: DEBUG "Restart" Songfile = 0 Song = 0 LOW Reset GOTO Main '----------{Program Code}----------------------------------- Main: DEBUG "Main" GOSUB SubFileSelect GOSUB SubFileSelect2 GOSUB SubSongSelect SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songplay] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Play] PAUSE SongDelay GOTO Restart '----------{Sub Routines}----------------------------------- SubFileSelect: DEBUG "SubFileSelect" BUTTON Button_1, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 1 BUTTON Button_2, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 2 BUTTON Button_3, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 4 BUTTON Button_4, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 8 RETURN SubFileSelect2: DEBUG "SubFileSelect2" BUTTON Button_1, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 10 BUTTON Button_2, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 20 BUTTON Button_3, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 40 BUTTON Button_4, 1, 255, 20, btnwork, 1, Main Songfile = Songfile + 80 RETURN SubSongSelect: DEBUG "SubSongSelect" SELECT Songfile CASE 11 Song = 0 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 12 Song = 1 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 14 Song = 2 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 18 Song = 3 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 21 Song = 4 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 22 Song = 5 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 24 Song = 6 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 28 Song = 7 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 41 Song = 8 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 42 Song = 9 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 44 Song = 16 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 48 Song = 17 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 81 Song = 18 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 82 Song = 19 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 84 Song = 20 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] CASE 88 Song = 21 SHIFTOUT Data1, Clock, MSBPOST ,[noparse][[/noparse]songselect] SHIFTIN Data1, Clock, MSBPOST ,[noparse][[/noparse]Song] ENDSELECT RETURN
Edited to include info on development board and sound module.
Second edit to include updated code
Post Edited (Quornes) : 5/10/2010 3:28:44 PM GMT
Comments
This part is almost exactly repeated many times and would be a good candidate for a subroutine. You could do a case to get the song number and then call the sub to play it, much less code and chance for errors.
Also a link to your sound chip would be helpful.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
With the case command, would something like this work?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
What I currently have is something like this.
BUTTON command works like this
BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address
My problem is the Address part. Originally I thought setting it up the way I have it would change Songfile when the button was pushed, but after checking
"Back to the Basics (PBASIC) With Fun and Games" www.parallax.com/dl/docs/cols/nv/vol1/col/nv35.pdf
it seems that is not the case. Instead I would have to do something like this.
My question is there a way around doing the above code for each button pushed?