Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 2.84 KB

reflex_subtask_2.asciidoc

File metadata and controls

32 lines (22 loc) · 2.84 KB

Sub-Task 2 will use the same circuit you assembled for Sub-Task 1; we will simply make a change to the programming that will light up the LED after a random number of seconds has elapsed. The parts required for Sub-Task 2 are identical to those listed in [reflex_subtask_1].

You can download the program for Sub-Task 2 at http://examples.oreilly.com/0636920020882/ or simply enter the code below into the Arduino IDE:

link:attachments/SubTask2_draft1.0.pde[role=include]

After you upload this sketch to the MintDuino, and each time you reboot or power up the MintDuino, the following will occur once:

  1. The minimum wait time for turning on the LED will be initialized with a value of 2000 milliseconds (2 seconds).

  2. A random seed will be generated using ambient noise (fluorescent lights, cosmic rays, radio waves, etc.) that analog pin 1 picks up.

Next, as long as the MintDuino is running (until you turn it off or its battery dies), the following actions occur over and over:

  1. The main loop of the sketch starts and a random value between 0 and 5000 milliseconds will be added to the minimum wait time to generate a value between 2000 (2 seconds) and 7000 (7 seconds).

  2. A for loop, which sets the variable count to 0, 1, and 2 in order, comes next. I don’t use the variable count for anything other than making sure the code inside the loop runs exactly three times. This causes three fast flashes of the LED, alerting game players to begin watching for the game LED to light.

  3. Next, there is a random pause (based on a value between 2000 and 7000 milliseconds).

  4. The LED will light and hold for two seconds.

  5. The LED will turn off and remain off for a five second delay.

  6. The loop begins again (back to step 1).

As you can see, the beginnings of the MintDuino Reflex Game are starting to appear. We have a random amount of time that will pass before the LED lights up–this is what the two players will be waiting to see before they push their buttons.

And buttons is what we need to learn how to use now. We’ll next tackle Sub-Task 3 and learn how to light that LED by pressing a pushbutton. Unplug the USB cable from the FTDI/MintDuino and make no changes to the wiring of the LED and RES1.

Note

If you managed to get the LED to light in Sub-Task 1, then any problems you’ll likely have with Sub-Task 2 will exist in the program itself.

If you’re not seeing the initial three quick flashes of the LED, check your code to make certain you’re not using the ledWait variable to control the on-and-off lighting in the for loop (there should be two delays of 250 milliseconds in the for loop). If you’re not getting a random wait after the three initial flashes (for example, if the delay is always the same number of seconds), make certain that you’re using ledWait to calculate the delay before taking the pin high right after the for loop.