random problem


Results 1 to 6 of 6

Thread: random problem

Threaded View

  1. #1
    Join Date
    Oct 2007
    Location
    The Netherlands
    Posts
    45

    Default random problem

    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
    Last edited by eggman; - 21st May 2009 at 18:34.

Similar Threads

  1. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. Another Serin/Serout Problem!
    By jmbanales21485 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 16:26
  4. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59
  5. 6 random numbers limiting to 49 ?????
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th June 2005, 23:27

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts