Skip to content

Final project

Final project – Fablab

Road to final ideas

  1. Parametric box where you can lock your phone and controlled by a timer lock were it focus in helping youth in control there smart phone addiction.
  2. 4-in-1 portrait frame where it help you put 4 different picture in photo frame and can be controlled by remote control to change the main face.
  3. Parametric jewelry and accessory box with a place where you can put your phone to present a hologram inside the box.

Introduction

I decided to mesh all the three ideas into one where it is artistic, parametric, and creative and help someone. I noticed that in the game room in my house were children set some color sketches on the wall and their toys they dearly loved once thrown in the storage box with their paintings and drawings. Therefore I decide to create something helpful for hyperactive children who may suffer from ADHD. After some research I found out that letting children express their creativity can be a way to let them feel calm and more focused.

I noticed that we need something to help children be more dependent help them overcome their fear of dark and enable them to do their daily life activity such as going to bathroom alone at night and wake-up for school alone. Helping children overcome their fear is important to unleash their creativity and build there hobbies and talent. One of the ways is to make them understand our physical world better such sea-life and nature. Also exposing children to any form of art is a great way to let them interact with their surrounding and help them express their ideas and have fun at the time.

I tried to generate an idea that help children in daily life and express their creativity. I found an interesting idea about infinity mirror where if you put any item between two mirrors in specific controlled light surrounding condition you can see the object reflect infinitely. An example, if you go to an elevator with three mirror in different direction you can see an infinity image of yourself. Therefore, I decided to create a kids-friendly table that have sensors to help children wake up in the morning for school and help them overcome their fear of darkness because when the move across it to go to the bathroom at night it detect their movement and light up until the children went back to sleep.

Importance of My Final Project

Art can be a powerful tool for children with ADHD and hyperactivity. Here’s why:

• Focus and Concentration: Art projects, especially those with a clear beginning, middle, and end, can help children with ADHD focus their attention and channel their energy. The repetitive nature of some art forms, like drawing or painting, can provide a calming structure.

• Emotional Expression: Art provides a non-verbal way for children to express their feelings, which can be challenging for those with ADHD who may struggle with impulsivity or difficulty communicating emotions.

• Stress Reduction: The creative process can be very relaxing and help reduce anxiety and stress, common challenges for children with ADHD.

• Self-Esteem Boost: Completing an art project, no matter how simple, can give children a sense of accomplishment and boost their self-esteem.

• Fine Motor Skills: Many art forms, like drawing, painting, and sculpting, help develop fine motor skills, which can be beneficial for children with ADHD who may have difficulties with coordination.

• Problem-Solving: Art often involves problem-solving, such as figuring out how to mix colors to achieve a certain effect or how to create a three-dimensional object.

Types of Art that Can Help: • Drawing and Painting: These activities can be very calming and help children focus their attention.

• Sculpting and Modeling: Working with clay or other materials can be a great way to channel energy and develop fine motor skills.

• Collage: Creating collages can be a fun and engaging way to express creativity and explore different textures and colors.

• Music: Playing an instrument or listening to music can be very calming and help children regulate their emotions. It’s important to remember that every child is different, and what works for one may not work for another. It’s a good idea to experiment with different types of art activities to see what your child enjoys most.

Electronics

Micro-controller

Knowing your microcontroller name and understanding your pin layout is essential to create your code. Difficulties – pin number + if analog or digital + why extra pins what to do?

Light shifting

Grove - RGB LED Stick (10-WS2813 Mini)

Download library

[visit website] - https://github.com/adafruit/Adafruit_NeoPixel

Code:

#include <Adafruit_NeoPixel.h>

// Define the number of LEDs
#define NUM_LEDS 10

// Define the data pin connected to the LED strip
#define PIN 4

// Create an Adafruit_NeoPixel object
Adafruit_NeoPixel pixels(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // Initialize the NeoPixel library
  pixels.begin(); 
}

void loop() {
  // Example: Set all LEDs to red
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(255, 0, 0)); 
  }
  pixels.show(); // Update the LEDs
  delay(500); 

  // Example: Set all LEDs to green
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(0, 255, 0)); 
  }
  pixels.show(); 
  delay(500); 

  // Example: Set all LEDs to blue
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(0, 0, 255)); 
  }
  pixels.show(); 
  delay(500); 

  // Example: Set all LEDs to white
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(255, 255, 255)); 
  }
  pixels.show(); 
  delay(500); 

  // Example: Set all LEDs to off
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(0, 0, 0)); 
  }
  pixels.show(); 
  delay(500);
}

Remote Decode

There is different format to see the corresponding code of each remote button in the serial monitor for me it was easier two digit values instead of using Hex value.

Code

#include <IRremote.h>
#define IR_RECEIVE_PIN A0

void setup()
{
  Serial.begin(9600); // // Establish serial communication
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
}

void loop() {
  if (IrReceiver.decode()) {
      Serial.println(IrReceiver.decodedIRData.command);
      IrReceiver.resume(); // Enable receiving of the next value
  }
}

Color Remote

Code

#include <Adafruit_NeoPixel.h>

// Define the number of LEDs
#define NUM_LEDS 10

// Define the data pin connected to the LED strip
#define PIN 9

// Create an Adafruit_NeoPixel object
Adafruit_NeoPixel pixels(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // Initialize the NeoPixel library
  serial.begin(115200)
  pixels.begin(); 
}

void loop() {
  // Example: Set all LEDs to red
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(255, 0, 0)); 
  }
  pixels.show(); // Update the LEDs
  delay(500); 

  // Example: Set all LEDs to green
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(0, 255, 0)); 
  }
  pixels.show(); 
  delay(500); 

  // Example: Set all LEDs to blue
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(0, 0, 255)); 
  }
  pixels.show(); 
  delay(500); 

  // Example: Set all LEDs to white
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(255, 255, 255)); 
  }
  pixels.show(); 
  delay(500); 

  // Example: Set all LEDs to off
  for(int i=0;i<NUM_LEDS;i++) {
    pixels.setPixelColor(i, pixels.Color(0, 0, 0)); 
  }
  pixels.show(); 
  delay(500);
}

Light sensor

Code

#include <Arduino.h>

// Define the pin connected to the light sensor's analog output
const int lightSensorPin = 4; 

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600); 
}

void loop() {
  // Read the analog value from the light sensor
  int sensorValue = analogRead(lightSensorPin); 

  // Print the sensor value to the serial monitor
  Serial.print("Light Sensor Value: ");
  Serial.println(sensorValue);

  // Optional: Map the sensor value to a range (e.g., 0-255)
  int mappedValue = map(sensorValue, 0, 1023, 0, 255); 

  // Use the mapped value to control something (e.g., an LED's brightness)
  // ...

  delay(100); // Delay to slow down the reading rate
}

Night Mode

Code

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

// Define the pin connected to the light sensor's analog output
const int lightSensorPin = A2;

// Define the pin connected to the NeoPixel data in
const int ledPin = 9; 
const int numLeds = 10; 

// Define the NeoPixel object
Adafruit_NeoPixel pixels(numLeds, ledPin, NEO_GRB + NEO_KHZ800); 

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600); 

  // Initialize the NeoPixel library
  pixels.begin();
  pixels.setBrightness(64); // Adjust brightness (0-255)
  pixels.show(); // Initialize all pixels to 'off' 
}

