Sept. 19, 2023
Make a red, green and blue LED light up consecutively.
Component | Amount |
---|---|
ESP32-S3-WROOM | 1 |
GPIO Extension Board | 1 |
Project Board | 1 |
LED (R, G, B) | 3 |
Wire M-M | 6 |
Resistor - 220 Ω | 3 |
from time import sleep_ms
from machine import Pin
led_r = Pin(1,Pin.OUT) # pin for red led
led_g = Pin(2,Pin.OUT) # pin for green led
led_b = Pin(3,Pin.OUT) # pin for blue led
try:
while True:
led_r.value(1) # red led turn on
sleep_ms(1000)
led_r.value(0) # red led turn off
led_g.value(1) # green led turn on
sleep_ms(1000)
led_g.value(0) # green led turn off
led_b.value(1) # blue led turn on
sleep_ms(1000)
led_b.value(0) # blue led turn off
except:
pass
Create a circuit that turns on an LED light when pressing one button, and turns that LED light off when pressing another button. The buttons should not be able to toggle the light by themselves.
Component | Amount |
---|---|
ESP32-S3-WROOM | 1 |
GPIO Extension Board | 1 |
Project Board | 1 |
LED red | 1 |
Wire M-M | 6 |
Push Button | 2 |
Resistor - 220 Ω | 1 |
Resistor - 10k Ω | 4 |
import time
from machine import Pin
led = Pin(1, Pin.OUT) # pin for led
button_a = Pin(3, Pin.IN,Pin.PULL_UP) # connection for button a
button_b = Pin(10, Pin.IN,Pin.PULL_UP) # connection for button b
while True:
if not button_a.value(): # button A pressed
time.sleep_ms(20) # account for bounce
if not button_a.value(): # if button A still pressed
if not led.value():
led.value(1) # turn led on
if not button_b.value(): # button B pressed
time.sleep_ms(20) # account for bounce
if not button_b.value(): # if button B still pressed
if led.value():
led.value(0) # turn led off