Pre-Lecture Prep and Pre-Quiz
Please read the short writeup about while loops and complete the pre-quiz before class (links on Moodle).
Announcements
- Homework 4 is due Tuesday at 11:40am EDT.
- On grading
- Office hours and wizard sessions:
- Delano: Wednesdays at 3pm-5pm EDT (same zoom link as lecture), or by appointment
- Cheever: check his schedule
- Ruether: by appointment Wednesdays 10am-12pm, Thursdays 3pm-5pm EDT (link)
- Wizard sessions: Sunday 1-3pm EDT, Monday 7-9pm EDT (zoom link on moodle)
Learning Objectives and Outcomes
In this lecture, you will...
- read a short writeup about while loops
- work on in class examples on how to use while loops to receive inputs from the serial terminal and turn on a sequence of neopixels
By the end of this lecture, you should be able to...
- Use while loops to read received characters from the serial terminal
- Use while loops to turn on an arbitrary sequence of neopixels, including using break as needed
While Loops
The default flow of an Arduino program is controlled using setup() and loop(), with setup() running once and loop() repeating indefinitely:

The main technique we have discussed to change the program flow inside is if statements (and their variants such as switch-case statements). These statements run a single time; there is no additional loop component to them. But suppose we would like to wait for an input to occur and pause the code, or turn on a sequence of neopixels on programmatically. This is where a new type of technique comes into play: while loops.