void loop() {
  // Read the analog value from the light sensor
  int sensorValue = analogRead(lightSensorPin); 

  // Print the sensor value to the serial monitor
  Serial.print("Light Sensor Value: ");
  Serial.println(sensorValue);

  // Check if the light sensor value is below the threshold
  if (sensorValue < 100) { 
    // Turn on all LEDs to a color (e.g., blue)
    for (int i = 0; i < numLeds; i++) {
      pixels.setPixelColor(i, pixels.Color(0, 0, 255)); // Blue
    }
    pixels.show();
  } else {
    // Turn off all LEDs
    pixels.clear();
    pixels.show();
  }

  delay(100); // Delay to slow down the reading rate
}

Speaker – Test

Code

/*macro definition of Speaker pin*/  
#define SPEAKER D1

int BassTab[]={1911,1702,1516,1431,1275,1136,1012};//bass 1~7

void setup()
{
    pinInit();
}
void loop()
{
        /*sound bass 1~7*/
    for(int note_index=0;note_index<7;note_index++)
    {
        sound(note_index);
        delay(500);
    }
}
void pinInit()
{
    pinMode(SPEAKER,OUTPUT);
    digitalWrite(SPEAKER,LOW);
}
void sound(uint8_t note_index)
{
    for(int i=0;i<100;i++)
    {
        digitalWrite(SPEAKER,HIGH);
        delayMicroseconds(BassTab[note_index]);
        digitalWrite(SPEAKER,LOW);
        delayMicroseconds(BassTab[note_index]);
    }
}

RGB LED – Speaker

Code

#include <Adafruit_NeoPixel.h>

#define SPEAKER D1
#define NUM_LEDS 10 // Number of LEDs
#define LED_PIN 9 // Digital pin connected to the NeoPixel data input

// Define colors
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define WHITE 0xFFFFFF
#define OFF 0x000000

int BassTab[]={1911,1702,1516,1431,1275,1136,1012};//bass 1~7

Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(SPEAKER, OUTPUT);
  pixels.begin();
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {
  for(int note_index=0; note_index<7; note_index++) {
    sound(note_index);
    delay(500);
  }
}

void sound(uint8_t note_index) {
  for(int i=0; i<100; i++) {
    digitalWrite(SPEAKER, HIGH);

    // Set all LEDs to the same color based on note (example)
    if (note_index == 0) { 
      for(int j=0; j<NUM_LEDS; j++) {
        pixels.setPixelColor(j, RED); 
      }
    } else if (note_index == 1) {
      for(int j=0; j<NUM_LEDS; j++) {
        pixels.setPixelColor(j, GREEN); 
      }
    } else if (note_index == 2) {
      for(int j=0; j<NUM_LEDS; j++) {
        pixels.setPixelColor(j, BLUE); 
      }
    } else if (note_index >= 3 && note_index <= 6) {
      for(int j=0; j<NUM_LEDS; j++) {
        pixels.setPixelColor(j, WHITE); 
      }
    } 
    pixels.show(); 

    delayMicroseconds(BassTab[note_index]);
    digitalWrite(SPEAKER, LOW);
    pixels.clear(); // Turn off all LEDs
    pixels.show();
    delayMicroseconds(BassTab[note_index]);
  }
}

Chair roulette

Code

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

#define BUZZER_PIN D1
#define LED_PIN 9
#define NUM_LEDS 10  // Number of LEDs (10 in this case)
#define LED_BRIGHTNESS 64 // Adjust brightness (0-255)

// Define colors
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define CYAN 0x00FFFF
#define MAGENTA 0xFF00FF
#define WHITE 0xFFFFFF
#define ORANGE 0xFFFF00

// Define note frequencies (approximate)
const int notes[] = {
  262, 262, 262, 294, 330, 330, 294, 294,
  262, 330, 294, 294, 262, 262, 262, 330,
  392, 392, 392, 440, 494, 494, 440, 440,
  392, 494, 440, 440, 392, 392, 392, 494
};

// Define note durations (milliseconds) - Adjust for tempo
const int durations[] = {
  500, 500, 500, 500, 500, 500, 500, 500,
  500, 500, 500, 500, 500, 500, 500, 500,
  500, 500, 500, 500, 500, 500, 500, 500,
  500, 500, 500, 500, 500, 500, 500, 500
};

// Define colors for each note (optional)
const uint32_t noteColors[] = {
  RED, RED, RED, ORANGE, YELLOW, YELLOW, ORANGE, ORANGE,
  RED, YELLOW, ORANGE, ORANGE, RED, RED, RED, YELLOW,
  GREEN, GREEN, GREEN, CYAN, WHITE, WHITE, CYAN, CYAN,
  GREEN, WHITE, CYAN, CYAN, GREEN, GREEN, GREEN, WHITE
};

Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
volatile bool isPlaying = true; // Flag to control playback state

void setIsPlaying(bool state) {
  isPlaying = state;
}

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  pixels.begin();
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {
  playBabyShark();
  delay(1000); // Pause between songs
}

void playBabyShark() {
  for (int i = 0; i < sizeof(notes) / sizeof(notes[0]); i++) {
    if (!isPlaying) {
      break; // Exit the loop if playback is paused
    }
    tone(BUZZER_PIN, notes[i], durations[i]);

    // Set all LEDs to the same color based on the current note
    for (int j = 0; j < NUM_LEDS; j++) {
      pixels.setPixelColor(j, noteColors[i]);
    }
    pixels.show();

    delay(durations[i]);
    pixels.clear(); // Turn off LEDs
    pixels.show();

    // Add a random pause after every 10th note
    if (i % 15 == 14) {
      int random_pause = random(4000, 10000);
      delay(random_pause);
    }
  }
}

Happy Birthday 2U

