Day 9: The Festival Of Lights

  1. Understand the basics of using buttons and LEDs.
  2. Learn how to connect components to the HERO R3 and breadboard.
  3. Write and upload code to control the circuit using the Arduino IDE.
  4. Create different lighting modes with variable brightness.

– HERO board
– USB cable
– Breadboard
– 3 LEDs (different colors)
– 1 Button
– Resistors (220 ohm, 10k ohm)
– Jumper wires (Male to Male)
– Printer paper
– Cardboard
– Yarn

As the sun set over Cogsworth City, a warm glow began to fill the streets. It was the annual Festival of Lights, a time when the entire city celebrated with beautiful illuminations and joyous gatherings. This year, Astrid and Gear wanted to contribute something truly magical to the festivities. They decided to create an enchanted lantern that could light up in different modes, each with its own unique charm. Using their adventure kit, they would build a lantern that could glow like a flickering fire or shimmer like magical fairy lights, all controlled by the press of a button.

Gear: “Astrid, the Festival of Lights is the perfect occasion for us to create something enchanting. Let’s build a magical lantern that lights up in different modes like a flickering fire or sparkling fairy lights. We can control it with a button and even adjust the brightness for each mode. Are you ready to add a touch of magic to the festival?”

Astrid: “Yes, Gear! Let’s create something that will mesmerize everyone. This is our chance to shine.”

Gear: “Fantastic! Today, we’ll use our HERO board, LEDs, and a few other components to bring our enchanted lantern to life. Let’s get started.”

Gear: “Astrid, today we’re going to build an enchanted lantern for the festival. We’ll create different lighting modes and control them with a button. We’ll also add variable brightness to each mode.”

Astrid: “That sounds amazing, Gear! How do we start?”

Gear: “First, let’s build the lantern structure. Cut the cardboard into four equal-sized panels and tape them together to form a box. Cut a hole in the top for the LEDs to shine through.”

Astrid: “Got it. What about the paper?”

Gear: “Cut the printer paper to fit each panel and tape it on the inside of the box. This will diffuse the light and create a magical glow.”

Gear: “Place the HERO board on your work surface and the breadboard next to it.”

Astrid: “Done. What’s next?”

Gear: “Now, place the button and LEDs on the breadboard, each spaced apart.”

Gear: “Connect one side of the button to digital pin 2 on the HERO board using a jumper wire. Connect the other side to the ground (GND) rail on the breadboard through a 10k ohm resistor. Also, connect this side to the 5V rail on the breadboard.”

Gear: “Place the LEDs on the breadboard, spaced apart. Connect the long leg (anode) of the first LED to digital pin 8 on the HERO board using a jumper wire. Connect the short leg (cathode) to the ground rail on the breadboard through a 220 ohm resistor.”

Astrid: “I’ll do the same for the other two LEDs, connecting them to digital pins 9 and 10, respectively.”

Gear: “To add a decorative touch, wrap yarn around the cardboard box. This will give the lantern a festive look and add to its charm.”

Gear: “Astrid, LEDs light up when electricity flows through them. By using resistors, we can control the amount of current and protect the LEDs from burning out. The button acts as a switch, allowing us to change the lighting modes.”

Gear: “Astrid, now we need to write code that will control the LEDs and switch between different lighting modes. Let’s write the code step-by-step.”

Gear: “Upload the code to your HERO board and let’s test the circuit. Press the button to switch between the different lighting modes.”

Astrid: “The LEDs flicker like a fire in mode 0, shimmer like fairy lights in mode 1, and stay steadily bright in mode 2. It works!”

Gear: “Now that we have written the code, let’s go through it step-by-step:”

– `const int buttonPin = 2;` declares the pin for the button.
– `const int ledPin1 = 8;` declares the pin for the first LED.
– `const int ledPin2 = 9;` declares the pin for the second LED.
– `const int ledPin3 = 10;` declares the pin for the third LED.
– `const int onboardLed = 13;` declares the pin for the onboard LED.
– In the `setup()` function, we initialize the pins and start serial communication for debugging.
– In the `loop()` function, we read the state of the button using `digitalRead(buttonPin);`.
– If the button state changes, we toggle the mode and update the onboard LED accordingly.
– Depending on the mode, we call different functions to create the desired lighting effect.
– `fireMode()` creates a flickering fire effect by randomly changing the brightness of the LEDs.
– `fairyMode()` creates a shimmering fairy light effect by smoothly

Post a comment

Leave a Comment

Your email address will not be published. Required fields are marked *