Shop OBEX P1 Docs P2 Docs Learn Events
Coding Help! — Parallax Forums

Coding Help!

matthew024matthew024 Posts: 9
edited 2008-07-12 20:41 in Learn with BlocklyProp
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

  • FranklinFranklin Posts: 4,747
    edited 2008-07-12 03:18
    You should have some debounce on your switches. What does it do you don't like or want different?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • matthew024matthew024 Posts: 9
    edited 2008-07-12 19:53
    I just want one to start and one to stop anytime. Then if I press the start once more, it should go again.
  • P!-RoP!-Ro Posts: 1,189
    edited 2008-07-12 20:41

    The first thing I would do is to simplify the code a little so it is easier for you and others to understand. One of the things you can do is to get rid of all those variables and replace them with constants. For instance, RED_LED1 VAR Byte and RED_LED1= 15 would turn into RED_LED1 CON 15. Also, in your if-then statement, I would add a sub to go to if IN3 = 1, so people aren't confused by the ELSE at the bottom of it.

    If you want it to stop when you push the second button, one possibility is to add another if-then statement at the bottom and use the GOTO command. If you use this you could get rid of the second loop and put the name there (like randomBinks[noparse]:)[/noparse] and a second one before the first DO command. When the pushbutton is pressed, make it go back to the first loop you have, and if it isn't pressed, make it go back to where you had the second DO command (what I called randomBlinks). Hope this helped.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Pi Guy
Sign In or Register to comment.