Dowload Library (https://gist.github.com/mikeputnam/2820675 )

Code

#include "pitches.h"
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

#define BUZZER_PIN D1
#define LED_PIN D9
#define NUM_LEDS 10  // Number of LEDs (10 in this case)
#define LED_BRIGHTNESS 64 // Adjust brightness (0-255)
// Define colors
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define CYAN 0x00FFFF
#define MAGENTA 0xFF00FF
#define WHITE 0xFFFFFF
#define ORANGE 0xFFFF00

int melody[] = {
  NOTE_C4, NOTE_C4, 
  NOTE_D4, NOTE_C4, NOTE_F4,
  NOTE_E4, NOTE_C4, NOTE_C4, 
  NOTE_D4, NOTE_C4, NOTE_G4,
  NOTE_F4, NOTE_C4, NOTE_C4,

  NOTE_C5, NOTE_A4, NOTE_F4, 
  NOTE_E4, NOTE_D4, NOTE_AS4, NOTE_AS4,
  NOTE_A4, NOTE_F4, NOTE_G4,
  NOTE_F4
};

int durations[] = {
  4, 8, 
  4, 4, 4,
  2, 4, 8, 
  4, 4, 4,
  2, 4, 8,

  4, 4, 4, 
  4, 4, 4, 8,
  4, 4, 4,
  2
};

// Define colors for each note (optional)
const uint32_t noteColors[] = {
  RED, YELLOW, 
  CYAN, ORANGE, WHITE,
  GREEN, BLUE, MAGENTA, 
  WHITE, CYAN, RED,
  BLUE, GREEN, RED,

  RED, ORANGE, WHITE, 
  CYAN, CYAN, GREEN, BLUE,
  YELLOW, MAGENTA, MAGENTA,
  YELLOW
};

Adafruit_NeoPixel strips(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  strips.begin();
  strips.setBrightness(LED_BRIGHTNESS); // Set brightness
  strips.show(); // Initialize all pixels to 'off'
}

void loop() {
  int size = sizeof(durations) / sizeof(int);

  for (int note = 0; note < size; note++) {
    //to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int duration = 1000 / durations[note];

    // Play the note
    tone(BUZZER_PIN, melody[note], duration);

    // Set the LED color based on the note (if defined)
    if (note < sizeof(noteColors) / sizeof(noteColors[0])) {
      strips.setPixelColor(note % NUM_LEDS, noteColors[note]); 
    } else {
      // If no color defined, set to default (e.g., white)
      strips.setPixelColor(note % NUM_LEDS, WHITE); 
    }

    // **Crucial change: Turn on ALL LEDs with the current note's color**
    for (int i = 0; i < NUM_LEDS; i++) { 
      strips.setPixelColor(i, noteColors[note]); 
    }

    strips.show();

    //to distinguish the notes, set a minimum time between them.
    //the note's duration + 30% seems to work well:
    int pauseBetweenNotes = duration * 1.30;
    delay(pauseBetweenNotes);

    //stop the tone playing:
    noTone(BUZZER_PIN);

    // Clear the LEDs
    strips.clear(); 
    strips.show(); 
  }
}

Pink Panther 1 by 1

Code

#include "pitches.h"
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

#define BUZZER_PIN D1
#define LED_PIN 9
#define NUM_LEDS 10  // Number of LEDs (10 in this case)
#define LED_BRIGHTNESS 64 // Adjust brightness (0-255)

// Define colors
#define MAGENTA 0xFF00FF
#define WHITE 0xFFFFFF

int melody[] = {
  REST, REST, REST, NOTE_DS4, 
  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_E4, NOTE_G4, NOTE_B4, 
  NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, 
  NOTE_E4, REST, REST, NOTE_DS4,

  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_G4, NOTE_B4, NOTE_E5,
  NOTE_DS5, 
  NOTE_D5, REST, REST, NOTE_DS4, 
  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_E4, NOTE_G4, NOTE_B4, 

  NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, 
  NOTE_E4, REST,
  REST, NOTE_E5, NOTE_D5, NOTE_B4, NOTE_A4, NOTE_G4, NOTE_E4,
  NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, 
  NOTE_G4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_E4
};

int durations[] = {
  2, 4, 8, 8, 
  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 
  2, 16, 16, 16, 16, 
  2, 4, 8, 4,

  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8,
  1, 
  2, 4, 8, 8, 
  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 

  2, 16, 16, 16, 16, 
  4, 4,
  4, 8, 8, 8, 8, 8, 8,
  16, 8, 16, 8, 16, 8, 16, 8, 
  16, 16, 16, 16, 16, 2
};

// Define colors for each note (optional)
const uint32_t noteColors[] = {
  WHITE, WHITE, WHITE, MAGENTA, 
  MAGENTA, WHITE, MAGENTA, MAGENTA, WHITE, MAGENTA,
  MAGENTA, MAGENTA, MAGENTA, WHITE, WHITE, MAGENTA, MAGENTA, WHITE, 
  WHITE, WHITE, MAGENTA, WHITE, MAGENTA, 
  MAGENTA, WHITE, WHITE, MAGENTA,

  MAGENTA, WHITE, WHITE, MAGENTA, WHITE, MAGENTA,
  WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, MAGENTA,
  MAGENTA, 
  MAGENTA, WHITE, WHITE, WHITE, 
  WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
  WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, 

  MAGENTA, MAGENTA, MAGENTA, MAGENTA, WHITE, 
  WHITE, WHITE,
  WHITE, MAGENTA, MAGENTA, MAGENTA, WHITE, WHITE, MAGENTA,
  MAGENTA, MAGENTA, MAGENTA, MAGENTA, WHITE, WHITE, WHITE, WHITE, 
  MAGENTA, MAGENTA, MAGENTA, WHITE, WHITE, WHITE
};

Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  pixels.begin();
  pixels.setBrightness(LED_BRIGHTNESS); // Set brightness
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {
  int size = sizeof(durations) / sizeof(int);

  for (int note = 0; note < size; note++) {
    //to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int duration = 1000 / durations[note];

    // Play the note
    tone(BUZZER_PIN, melody[note], duration);

    // Set the LED color based on the note (if defined)
    if (note < sizeof(noteColors) / sizeof(noteColors[0])) {
      pixels.setPixelColor(note % NUM_LEDS, noteColors[note]); 
    } else {
      // If no color defined, set to default (e.g., white)
      pixels.setPixelColor(note % NUM_LEDS, WHITE); 
    }

    pixels.show();

    //to distinguish the notes, set a minimum time between them.
    //the note's duration + 30% seems to work well:
    int pauseBetweenNotes = duration * 1.30;
    delay(pauseBetweenNotes);

    //stop the tone playing:
    noTone(BUZZER_PIN);

    // Clear the LEDs
    pixels.clear(); 
    pixels.show(); 
  }
}

Pink Panther Full LED

Code

#include "pitches.h"
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

#define BUZZER_PIN D1
#define LED_PIN 9
#define NUM_LEDS 10  // Number of LEDs (10 in this case)
#define LED_BRIGHTNESS 64 // Adjust brightness (0-255)

// Define colors
#define MAGENTA 0xFF00FF
#define WHITE 0xFFFFFF

int melody[] = {
  REST, REST, REST, NOTE_DS4, 
  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_E4, NOTE_G4, NOTE_B4, 
  NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, 
  NOTE_E4, REST, REST, NOTE_DS4,

  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_G4, NOTE_B4, NOTE_E5,
  NOTE_DS5, 
  NOTE_D5, REST, REST, NOTE_DS4, 
  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_E4, NOTE_G4, NOTE_B4, 

  NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, 
  NOTE_E4, REST,
  REST, NOTE_E5, NOTE_D5, NOTE_B4, NOTE_A4, NOTE_G4, NOTE_E4,
  NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, 
  NOTE_G4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_E4
};

int durations[] = {
  2, 4, 8, 8, 
  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 
  2, 16, 16, 16, 16, 
  2, 4, 8, 4,

  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8,
  1, 
  2, 4, 8, 8, 
  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 

  2, 16, 16, 16, 16, 
  4, 4,
  4, 8, 8, 8, 8, 8, 8,
  16, 8, 16, 8, 16, 8, 16, 8, 
  16, 16, 16, 16, 16, 2
};

// Define colors for each note (optional)
const uint32_t noteColors[] = {
  WHITE, MAGENTA, WHITE, MAGENTA, 
  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA,
  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, 
  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, 
  MAGENTA, WHITE, MAGENTA, WHITE,

  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE,
  WHITE,MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA,
  WHITE, 
  WHITE, MAGENTA, WHITE, MAGENTA, 
  WHITE, MAGENTA, WHITE,MAGENTA, WHITE, MAGENTA,
  WHITE, MAGENTA, WHITE,MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, 

  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, 
  MAGENTA, WHITE,
  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA,
  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, 
  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA
};

Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  pixels.begin();
  pixels.setBrightness(LED_BRIGHTNESS); // Set brightness
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {
  int size = sizeof(durations) / sizeof(int);

  for (int note = 0; note < size; note++) {
    //to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int duration = 1000 / durations[note];

    // Play the note
    tone(BUZZER_PIN, melody[note], duration);

    // Set the LED color based on the note (if defined)
    if (note < sizeof(noteColors) / sizeof(noteColors[0])) {
      pixels.setPixelColor(note % NUM_LEDS, noteColors[note]); 
    } else {
      // If no color defined, set to default (e.g., white)
      pixels.setPixelColor(note % NUM_LEDS, WHITE); 
    }

    // **Crucial change: Turn on ALL LEDs with the current note's color**
    for (int i = 0; i < NUM_LEDS; i++) { 
      pixels.setPixelColor(i, noteColors[note]); 
    }

    pixels.show();

    //to distinguish the notes, set a minimum time between them.
    //the note's duration + 30% seems to work well:
    int pauseBetweenNotes = duration * 1.30;
    delay(pauseBetweenNotes);

    //stop the tone playing:
    noTone(BUZZER_PIN);

    // Clear the LEDs
    pixels.clear(); 
    pixels.show(); 
  }
}

Mario Bros

Code

#include "pitches.h"
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

#define BUZZER_PIN D1
#define LED_PIN D9
#define NUM_LEDS 10  // Number of LEDs (10 in this case)
#define LED_BRIGHTNESS 64 // Adjust brightness (0-255)
// Define colors
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define CYAN 0x00FFFF
#define MAGENTA 0xFF00FF
#define WHITE 0xFFFFFF
#define ORANGE 0xFFFF00

int melody[] = {
  NOTE_E5, NOTE_E5, REST, NOTE_E5, REST, NOTE_C5, NOTE_E5,
  NOTE_G5, REST, NOTE_G4, REST, 
  NOTE_C5, NOTE_G4, REST, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5,NOTE_C5, NOTE_D5, NOTE_B4,
  NOTE_C5, NOTE_G4, REST, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5,NOTE_C5, NOTE_D5, NOTE_B4,

  REST, NOTE_G5, NOTE_FS5, NOTE_F5, NOTE_DS5, NOTE_E5,
  REST, NOTE_GS4, NOTE_A4, NOTE_C4, REST, NOTE_A4, NOTE_C5, NOTE_D5,
  REST, NOTE_DS5, REST, NOTE_D5,
  NOTE_C5, REST,

  REST, NOTE_G5, NOTE_FS5, NOTE_F5, NOTE_DS5, NOTE_E5,
  REST, NOTE_GS4, NOTE_A4, NOTE_C4, REST, NOTE_A4, NOTE_C5, NOTE_D5,
  REST, NOTE_DS5, REST, NOTE_D5,
  NOTE_C5, REST,

  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5,
  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,

  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5, NOTE_E5,
  REST, 
  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5,
  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_E5, REST, NOTE_E5, REST, NOTE_C5, NOTE_E5,
  NOTE_G5, REST, NOTE_G4, REST, 
  NOTE_C5, NOTE_G4, REST, NOTE_E4,

  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5, NOTE_C5, NOTE_D5, NOTE_B4,

  NOTE_C5, NOTE_G4, REST, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5, NOTE_C5, NOTE_D5, NOTE_B4,

  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_D5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_G5, NOTE_F5,

  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_B4, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_E4, NOTE_E4, NOTE_C4,

  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_D5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_G5, NOTE_F5,

  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_B4, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_E4, NOTE_E4, NOTE_C4,
  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5, NOTE_E5,
  REST,

  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5,
  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_E5, REST, NOTE_E5, REST, NOTE_C5, NOTE_E5,
  NOTE_G5, REST, NOTE_G4, REST, 
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_D5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_G5, NOTE_F5,

  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_B4, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_E4, NOTE_E4, NOTE_C4,

  // Game over sound
  NOTE_C5, NOTE_G4, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_A4, NOTE_GS4, NOTE_AS4, NOTE_GS4,
  NOTE_G4, NOTE_D4, NOTE_E4
};

int durations[] = {
  8, 8, 8, 8, 8, 8, 8,
  4, 4, 8, 4, 
  4, 8, 4, 4,
  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4,8, 8, 4,
  4, 8, 4, 4,
  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4,8, 8, 4,


  4, 8, 8, 8, 4, 8,
  8, 8, 8, 8, 8, 8, 8, 8,
  4, 4, 8, 4,
  2, 2,

  4, 8, 8, 8, 4, 8,
  8, 8, 8, 8, 8, 8, 8, 8,
  4, 4, 8, 4,
  2, 2,

  8, 4, 8, 8, 8, 4,
  8, 4, 8, 2,

  8, 4, 8, 8, 8, 8, 8,
  1, 
  8, 4, 8, 8, 8, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8, 4,
  4, 4, 4, 4, 
  4, 8, 4, 4,

  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4, 8, 8, 4,

  4, 8, 4, 4,
  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4, 8, 8, 4,

  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8,

  8, 4, 8, 2,
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8,
  8, 4, 8, 2,

  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8,

  8, 4, 8, 2,
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8, 8,
  1,

  8, 4, 8, 8, 8, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8, 4,
  4, 4, 4, 4, 
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8,

  8, 4, 8, 2,
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8,
  8, 4, 8, 2,

  //game over sound
  4, 4, 4,
  8, 8, 8, 8, 8, 8,
  8, 8, 2
};

// Define colors for each note (optional)
const uint32_t noteColors[] = {
  WHITE, BLUE, YELLOW, MAGENTA, GREEN, CYAN,WHITE ,
  RED, GREEN, BLUE, YELLOW, 
  CYAN, ORANGE, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE,YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA,WHITE, ORANGE, RED,


  GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW,

  CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED,

  GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,

  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN,
  BLUE, 
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN,
  MAGENTA, WHITE, ORANGE, RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE, 
  RED, GREEN, BLUE, YELLOW,

  CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN, BLUE,

  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN, MAGENTA,

  WHITE, ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE, YELLOW, CYAN,

  MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW,

  CYAN, MAGENTA, WHITE, ORANGE, RED,
  BLUE, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN,

  BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE, YELLOW, CYAN,
  MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, MAGENTA, WHITE, ORANGE, RED,
  GREEN,

  BLUE, YELLOW, CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, 
  ORANGE, RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,

  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN,

  //game over sound
  MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED

};

Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  pixels.begin();
  pixels.setBrightness(LED_BRIGHTNESS); // Set brightness
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {
  int size = sizeof(durations) / sizeof(int);

  for (int note = 0; note < size; note++) {
    //to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int duration = 1000 / durations[note];

    // Play the note
    tone(BUZZER_PIN, melody[note], duration);

    // Set the LED color based on the note (if defined)
    if (note < sizeof(noteColors) / sizeof(noteColors[0])) {
      pixels.setPixelColor(note % NUM_LEDS, noteColors[note]); 
    } else {
      // If no color defined, set to default (e.g., white)
      pixels.setPixelColor(note % NUM_LEDS, WHITE); 
    }

    // **Crucial change: Turn on ALL LEDs with the current note's color**
    for (int i = 0; i < NUM_LEDS; i++) { 
      pixels.setPixelColor(i, noteColors[note]); 
    }

    pixels.show();

    //to distinguish the notes, set a minimum time between them.
    //the note's duration + 30% seems to work well:
    int pauseBetweenNotes = duration * 1.30;
    delay(pauseBetweenNotes);

    //stop the tone playing:
    noTone(BUZZER_PIN);

    // Clear the LEDs
    pixels.clear(); 
    pixels.show(); 
  }
}

Final Code

#include <IRremote.h> // Assuming you're using the standard IRremote library
#include "pitches.h"
#include <Adafruit_NeoPixel.h>

// Define pins
const int IR_RECEIVE_PIN = A0; // Pin connected to the IR receiver
const int lightSensorPin = A2; // Analog pin connected to the light sensor

// Define the number of LEDs
#define NUM_LEDS 260
#define BUZZER_PIN D1
// Define the data pin connected to the LED strip
#define PIN 9
#define LED_BRIGHTNESS 64 // Adjust brightness (0-255)

// Define colors
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define CYAN 0x00FFFF
#define MAGENTA 0xFF00FF
#define WHITE 0xFFFFFF
#define ORANGE 0xFFFF00

// Define note frequencies (approximate)
const int notes[] = {
  262, 262, 262, 294, 330, 330, 294, 294,
  262, 330, 294, 294, 262, 262, 262, 330,
  392, 392, 392, 440, 494, 494, 440, 440,
  392, 494, 440, 440, 392, 392, 392, 494
};

// Define note durations (milliseconds) - Adjust for tempo
const int durations[] = {
  500, 500, 500, 500, 500, 500, 500, 500,
  500, 500, 500, 500, 500, 500, 500, 500,
  500, 500, 500, 500, 500, 500, 500, 500,
  500, 500, 500, 500, 500, 500, 500, 500
};

// Define colors for each note (optional)
const uint32_t noteColors[] = {
  RED, RED, RED, ORANGE, YELLOW, YELLOW, ORANGE, ORANGE,
  RED, YELLOW, ORANGE, ORANGE, RED, RED, RED, YELLOW,
  GREEN, GREEN, GREEN, CYAN, WHITE, WHITE, CYAN, CYAN,
  GREEN, WHITE, CYAN, CYAN, GREEN, GREEN, GREEN, WHITE
};

int melody[] = {
  REST, REST, REST, NOTE_DS4, 
  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_E4, NOTE_G4, NOTE_B4, 
  NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, 
  NOTE_E4, REST, REST, NOTE_DS4,

  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_G4, NOTE_B4, NOTE_E5,
  NOTE_DS5, 
  NOTE_D5, REST, REST, NOTE_DS4, 
  NOTE_E4, REST, NOTE_FS4, NOTE_G4, REST, NOTE_DS4,
  NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_E4, NOTE_G4, NOTE_B4, 

  NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, 
  NOTE_E4, REST,
  REST, NOTE_E5, NOTE_D5, NOTE_B4, NOTE_A4, NOTE_G4, NOTE_E4,
  NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_AS4, NOTE_A4, 
  NOTE_G4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_E4
};

int durations1[] = {
  2, 4, 8, 8, 
  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 
  2, 16, 16, 16, 16, 
  2, 4, 8, 4,

  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8,
  1, 
  2, 4, 8, 8, 
  4, 8, 8, 4, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 

  2, 16, 16, 16, 16, 
  4, 4,
  4, 8, 8, 8, 8, 8, 8,
  16, 8, 16, 8, 16, 8, 16, 8, 
  16, 16, 16, 16, 16, 2
};

// Define colors for each note (optional)
const uint32_t noteColors1[] = {
  WHITE, MAGENTA, WHITE, MAGENTA, 
  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA,
  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, 
  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, 
  MAGENTA, WHITE, MAGENTA, WHITE,

  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE,
  WHITE,MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA,
  WHITE, 
  WHITE, MAGENTA, WHITE, MAGENTA, 
  WHITE, MAGENTA, WHITE,MAGENTA, WHITE, MAGENTA,
  WHITE, MAGENTA, WHITE,MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, 

  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, 
  MAGENTA, WHITE,
  MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA,
  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA, 
  WHITE, MAGENTA, WHITE, MAGENTA, WHITE, MAGENTA
};

int melody2[] = {
  NOTE_E5, NOTE_E5, REST, NOTE_E5, REST, NOTE_C5, NOTE_E5,
  NOTE_G5, REST, NOTE_G4, REST, 
  NOTE_C5, NOTE_G4, REST, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5,NOTE_C5, NOTE_D5, NOTE_B4,
  NOTE_C5, NOTE_G4, REST, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5,NOTE_C5, NOTE_D5, NOTE_B4,

  REST, NOTE_G5, NOTE_FS5, NOTE_F5, NOTE_DS5, NOTE_E5,
  REST, NOTE_GS4, NOTE_A4, NOTE_C4, REST, NOTE_A4, NOTE_C5, NOTE_D5,
  REST, NOTE_DS5, REST, NOTE_D5,
  NOTE_C5, REST,

  REST, NOTE_G5, NOTE_FS5, NOTE_F5, NOTE_DS5, NOTE_E5,
  REST, NOTE_GS4, NOTE_A4, NOTE_C4, REST, NOTE_A4, NOTE_C5, NOTE_D5,
  REST, NOTE_DS5, REST, NOTE_D5,
  NOTE_C5, REST,

  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5,
  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,

  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5, NOTE_E5,
  REST, 
  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5,
  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_E5, REST, NOTE_E5, REST, NOTE_C5, NOTE_E5,
  NOTE_G5, REST, NOTE_G4, REST, 
  NOTE_C5, NOTE_G4, REST, NOTE_E4,

  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5, NOTE_C5, NOTE_D5, NOTE_B4,

  NOTE_C5, NOTE_G4, REST, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_AS4, NOTE_A4,
  NOTE_G4, NOTE_E5, NOTE_G5, NOTE_A5, NOTE_F5, NOTE_G5,
  REST, NOTE_E5, NOTE_C5, NOTE_D5, NOTE_B4,

  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_D5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_G5, NOTE_F5,

  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_B4, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_E4, NOTE_E4, NOTE_C4,

  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_D5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_G5, NOTE_F5,

  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_B4, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_E4, NOTE_E4, NOTE_C4,
  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5, NOTE_E5,
  REST,

  NOTE_C5, NOTE_C5, NOTE_C5, REST, NOTE_C5, NOTE_D5,
  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_E5, REST, NOTE_E5, REST, NOTE_C5, NOTE_E5,
  NOTE_G5, REST, NOTE_G4, REST, 
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_D5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_G5, NOTE_F5,

  NOTE_E5, NOTE_C5, NOTE_A4, NOTE_G4,
  NOTE_E5, NOTE_C5, NOTE_G4, REST, NOTE_GS4,
  NOTE_A4, NOTE_F5, NOTE_F5, NOTE_A4,
  NOTE_B4, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_E4, NOTE_E4, NOTE_C4,

  // Game over sound
  NOTE_C5, NOTE_G4, NOTE_E4,
  NOTE_A4, NOTE_B4, NOTE_A4, NOTE_GS4, NOTE_AS4, NOTE_GS4,
  NOTE_G4, NOTE_D4, NOTE_E4
};

int durations2[] = {
  8, 8, 8, 8, 8, 8, 8,
  4, 4, 8, 4, 
  4, 8, 4, 4,
  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4,8, 8, 4,
  4, 8, 4, 4,
  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4,8, 8, 4,


  4, 8, 8, 8, 4, 8,
  8, 8, 8, 8, 8, 8, 8, 8,
  4, 4, 8, 4,
  2, 2,

  4, 8, 8, 8, 4, 8,
  8, 8, 8, 8, 8, 8, 8, 8,
  4, 4, 8, 4,
  2, 2,

  8, 4, 8, 8, 8, 4,
  8, 4, 8, 2,

  8, 4, 8, 8, 8, 8, 8,
  1, 
  8, 4, 8, 8, 8, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8, 4,
  4, 4, 4, 4, 
  4, 8, 4, 4,

  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4, 8, 8, 4,

  4, 8, 4, 4,
  4, 4, 8, 4,
  8, 8, 8, 4, 8, 8,
  8, 4, 8, 8, 4,

  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8,

  8, 4, 8, 2,
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8,
  8, 4, 8, 2,

  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8,

  8, 4, 8, 2,
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8, 8,
  1,

  8, 4, 8, 8, 8, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8, 4,
  4, 4, 4, 4, 
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 8, 8, 8, 8, 8,

  8, 4, 8, 2,
  8, 4, 8, 4, 4,
  8, 4, 8, 2,
  8, 4, 8, 8, 8, 8,
  8, 4, 8, 2,

  //game over sound
  4, 4, 4,
  8, 8, 8, 8, 8, 8,
  8, 8, 2
};

// Define colors for each note (optional)
const uint32_t noteColors2[] = {
  WHITE, BLUE, YELLOW, MAGENTA, GREEN, CYAN,WHITE ,
  RED, GREEN, BLUE, YELLOW, 
  CYAN, ORANGE, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE,YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA,WHITE, ORANGE, RED,


  GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW,

  CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED,

  GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,

  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN,
  BLUE, 
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN,
  MAGENTA, WHITE, ORANGE, RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE, 
  RED, GREEN, BLUE, YELLOW,

  CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN, BLUE,

  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN, MAGENTA,

  WHITE, ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE, YELLOW, CYAN,

  MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW,

  CYAN, MAGENTA, WHITE, ORANGE, RED,
  BLUE, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN,

  BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE, YELLOW, CYAN,
  MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, MAGENTA, WHITE, ORANGE, RED,
  GREEN,

  BLUE, YELLOW, CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, 
  ORANGE, RED, GREEN, BLUE, YELLOW,
  CYAN, MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,

  WHITE, ORANGE, RED, GREEN,
  BLUE, YELLOW, CYAN, MAGENTA, WHITE,
  ORANGE, RED, GREEN, BLUE,
  YELLOW, CYAN, MAGENTA, WHITE, ORANGE, RED,
  GREEN, BLUE, YELLOW, CYAN,

  //game over sound
  MAGENTA, WHITE, ORANGE,
  RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA,
  WHITE, ORANGE, RED

};

int melody3[] = {
  NOTE_C4, NOTE_C4, 
  NOTE_D4, NOTE_C4, NOTE_F4,
  NOTE_E4, NOTE_C4, NOTE_C4, 
  NOTE_D4, NOTE_C4, NOTE_G4,
  NOTE_F4, NOTE_C4, NOTE_C4,

  NOTE_C5, NOTE_A4, NOTE_F4, 
  NOTE_E4, NOTE_D4, NOTE_AS4, NOTE_AS4,
  NOTE_A4, NOTE_F4, NOTE_G4,
  NOTE_F4
};

int durations3[] = {
  4, 8, 
  4, 4, 4,
  2, 4, 8, 
  4, 4, 4,
  2, 4, 8,

  4, 4, 4, 
  4, 4, 4, 8,
  4, 4, 4,
  2
};

// Define colors for each note (optional)
const uint32_t noteColors3[] = {
  RED, YELLOW, 
  CYAN, ORANGE, WHITE,
  GREEN, BLUE, MAGENTA, 
  WHITE, CYAN, RED,
  BLUE, GREEN, RED,

  RED, ORANGE, WHITE, 
  CYAN, CYAN, GREEN, BLUE,
  YELLOW, MAGENTA, MAGENTA,
  YELLOW
};

IRrecv irrecv(IR_RECEIVE_PIN);
decode_results results;

volatile bool isPlaying = true; // Flag to control playback state
void setIsPlaying(bool state) {
  isPlaying = state;
}

bool playOnce = true; // Flag to control loop repetition

// NeoPixel setup
Adafruit_NeoPixel pixels(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
  // Assuming IrReceiver.begin(IR_RECEIVE_PIN); is the correct initialization for your IR receiver library
  IrReceiver.begin(IR_RECEIVE_PIN); 
  pixels.begin();
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  if (IrReceiver.decode()) {
    Serial.println(IrReceiver.decodedIRData.command);

    if (IrReceiver.decodedIRData.command == 12) { // Replace with your actual remote codes
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(255, 0, 0));
      }
      pixels.show(); // Update the LEDs
      delay(500);
    } else if (IrReceiver.decodedIRData.command == 8) { // '4' purple
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(75,0,130));
      }
      pixels.show();
      delay(500);
    } else if (IrReceiver.decodedIRData.command == 28) { // '5' sky-blue
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(135,206, 235));
      }
      pixels.show();
      delay(500);
    } else if (IrReceiver.decodedIRData.command == 90) { // '6' fire-orange
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(255,21,0));
      }
      pixels.show();
      delay(500);
    } else if (IrReceiver.decodedIRData.command == 24) {
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(0, 255, 0));
      }
      pixels.show();
      delay(500);
    } else if (IrReceiver.decodedIRData.command == 94 ) {
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(255, 255, 0));
      }
      pixels.show();
      delay(500);
    } else if (IrReceiver.decodedIRData.command == 67) {
      for (int i = 0; i < sizeof(notes) / sizeof(notes[0]); i++) {
        if (!isPlaying) {
          break; // Exit the loop if playback is paused
        }
        tone(BUZZER_PIN, notes[i], durations[i]);

        // Set all LEDs to the same color based on the current note
        for (int j = 0; j < NUM_LEDS; j++) {
          pixels.setPixelColor(j, noteColors[i]);
        }
        pixels.show();

        delay(durations[i]);
        pixels.clear(); // Turn off LEDs
        pixels.show();

        // Add a random pause after every 10th note
        if (i % 15 == 14) {
          int random_pause = random(4000, 10000);
          delay(random_pause);
        }
      }
      for (int i = 0; i < sizeof(notes) / sizeof(notes[0]); i++) {
        if (!isPlaying) {
          break; // Exit the loop if playback is paused
        }
        tone(BUZZER_PIN, notes[i], durations[i]);

        // Set all LEDs to the same color based on the current note
        for (int j = 0; j < NUM_LEDS; j++) {
          pixels.setPixelColor(j, noteColors[i]);
        }
        pixels.show();

        delay(durations[i]);
        pixels.clear(); // Turn off LEDs
        pixels.show();

        // Add a random pause after every 10th note
        if (i % 15 == 14) {
          int random_pause = random(4000, 10000);
          delay(random_pause);
        }
      }

      for (int i = 0; i < sizeof(notes) / sizeof(notes[0]); i++) {
        if (!isPlaying) {
          break; // Exit the loop if playback is paused
        }
        tone(BUZZER_PIN, notes[i], durations[i]);

        // Set all LEDs to the same color based on the current note
        for (int j = 0; j < NUM_LEDS; j++) {
          pixels.setPixelColor(j, noteColors[i]);
        }
        pixels.show();

        delay(durations[i]);
        pixels.clear(); // Turn off LEDs
        pixels.show();

        // Add a random pause after every 10th note
        if (i % 15 == 14) {
          int random_pause = random(4000, 10000);
          delay(random_pause);
        }
      }

      for (int i = 0; i < sizeof(notes) / sizeof(notes[0]); i++) {
        if (!isPlaying) {
          break; // Exit the loop if playback is paused
        }
        tone(BUZZER_PIN, notes[i], durations[i]);

        // Set all LEDs to the same color based on the current note
        for (int j = 0; j < NUM_LEDS; j++) {
          pixels.setPixelColor(j, noteColors[i]);
        }
        pixels.show();

        delay(durations[i]);
        pixels.clear(); // Turn off LEDs
        pixels.show();

        // Add a random pause after every 10th note
        if (i % 15 == 14) {
          int random_pause = random(4000, 10000);
          delay(random_pause);
        }
      }
      pixels.show();
      pixels.clear(); // Turn off LEDs
      delay(1000); // Delay to slow down the reading rate

    } else if (IrReceiver.decodedIRData.command == 9) { // Corrected position
      // Read the analog value from the light sensor
      int sensorValue = analogRead(lightSensorPin);

      // Print the sensor value to the serial monitor
      Serial.print("Light Sensor Value: ");
      Serial.println(sensorValue);

      // Check if the light sensor value is below the threshold
      if (sensorValue < 500) {
        // Turn on all LEDs to a color (e.g., blue)
        for (int i = 0; i < NUM_LEDS; i++) {
          pixels.setPixelColor(i, pixels.Color(255, 211, 172)); // Peachy
        }
      } else {
        // Turn off all LEDs
        pixels.clear();
      }

      pixels.show();
      delay(100); // Delay to slow down the reading rate
    } 
    // Add the reset functionality
    else if (IrReceiver.decodedIRData.command == 69) { // 'CH-' TURN OFF System no lights 
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(0, 0, 0));
      }
      pixels.show();
      delay(500);
    }
    else if (IrReceiver.decodedIRData.command == 82) { // '8' Pink Panther
       int size = sizeof(durations1) / sizeof(int);

  for (int note = 0; note < size; note++) {
    //to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int duration = 1000 / durations1[note];

    // Play the note
    tone(BUZZER_PIN, melody[note], duration);

    // Set the LED color based on the note (if defined)
    if (note < sizeof(noteColors1) / sizeof(noteColors1[0])) {
      pixels.setPixelColor(note % NUM_LEDS, noteColors1[note]); 
    } else {
      // If no color defined, set to default (e.g., white)
      pixels.setPixelColor(note % NUM_LEDS, WHITE); 
    }

    // **Crucial change: Turn on ALL LEDs with the current note's color**
    for (int i = 0; i < NUM_LEDS; i++) { 
      pixels.setPixelColor(i, noteColors1[note]); 
    }

    pixels.show();

    //to distinguish the notes, set a minimum time between them.
    //the note's duration + 30% seems to work well:
    int pauseBetweenNotes = duration * 1.30;
    delay(pauseBetweenNotes);

    //stop the tone playing:
    noTone(BUZZER_PIN);

    // Clear the LEDs
    pixels.clear(); 
    pixels.show(); 
  }
}
    }
    else if (IrReceiver.decodedIRData.command == 74) { // '9' Mario Bro theme song

       int size = sizeof(durations2) / sizeof(int);

  for (int note = 0; note < size; note++) {
    //to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int duration = 1000 / durations2[note];

    // Play the note
    tone(BUZZER_PIN, melody2[note], duration);

    // Set the LED color based on the note (if defined)
    if (note < sizeof(noteColors1) / sizeof(noteColors2[0])) {
      pixels.setPixelColor(note % NUM_LEDS, noteColors2[note]); 
    } else {
      // If no color defined, set to default (e.g., white)
      pixels.setPixelColor(note % NUM_LEDS, WHITE); 
    }

    // **Crucial change: Turn on ALL LEDs with the current note's color**
    for (int i = 0; i < NUM_LEDS; i++) { 
      pixels.setPixelColor(i, noteColors2[note]); 
    }

    pixels.show();

    //to distinguish the notes, set a minimum time between them.
    //the note's duration + 30% seems to work well:
    int pauseBetweenNotes = duration * 1.30;
    delay(pauseBetweenNotes);

    //stop the tone playing:
    noTone(BUZZER_PIN);

    // Clear the LEDs
    pixels.clear(); 
    pixels.show(); 
    IrReceiver.decodedIRData.command = 0;

  }
     playOnce = false;
   } else if (IrReceiver.decodedIRData.command == 66) { // '7' HBD
   if (playOnce) {
       int size = sizeof(durations3) / sizeof(int);

  for (int note = 0; note < size; note++) {
    //to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int duration = 1000 / durations3[note];

    // Play the note
    tone(BUZZER_PIN, melody3[note], duration);

    // Set the LED color based on the note (if defined)
    if (note < sizeof(noteColors1) / sizeof(noteColors3[0])) {
      pixels.setPixelColor(note % NUM_LEDS, noteColors3[note]); 
    } else {
      // If no color defined, set to default (e.g., white)
      pixels.setPixelColor(note % NUM_LEDS, WHITE); 
    }

    // **Crucial change: Turn on ALL LEDs with the current note's color**
    for (int i = 0; i < NUM_LEDS; i++) { 
      pixels.setPixelColor(i, noteColors3[note]); 
    }

    pixels.show();

    //to distinguish the notes, set a minimum time between them.
    //the note's duration + 30% seems to work well:
    int pauseBetweenNotes = duration * 1.30;
    delay(pauseBetweenNotes);

    //stop the tone playing:
    noTone(BUZZER_PIN);

    // Clear the LEDs
    pixels.clear(); 
    pixels.show(); 
    IrReceiver.decodedIRData.command = 0;
  }

     } else if (IrReceiver.decodedIRData.command == 13 ) { //100+ DONT PRESS SYSTEM FAILURE
      for (int i = 0; i < NUM_LEDS; i++) {
        pixels.setPixelColor(i, pixels.Color(255, 255, 0));
      }
      pixels.show();
      delay(500);
      IrReceiver.decodedIRData.command = 0;
     }
   }

    irrecv.resume(); // Receive the next value
 }

