Colorful LED Cube

by AZDelivery in Circuits > Arduino

16 Views, 1 Favorites, 0 Comments

Colorful LED Cube

bunter-led-wurfel-led-ring-per-gyroskop-und-esp32-steuern-785048.gif

A LED cube with an automatic color change is to be built. To realize this, the LED ring, the gyroscope, and a D1 Mini ESP32 are used. With this project, the color of the LED ring can be controlled by gyroscope and ESP32 depending on position. In the video, this is clearly shown using a 3D printed cube that lights up in a different color with each rotation.

Supplies

Print the Box

Downloads


3D printing templates at Thing

sketch Ledwuerfel.ino

Downloads

Wiring

connection.png

Program Code

/*
   ___ _____        ____       ___                      
  /   /__  /       / __ \___  / (_)   _____  _______  __
 / /| | / / ______/ / / / _ \/ / / | / / _ \/ ___/ / / /
/ ___ |/ /_/_____/ /_/ /  __/ / /| |/ /  __/ /  / /_/ /
/_/  |_/____/    /_____/\___/_/_/ |___/\___/_/   \__, /  
                                               /____/   
Product, the data sheet, and Pinout at:
 https://www.az-delivery.de/

Project: GY-521 MPU-6050 3-axis gyroscope sensor and RGB LED ring
Date: 10/2022

*/
#include <Arduino.H>
#include <Adafruit_mppu6050.H>
#include <Adafruit_sensor.H>
#include <Wire.H>
#include <fast leather.H>

Adafruit_mppu6050 MPU;

float Xtreshhold = 0.0;
float Ytreshhold = 0.0;
float Ztreshold = 0.0;

#define Num_Leds 12
#define Data_pin 25

CRGB LEDs[Num_Leds];

void Settreshholds()
{
 sensors_event_t A, G, tempo;
 MPU.Geete event(&A, &G, &tempo);
 Xtreshhold = (A.acceleration.X);
 Ytreshhold = (A.acceleration.y);
 Ztreshold = (A.acceleration.Z);
}

void set up(void)
{
 Serial.Begin(115200);
 IF (!MPU.Begin())
 {
   Serial.print("Failed to Find MPU6050 CHIP");
   while (true)
   {
   }
 }
 Fast leather.Addleds<WS2812, Data_pin, Grb>(LEDs, Num_Leds);
}

void loop()
{

 Settreshholds();

 IF (Ztreshold <= -4.5) // down
 {
   for (intimately I = 0; I < Num_Leds; I++)
   {
     LEDs[I].STRGB(255, 0, 0); // red
   }
 }

 Else IF (Ztreshold >= 4.5) // up
 {
   for (intimately I = 0; I < Num_Leds; I++)
   {
     LEDs[I].STRGB(0, 255, 0); // Green
   }
 }

 Else IF (Xtreshhold <= -4.5) // Left
 {
   for (intimately I = 0; I < Num_Leds; I++)
   {
     LEDs[I].STRGB(0, 0, 255); // Blue
   }
 }

 Else IF (Xtreshhold >= 4.5) // right
 {
   for (intimately I = 0; I < Num_Leds; I++)
   {
     LEDs[I].STRGB(255, 255, 0); // yellow
   }
 }

 Else IF (Ytreshhold <= -4.5) // front
 {

   for (intimately I = 0; I < Num_Leds; I++)
   {
     LEDs[I].STRGB(0, 255, 255); // cyan
   }
 }

 Fast leather.setbrightness(20);
 Fast leather.show();
}