Working with pulsein

69-cat

Member
I am working on a code that will control an MP3 player (DFPlayer) via serial data. My goal was to be able to play 4 files with using an AUX channel on an RC transmitter/receiver. I am able to control file one but can not figure out how to set the pulsein range to control each file without triggering the first one. Looking to trigger each file with: example between 90 to 105, 120 to 135 and so on but I see an issue with the scanning of the input only triggering the first value but just dont know how to set it up to ignore the first file (lower value) if the pulsein value is correct to trigger the second file and so on. Hope someone from the forum can give me a boost to get over the issue that I am having.
Thank you....
Dave
 

Attachments

AllyCat

Senior Member
Hi Dave,
Code:
if b2 > 80 then
    goto file1  
endif
if b2 = 110 then
    goto file2  
endif
; etc...
That will always GOTO file1 unless b2 <= 80, which is presumably required to "do nothing". The simpest "fix" is probably, for example:
Code:
if b2 <= 80 then tooshort
if b2 <= 110 then file1
if b2 <= 130 then file2
; etc..
tooshort:   ; Report error or simply loop back
The code could be written much more compactly, for example (untested) with a SELECT ... CASE instruction, or if the pulse widths are equally spaced, a simple mathematical expression could be used, for example: b3 = b2 - 80 / 30 , followed directly by the SEROUT or an ON b3 GOTO ...... construction, etc..
Code:
main:
   pulsin c.1,1,b2
   select case b2
      case 80 to 115
         b3 = 1
      case 120 to 135
         b3 = 2
;  etc..
   else
     sertxd(cr,lf,"Out Of Range")  : goto main
   endselect
   serout mp3,baud, ($7E,$FF,$06,$0F,$00,$01,b3,$EF)
   sertxd(cr,lf,"Playing file ",#b3)   ; For debugging
   do : loop while busy = 0
goto main
Cheers, Alan.
 

69-cat

Member
Thank you for your help and the feedback, I will try these out. Yes, I am not that good with the (short cuts) with code writing but I try to work out what ever issues I come across myself before I reach out to others. On The Job Training LOL...that how we learn
Dave
 
Top