Shop OBEX P1 Docs P2 Docs Learn Events
Class Project — Parallax Forums

Class Project

RumfinatorRumfinator Posts: 1
edited 2008-12-02 21:11 in BASIC Stamp
My partner and I are building a school project. The point of the project is to create a simulated battle field. We will have 14 toy soldiers that sit on a small foam constructed battlefield. Each soldier will sit above a plastic tube. The plastic tubes are connected to a 24v 24 output pneumatic manifold. Each input from the pneumatic manifold is controlled by an output from a demulitplexer (which is controlled by the basic stamp).

What we want to do is program the basic stamp in the following manor:
1) Star button enables program
2)Random generator will generate a number between 1-14
3)whichever number is picked will set of a if/then statement that goes to a sub program
4)that sub program will enable the corresponding pneumatic manifold input.
5)That then sends a puff of air under the corresponding soldier to launch them into the air.
6)This will continue to happen until one team of 7 is completely eliminated.
7)That will trigger one more sub program to play the winning teams victory song through one of our four speakers.
8)DONE!

My main question is 1) Is this doable with a random generator? 2)There are going to be many in/then statements, is there a command that can condense this?

P.S. My partner and I just started to learn about the Basic stamp a few weeks ago and we are not experienced programmers. Any direction would actually be excellent!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-02 18:38
    1) Yes. The RANDOM statement produces a "random" value between 0 and 65535. You can use the modulus operator ("// 14") to produce a remainder between 0 and 13, then add 1. Look in the Basic Manual for the explanation for "//".

    2) There's no way to directly condense IF / THEN without actually simplifying the choices involved. Statements like LOOKUP, LOOKDOWN, SELECT can all help simplify a program. Sometimes using small arrays can help. It depends on the details.

    3) There are lots of tutorials on Parallax's website. From the main page, click on the Resources tab, then Downloads, then Stamps in Class Downloads. A good starting point is the "What's a Microcontroller?" tutorial. Also look through the Nuts and Volts Columns. The index is off the Resources tab as well.
  • SRLMSRLM Posts: 5,045
    edited 2008-12-02 21:11
    Note that the random generator is psuedo-random. Whatever value you seed it with will always provide the same result as long as the seed is the same. There are lots of discussions on how to make a more random number, but perhaps your best option would be to time the down time of the button, and use that as the seed value.
Sign In or Register to comment.