# Name: Hoor Shumail
# Reg: 22-NTU-CS-1347
# Home task: 2.1 Working with Neopixel and input button
print("starting of neopixel flashing ") # just checking printing output
from machine import Pin
from neopixel import NeoPixel
import time
btn =Pin(0, Pin.IN, Pin.PULL_UP) # same pin for physical esp32 s3 built in Boot buton
pin = Pin(33, Pin.OUT) # set 48 for your physical esp32 s3
neo = NeoPixel(pin, 1) # create NeoPixel driver for 1 pixel
while True:
while(btn.value()==1): # flashing of neopixel stopped when button is in pressed status
neo[0] = (255, 0, 0) # set the first pixel to red
print("red")
neo.write() # write data to all pixels
time.sleep(.2)
neo[0] = (0, 255, 0) # set the first pixel to green
print("red")
neo.write() # write data to all pixels
time.sleep(.2)
neo[0] = (0, 0, 255) # set the first pixel to blue
print("blue")
neo.write() # write data to all pixels
time.sleep(.2)
# Task Questions:
# Upload the same code to a physical ESP32 S3:
# Run the code.
# Take a snapshot of Thonny.
# Record a short video of your physical device (change the pin from 33 to 48 for the physical device).
# Investigate the Neopixel color behavior:
# Why does the Neopixel always turn blue when the button is pressed?
# How can it be made to stop on different colors in real-time (e.g., sometimes red, sometimes green, sometimes blue)?
# Modify the code for button presses:
# Change the color after every 5 button presses.
# Examine the result: Does the color change exactly after 5 presses, or is there abnormal behavior?
# If there is abnormal behavior, what could be the reason?
# Make your own code modifications:
# Implement your own changes to the code.
# Submit the link to your Wokwi project for all tasks (no hardware changes required for any task). Ensure all questions are answered in your own words, and the code is written in your own style.
# Most important: Do your own work. This is a viva-based home task.