Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
AZ-Delivery
Published © GPL3+

Colorful LED Cube

A LED cube with an automatic color change is to be built.

BeginnerWork in progress35

Things used in this project

Hardware components

GY-521 3-axis gyroscope
×1
RGB Led Ring
×1
ESP32 D1 Mini
×1
LM2596S power supply
×1
9V battery clip
×1

Story

Read more

Code

Program Code

Arduino
/*
    ___ _____        ____       ___                      
   /   /__  /       / __ \___  / (_)   _____  _______  __
  / /| | / / ______/ / / / _ \/ / / | / / _ \/ ___/ / / /
 / ___ |/ /_/_____/ /_/ /  __/ / /| |/ /  __/ /  / /_/ / 
/_/  |_/____/    /_____/\___/_/_/ |___/\___/_/   \__, /  
                                                /____/   
 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();
}

Credits

AZ-Delivery
16 projects • 3 followers
We are "AZ-Delivery - Your Expert for Microelectronics". Visit our shop with regularly new Blogs and free E-Books.
Contact

Comments

Please log in or sign up to comment.