Issues

Meshing all codes into one final code check the pin numbers and test few times to check if there is any error, for me I got an issue of when choosing Mario Bros remote button it stay in loop therefore in the end of the loop I put a value = 0 which is invalid value in my remote control it force the system to exit the loop and waits for new value input  

Using Fusion 360

First design (first draft – for general idea and sketches)

I created a first draft design to see what the design will look like and what are my limitation in design if I will use the CNC machine to do it. One of the limitation is I can’t pocket holed and all through holes in different sides for the same piece without flipping the work piece.

Create a prototype

In this step I tried to create a physical design to first-hand experience any issues and see any chance to overcome any problem and solve it directly

Sketch

In this stage using accurate measurement sketch your design in cardboard with actual measurement or a scale down version to test stability and design efficiency.

Cut

Cut your desired pieces from the cardboard using cutter and align with a ruler for accurate cut.

Assemble

In this stage use any sticking tool such as glue gun and tape have the desired structure.

Final Assembly

This final assembly try to reflect on shape regarding stability and functionality such as if the electric components can be placed neatly or not.

Review - Table correction after prototype

Make the stand X shape no +

Cancel electric bottom floor

Add 4 inner walls and gap 5 cm (use thinner walls if possible such as frosted acrylic)

Cancel finger joints and add push joint for the side (to make it more kid-friendly) / for the Top is not possible (do full material thickness cut)

