Saturday, November 19, 2011

Button Control Assignment (CIRC07)

Purpose
The purpose of this assignment is to investigate the code that utilizes the buttons in circuit seven.

Equipment

  • 2 x Pushbutton
  • 2 x 10k Ohm Resistor
  • 4 x 330 Ohm Resistor
  • 4 x LED
  • 10 x Wires
  • 1 x Arduino Uno
  • 1 x Breadboard & reference sheet
Assembly


     Assembling this circuit takes around 7-10 minutes. It has the same format as circuit seven, except there are 3 more LEDs. You can note that the number of wires and resistors increase accordingly. Simply follow the same pattern of assembly for the extra LEDs, resistors and wires. Make sure the pushbutton is securely inserted before uploading the program.


Program Details

   This assignment consists of 3 sets of codes. Each explained within their own comments. The main purpose is to use the 'analogread' function to read the state of the button, then use 'if, else if, else'  to connect the corresponding state to the output (LEDs). If the button is pressed, the state is 'LOW', it it's unpressed the state is 'HIGH'. The last set of code, uses the 'and' function within one of it's if statements. This only executes the if statement if both conditions are met. In fact, set 3 is almost a direct copy of set 2 except the parts that are commented (and function one of them). 

Set 1: When button A is pressed all even LEDs are turned on for 0.5 seconds. When button B is pressed, all odd LEDs are turned on for 0.5 seconds.





Set 2: First, the number of times button A is pressed corresponds to the LED that will be turned on. Each time it's pressed, the first LED turns on for confirmation. Then, button B is pressed, and the corresponding LED (according to previous # of presses) is turned on for 0.5 seconds. Button A must be pressed before button B. If not, nothing will happen. Also if nothing is pressed, nothing happens.





Set 3: This is similar to Set 2. However, the LED that will turn on is determined by the number of times both button A and B are pressed. Both buttons must be pressed before pressing button B. 



*The three different sets of code serve as modifications of each other. Refer to the Next Steps & Modifications section in CIRC07 for more modifications that utilize the pushbuttons.*

Results


     All programs worked, however there is strict timing, which is annoying. For instance, button A has to be pressed soon after the LED confirming this turns off.Or else, the program will jump to the 'else if' block. Besides this, the circuit worked as instructed by the program. It's also nice to learn efficient and complex programming techniques. The challenge is fun, versus programming as the kit instructs. 

Tips


     After assembling the circuit check to make sure everything is wired properly, especially resistors. The resistors for the buttons are especially important because if the resistors are missing, it'll be short circuited!! For the program, first make sure your pins correspond to the actual circuit. Before programming, have a rough sketch of how you're going to implement the basic functions. Also try to be as efficient as possible. As you're programming, remember to consider every possibility, so that everything is tackled in the 'if, else if, else' statements. Occasionally, stop and run through the program from the beginning to avoid care less mistakes, repetitions, and have flow. You'll often do this subconsciously. It's easy to miss brackets and such as the program gets bigger. To make sure you have brackets, click on a bracket. This signals it's corresponding bracket. At the end, click play to verify your program. 


Resources


Spark Fun Inventor's Starter Guide
http://schools.tdsb.on.ca/danforthcti/arduino/ArduinoGuide.html

No comments:

Post a Comment