Hello everyone,
I have a strange problem, I wrote a little program to control a VMUSIC2 MP3 player. It plays an MP3 with morse beeps that will then switch a lamp. The user can change the MP3 file without having to mess with the program.
After playing the file the player should wait between 0 and 45 minutes randomly before playing the morse code again.
All works okay but after a while the randomness disappears and it will always wait 45 minutes. Seems something wrong with the random command, maybe the seed? any help is appreciated. Here's the code:
Code:
' 12-05-09 morse code player, reads mp3 file to control lamp
@ device pic12F683, INTRC_OSC_NOCLKOUT, wdt_off, pwrt_on, mclr_off, protect_off
include "modedefs.bas"
define OSC 4
OSCCON = %01100000 ' Set to 4MHz
CMCON0 = %00000111 ' Analog comparators off
ANSEL = %00000010 ' Set AN1 as analog, rest digital
TRISIO = %00100010
GPIO = %00010000 ' GPIO.4 hoog voor serieel, start anders niet
relay var GPIO.0
led var GPIO.2
counter var word
temp var word
time var word
audio var byte
pause 2000
loop:
SerOut GPIO.4,T2400,["V3A",13] ' play all songs
play_morse:
toggle led
adcin 1,audio
if audio > 25 then ' test sound (more than 500 mV)
high relay
else
low relay
endif
SERIN2 GPIO.5,396,20,play_morse,[wait ("Stopped")]
random temp
time = temp/24 ' between 0 and 45 seconds
for counter = 1 to time
pause 1000
toggle led
next counter
goto loop
End
Bookmarks