For legs use 3X Thickness (3 plate glue together)

Increase leg height by 5 cm (from 22 cm to 27 cm)

4 wall (all through)

Joint height = plywood material thickness

Joint depth (extrude) = acrylic material thickness

To activate any system use Remote control

In Remote ‘1’ is to shut off any system working

Add LED strips that change colors

Add light sensor that enable specific color at night that help sleep.

Add speaker and add kids my favorite kid’s music such as Mario and pink panther.

Add chair roulette mode for kids to have fun

Add special occasion’s music such as Happy Birthday.

I find the project title after reviewing the prototype which is Kids friendly table

Market + dimensions

Go to the market to check for the prices and dimension of the extra components of the project to adjust your fusion 360 design to market availability

Mirror- 6 mm

Glass 8mm

Film 1 mm

Glass thickness 8+1 = 9mm

Frosted acrylic 3 mm

Wood – MDF 12 mm

Fusion 360 Final Design

Click here to download .DXF file

Table- Bottom

Sketch

Extrude 1 – outer frame

Extrude 2 – create holes

Rotational Pattern 1

Extrude 3 – create holes

Rectangular pattern

Upper_Lower_Side_panel_Joint_spacing = table_dimesion_square_GLASS + ( 2 * Electronic_border ) - ( table_edge_fixed_joint_space * 2 ) - plywood_joint_width

