Checklist: What you need to bring for this lecture
Learning Objectives
After this lecture you should be able to
use a while loop in Arduino code
explain the behavior of pull-down and pull-up circuits for buttons
explain how normally open (NO) and normally closed (NC) switches (or buttons) function in a DC circuit
create a circuit for using a momentary button as a digital input
use a momentary button as a “wait-to-start” input
Reading
Videos and Lecture Slides
Button input for Arduino
-
Screen cast (36.56)
Video
-
Arduino Codes
Each of the following codes are designed to handle the input from a momentary button configured with a pull-down resistor.
button_status.ino is a simple sketch to indicate whether the button is currently pressed. Apart from displaying the button status, this program has little practical use.
button_wait_for_input.ino is a sketch that blocks execution until a button is pressed. This could code could be used as a wait-to-start button.
button_interrupt.ino demonstrates how to use an interrupt to detect when a button is pressed. This is the recommended strategy for using button input.
button_interrupt_count.ino is the same as button_interrupt.ino except that the total number of button presses since start-up is printed to the Serial Monitor.