Shop OBEX P1 Docs P2 Docs Learn Events
Coding help. PLEASE! — Parallax Forums

Coding help. PLEASE!

matthew024matthew024 Posts: 9
edited 2008-07-15 08:41 in BASIC Stamp
I did a mini project. I have 6 leds and I put them to flashing in RANDOM. Either single, double, or triple leds. I also have two pushbuttons. I want one button to start the RANDOM flashing of lights and the other pushboutton to stop the flashing. Then if I push the other pb, then it should start flashing randomly again. I already tried the DO WHILE thing. I have Board of Education Full Discovery Kit. Rev C. CODING HELP!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-07-14 17:02
    This post is being moved from the Forum Support area to the BASIC Stamps forum as it is off topic in the original forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • MorrolanMorrolan Posts: 98
    edited 2008-07-15 08:41
    Is this a homework assignment by any chance? tongue.gif

    Your problem is the fact that the basic stamp does not have interrupts, so unless you find some way to frequently check for the status of a button within your code, you won't be able to switch them off.

    The reason is your program structure. Once your program has begun, you can't stop it unless you check the status of the button, but you also have to factor in your delay times. If you momentarily press the stop button during the 100ms delay, it will not stop as it will not even register that the button has been pressed. Instead you will have to hold the button until the flashing stops, as sometimes you will end up pressing the stop button partway through the delay.

    What you should do is create another subroutine called something like check_status. Check this to see if the stop button has been pressed as part of every case statement, so for example case 1 checks button and if it HASN'T been pressed, it returns and executes the next GOSUB which is one of the blinks.

    Also, your program isn't actually random - as your 'seed' variable (result) is empty every time you run your code, your program will actually follow the same pattern. As far as randomisation goes, you need to put a random character into the 'seed' variable before you actually execute the RANDOM part of your code...

    How I do this is on program startup, I use a loop which generates RANDOM (with a seed of 0) numbers until a button is pressed. Once that button is pressed, the current random number is used to then seed the main RANDOM part in my code. That way, even a few milliseconds difference will create a completely different random sequence.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.

    "I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
    Stephen Hawking

    Post Edited (Morrolan) : 7/15/2008 8:47:54 AM GMT
Sign In or Register to comment.