Rotational Pattern 2

Extrude 3 – electric holes + acrylic fitting holes

First leg

Sketch

Extrude – 3 * material thickness

2nd Leg

Sketch

Extrude – 3* material thickness

Side Panel – Longer

Sketch

Extrude 1 – main frame

Extrude 2 – finger joints

Rectangular Pattern

Mirror

Extrude – Create Pocket

Rectangular Pattern 2

Mirror 2

Side Panel – shorter

Sketch

Extrude 1 – main frame

Extrude 2 – upper finger joints

Rectangular pattern 1

Rectangular pattern 2

Distance = Side_panel_height - ( ( 2 * 25 ) * 1 mm ) - plywood_joint_width

Extrude 3 – lower finger joint

Rectangular pattern 3

Mirror

Extrude 4 – cut light sensor hole

Top Panel

Sketch – copy the bottom panel + add square offset

Extrude 1 – Main frame

Extrude 2 – cut Acrylic holes

Rotational Pattern 1

Extrude 2 – Cut Finger Joints holes

Rectangular pattern

Rotational Pattern 2

Extrude 3 – Cut Glass panel thickness

While cutting I made the total thickness = 8 to have a stronger foundation to carry the heavy glass panel. + I forget to cut acrylic cut corners to ensure a better fit.

1st Acrylic inner walls

