Physical Computing - LEDs and Push Buttons
In this laboratory, we will continue doing simple circuits where we get more familiar with ESP32 and Python. Instructions are given by Andrew J. Park, Ph.D..
We will use Freenove Ultimate Starter Kit for ESP32-WROVER which you can buy on Amazon. How to set up the kit and start uploading code you can find on Freenove.
Project 1 - Three LEDs
Date: 09/16/23
Instructions:
Design and construct a circuit that includes three LEDs (red, green, and blue). When your program runs, each LED turns on and off (blinks) sequentially and continually (red → green → blue → red → green → blue → …). Capture your settings and working circuit in photos and videos.
Parts:
- ESP32-WROVER x1
- GPIO Extension Board x1 (optional)
- Breadboard x1
- Jumper M/M x6
- Green LED 1x
- Red LED 1x
- Blue LED 1x
- Resistor 220Ω x3
Three LEDs schema:
Three LEDs Breadboard View:
Source Code:
from time import sleep_ms from machine import Pin ledGreen=Pin(2,Pin.OUT) #create LED object from pin2,Set Pin2 to output ledBlue=Pin(15,Pin.OUT) ledRed=Pin(18,Pin.OUT) arr = [ledBlue, ledGreen, ledRed] try: while True: # Infinite loop for element in arr: element.value(1) sleep_ms(200) element.value(0) except KeyboardInterrupt: pass
Project 2 - Two push buttons and an LED
Date: 09/16/23
Instructions:
Design and construct a circuit that includes two push buttons and an LED. When one button is pushed, the LED is on while the other button is pushed, the LED is off. When the same button is pushed multiple times, it should not change the status of the LED. Capture your settings and working circuit in photos and videos.
Parts:
- ESP32-WROVER x1
- GPIO Extension Board x1 (optional)
- Breadboard x1
- Jumper M/M x6
- Green LED 1x
- Push buttons 2x
- Resistor 220Ω x1
- Resistor 10kΩ x4
Two push buttons schema:
Two push buttons Breadboard View:
Source Code:
import time from machine import Pin led = Pin(2, Pin.OUT) buttonOn = Pin(13, Pin.IN, Pin.PULL_UP) buttonOff = Pin(12, Pin.IN, Pin.PULL_UP) def reverseGPIOON(): led.value(1) def reverseGPIOOFF(): led.value(0) while True: if not buttonOn.value(): time.sleep_ms(20) reverseGPIOON() if not buttonOff.value(): reverseGPIOOFF() time.sleep_ms(20)