PDA

View Full Version : Newbie needs help



chien_fu
- 11th June 2008, 01:59
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..

skimask
- 11th June 2008, 02:21
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.

chien_fu
- 11th June 2008, 02:29
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?

skimask
- 11th June 2008, 02:36
Is that common practice? Or would interrupts be used for something like that ever?

Totally your call...

chien_fu
- 12th June 2008, 00:06
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?

skimask
- 12th June 2008, 00:24
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.

chien_fu
- 12th June 2008, 01:19
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.

skimask
- 12th June 2008, 02:39
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?

Finchnixer
- 30th June 2008, 12:10
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?

skimask
- 30th June 2008, 13:52
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.