Extrude 1 – Main Frame

Extrude 2 – Upper finger joints

Rectangular Pattern 1

Extrude 3 – Side Finger Joints

Rectangular Pattern 2

Mirror 1

Mirror 2

2nd Acrylic inner walls

Sketch

Extrude 1 – main frame + side finger joint

Mirror 1

Extrude 2 – Top finger joints

Rectangular Pattern

Mirror 2

Layout

This step is crucial to organize your design parts into cutting machine such as CNC and laser cutter, it help us minimize material waste.

CNC - Cutting

Acrylic testing

Second cut is a must after taking measurement using Vernier caliber I noticed that 3.05 mm height is good but the width need to increase by 1.5 mm , therefore new tolerances need to be add in design

First wood panel

Cutting dide panels and legs + check the fitting

Second wood panel

The design is bit complex regarding the holes of acrylic are small they need smaller drill bit so changing to 3 mm drill bit for the holes first and after that you change it to 6 mm drill bit to other part of the designed part + check fitting with side panels

Fitting Problem

As you can see for the second wood panel I forget to add dog-bone therefore I had problem in the width of the finger joint similar situation to the acrylic fitting by thankfully the thickness is fine just I need to cut all finger joint by 1 -2 cm to make sure it fit easily.

Finishing Process

Filing – remove the tabs and smoothing sharp edges

