Newbie needs help


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2008
    Posts
    16

    Red face Newbie needs help

    So, I'm very new to this, bare with me... I have a loop statement going and going and going.. as follows: (just a 10sec interval flashing LED)

    loop:
    High 0
    Pause 10000

    Low 0
    Pause 10000

    Goto loop
    End

    And I want to interrupt this loop with a button push, more importantly a button hold, (2sec). So when you hold the button it pops out of its loop.

    Don't really know where to start with this... as far as I can tell I can only check the button state (up/dn) once per loop?
    Thanks for your patience..
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chien_fu View Post
    And I want to interrupt this loop with a button push, more importantly a button hold, (2sec). So when you hold the button it pops out of its loop.
    Don't really know where to start with this... as far as I can tell I can only check the button state (up/dn) once per loop?
    Thanks for your patience..
    Then don't do one 10-second pause, do 5 2-second pauses....
    Or 10 1-second pauses. If the button is held for 2 consecutive pauses, then kick out of the loop.

  3. #3
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Hot damn! That was quick thinkin! You just blew my mind...
    hehe, thanks dude!
    Is that common practice? Or would interrupts be used for something like that ever?
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chien_fu View Post
    Is that common practice? Or would interrupts be used for something like that ever?
    Totally your call...

  5. #5
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Reign in the randomness

    Next question...
    I'm trying to generate a random number between X and Y...
    The only command I see is:

    Random Var

    And the manual says it generates numbers up to 65,000

    Is there a way to reign this bugger in a bit?
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chien_fu View Post
    Next question...
    I'm trying to generate a random number between X and Y...
    The only command I see is:
    Random Var
    And the manual says it generates numbers up to 65,000
    Is there a way to reign this bugger in a bit?
    Turn on your outside the box thinking...

    If the number is too big, don't use it.
    If the number is too small, don't use it.
    If the number is below the lower limit of what you want, or above the upper limit of what you want, then DON'T USE IT.

  7. #7
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    That's what I've got going now...

    Randomizer:
    RANDOM rand
    high 3 : pause 10 'Blinks an LED once per random number generated
    low 3 : pause 10
    IF rand > 100 THEN Randomizer
    IF rand < 1 THEN Randomizer


    but the "random" numbers just seem to get larger and larger. After rand > 100 it just goes into a vicious blinking cycle, never to return.
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chien_fu View Post
    That's what I've got going now...
    Randomizer:
    RANDOM rand
    high 3 : pause 10 'Blinks an LED once per random number generated
    low 3 : pause 10
    IF rand > 100 THEN Randomizer
    IF rand < 1 THEN Randomizer
    but the "random" numbers just seem to get larger and larger. After rand > 100 it just goes into a vicious blinking cycle, never to return.
    What does your manual say about random, specifically the last sentence in the section about RANDOM?
    And what is the answer to 65535/655 ?
    Can you do anything at all with that?

  9. #9
    Join Date
    Jun 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    What does your manual say about random, specifically the last sentence in the section about RANDOM?
    And what is the answer to 65535/655 ?
    Can you do anything at all with that?
    I see the thread paused for a bit, so I thought I'd twist my head around this and suggest setting rand to 0 before running the randomizer every time, otherwise it'll use the existing rand-value as seed and thus just grow?

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Or use a 16 timer value as a seed the first time, or use an external clock, or this, or that.
    It's been discussed here numerous times on how to get truly random numbers and best answer so far is to seed the randomizer with a truly random event such as a user input which, most likely, could never be exactly the same every time.

Similar Threads

  1. Newbie making an ignition timer
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 5th August 2012, 17:45
  2. Newbie HELP :(
    By TheOne in forum mel PIC BASIC
    Replies: 3
    Last Post: - 27th March 2009, 17:15
  3. Newbie: Temperature measurements
    By Budda in forum General
    Replies: 10
    Last Post: - 30th March 2007, 09:56
  4. PIC Newbie
    By azmax100 in forum Schematics
    Replies: 7
    Last Post: - 23rd February 2007, 04:52
  5. request for a newbie forum
    By nimonia in forum Forum Requests
    Replies: 1
    Last Post: - 20th May 2006, 09:01

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