Monday, September 17, 2012

Lab: Digital Input/Output

Overview:

The purpose of this lab was to learn how to preform digital input and output with the Arduino and materials such as LEDs, motors, and buttons. 

Blinking LED:

For my first circuit, I made a simple blinking LED by delaying it while it had power and then again when it did not have power. 

I then improved upon the simple circuit by controlling the brightness of the LED like so:

8 LED Fun:

Next, I assembled a circuit that contained 8 LEDs and controlled then with code that included for loops (used to run a piece of code multiple times) and arrays (for managing a group of variables more easily) to keep the program small.

The first circuit turned all the LEDs on and then turned them all off. The code also included other fun animations such as turning on all LEDs one at a time and turning on all LEDs starting from the inside and working its way out giving an in and out effect.

This video shows the circuit doing all of the animations one after another:

Spin Motor Spin:

For this circuit, I used a transistor and a motor in my circuit which turned the motor on. I then played around with the code and made the motor accelerate and decelerate.

Button Pressing:

I added input to this circuit by included 2 small push buttons. I changed the circuit so that one button turns the LED on and the other turns it off. To make it better, I then made one button increase the brightness of the LED and the other button decrease the brightness.

State and Debouncing:

This circuit has a single push button. When you push and release the button the LED stays on until you push and release it again.

Reaction Challenge Game:

I designed and implemented a reaction challenge game that demonstrated my mastery of this lab. It involves both digital input and output. For this game, I set up a line of 7 LEDs with the one in the middle being red to indicate its importance. I also included a red LED and a green LED on the end for "win" and "lose". On the opposite end is a large push button for input.

The object of the game is for a player to push the button when the middle LED is lit. If the player does so, the green LED lights up and if not the red LED lights up. 

There are 8 levels to the game and each level has an increased speed. The player has 3 lives and once they are used up the row of LEDs lights up the number of LEDs that matches the level the player got to.





I used many for loops and functions in this game for things like traversing through the LEDs, losing lives, and "winning" or "losing". To see the whole code that was used it can be seen here: The code

Problems:

During this lab, I encountered problems with weaker resistors or LEDs. It was important for the bulbs to be of equal brightness for aesthetic reasons so using trial and error I found LEDs that worked for me. Another way to do this would be to read the resistors and know the level you are working with.

Links:

For more information on digital input and output:

No comments:

Post a Comment