Week 2: Embedded Programming

Prior Experience: 4/5

I've taken a class (RIP 6.08) all about embedded systems. We coded in C++/Arduino and used an ESP32. I made a pedometer, a smart clock (that sleeps upon inactivity and can be shaken awake), a morse code writer, a handheld trivia game, and a clap-activated system (that displays a different image based on the pattern of claps). For our final project, we made a system that keeps track of refrigerator inventory and suggests recipes based on leftover ingredients. However, this was in my freshman year, so I've unfortunately forgotten a lot of it.

Embedded Programming

Choosing a Microcontroller

I decided to use the ESP32 microcontroller because I have used it before (in 6.08), so I am mildly familiar with it. In more complex situations, I'll have to think more deeply about which microcontroller to use, but I think for a simple application, any will suffice.

The Idea

Since I'm not very good with circuits and completely new to Wokwi, I decided to go for something very simple: a RGB LED light, which switches colors based on the press of a button.

Wiring the Circuit

The R/G/B ends of the LED were connected to resistors, which were then connected to 3 different I/O pins on the microcontroller. The anode end was connected to 5V. Finally, the button was connected to ground and another I/O pin.

Writing the Program

Writing the program was not too difficult. Finally something I'm familiar with! The button debouncing logic was a little difficult to get right at first. For each iteration of loop, we essentially get the reading of the button, check whether the button state has changed from the previous state + whether the reading is HIGH, and if so, change the color of the LED. The debouncing logic involves checking whether the time since the last time the button bounced has exceeded a set "debounceDelay", and only executing our button press logic if so.

Simulating its Operation

It works!