CSCI 345: Lab 5
Inputs
and
Outputs
Due:
10PM
on
Monday,March 16th.
In this lab, you should learn:
- How to recieve input from a button
- How to debounce a button
- How to write to a LCD display
To complete this lab, you will need:
- A computer.
- An arduino.
- A USB cable to connect your arduino to your computer.
- A push button.
- A LCD display.
- A potentiometer.
- A 220Ω resistor and a 10 kΩ resistor.
- A breadboard.
- Wires.
Part 0 - Github
Click on this link to create your github repo.
Part 1 - Receiving input from a button.
Follow this guide to have your arduino read input from a button. After this, your onboard LED should blink when you press the button.Note: The buttons that come with your kit are slightly confusing, as they have 4 pins but actually only 2 electrical connections. A diagram of how they work can be found here.
Part 2 - Serial monitor.
It's extremely helpful to be able to have the arduino print to a computer for debugging purposes. Follow this tutorial to find out how to use the serial monitor to communicate with your computer from the arduino. You should be able to just add the serial monitor parts of the code to your existing sketch if you don't want to rewire anything.
Part 3 - Setting up an LCD display
Follow this guide to set up an LCD screen with your arduino. You will want both the LCD screen and the button attached to your arduino for the next steps, so keep that in mind as you are setting up.You can find a guide to what the different LCD pins do here
NOTE: The potentiometers that came with your kits may be wired slightly differently from the one in the tutorial. Check if the middle pin is on the same side or opposite side as the other two pins, and wire your circuit accordingly.
You may find this wiring diagram to be helpful.
Part 4 - Debouncing a button
Next, set up your button with the LCD screen, and write code to have the LCD screen display the number of times the button is pressed. You may notice that the button registers multiple button presses when you have only pressed this once. To fix this, you will need to write code to debounce the button. You can do that by following this tutorial.
Part 5 - Button games
Now you will take what you learned in the previous parts of the lab, and use it to design a game or program of your choosing. Your program must use both the LCD display, and one or more buttons.Some example programs:
- Have the user guess a random number by pressing the button the correct number of times.
- Have the user navigate through a choose-your-own-adventure type game, selecting options by pressing multiple buttons, or pressing the button a certain number of times.
- Have users compete to see who can press a button more times in a set amount of time.
- Have the user tap in a message in Morse code and display the message in english on the LCD display.
- Have the user navigate a maze by pushing different buttons for forward, backwards, up and down.
Handin
You will submit your assignment by posting a comment on the piazza thread for lab 5. Your post should include a link to the a video of you demoing your program, and a link to a github repository that contains your arduino code.
C. Taylor