Sanding

This process to create a rougher surface to ensure more paint to be captured

Painting

This time I tried to paint without primer, I noticed that more paint is needed to get good color coating or layer. I put that in mind and I got extra cans of paints just in case.

Apperence – final touches

I add blackboard paper wrap to the side panels which enables children to express their artistic side and ceativity.

Laser Cutter

Cut Acrylic to Bedsize

Acrylic is hard material when cutting shrapnel get all over the place it is crucial to wear protective gear while using table saw.

Upload design + Cutting

I uploaded two times first was for frosted acrylic (1st acrylic inner wall) and the second time was for red acrylic (2nd acrylic inner walls).

Check Fit

This is crucial to be perfect because I have few material in hand , if I want to buy from the market it takes 3-5 working days from Awal plastics and all the fitting test I did will be a waste of time thankfully my estimation and testing were successful.

Apperence – final touches

Peel off Factory cover and add kids friendly design weather it a laser cut design or a store bought stickers that are colorful and act as a wallpaper.

Final Assembly

Electronics

The fitting of sensor holes and wiring were ideal in the final design nothing is visible except for external sensors such light sensor and speaker were the glued to the bottom panel.

Possible Issues

Glass weight

I was in doubt if the glass holder was strong enough to carry the glass panel, therefore I asked a furniture shop to confirm my suspicion but thankfully according to their expert opinion is not an issue.

Reflection issue

I went to advertisement shop to see if they have one-way mirror film unfortunately they don’t have it, he told me to find it in building tint window shops. I tried to contact 10 shops from automotive shops to building shops until I finally reached to a shop located in Bahrain Mall, the tint was expensive were it cost 15 B.D for 40 cm X 40 cm glass panel. More expensive than glass panel and mirror which cost me around 7 B.D.

Installation issue

Speaker got crashed while assembling therefore I used a buzzer which worked perfectly since they are both using the same code.

Hero shot

Future Improvements

Don’t forget dog-bone.

Fitting in design are different in installation therefore increase tolerance to ensure smother and better fit.

The choice of material can be better to ensure lighter weight such as using PVC and more kid friendly material instead of using mirror I can use acrylic mirror.

Power bank get disconnected every 5 minutes so using lithium batteries connected with current controller is a better option to ensure that electricity always in system.

Manual built-in button in table.

Add smart night mode where if the table is beside the bed and I move across it light ON to close it press the table button.

Wake up system as the time turn to ‘6:00 a.m or every day at Fajer aAhan the light turns up and a buzzer comes ON to stop the system Click table button.


Last update: January 23, 2025