cris
Published © GPL3+

LED Stars

I made this project with stuff that I have in boxes, a project that attracts attention. Who doesn't like LEDs?

IntermediateShowcase (no instructions)24 hours58
LED Stars

Things used in this project

Hardware components

ATMega8-AU
Example
×1
IR sensor
Example
×1
8bit WS2812B LEDs Ring
Example
×1

Software apps and online services

KiCad
KiCad
Tinkercad
Autodesk Tinkercad
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Multitool, Screwdriver
Multitool, Screwdriver
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Enclosure

Sketchfab still processing.

Schematics

Circuit

Code

Code

C/C++
//added two push buttons
//mod 1 blink for a certain period of time
//mod 2 blink continuously


// include necessary libraries
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN_2            11  // DI PIN to D11
#define NUMPIXELS_2      16 // 16 LEDs, 8+8
Adafruit_NeoPixel pixels_2 = Adafruit_NeoPixel(NUMPIXELS_2, PIN_2, NEO_GRB + NEO_KHZ800);

#define PIN_3            12  // DI PIN to D12
#define NUMPIXELS_3      8 // 8 LEDs
Adafruit_NeoPixel pixels_3 = Adafruit_NeoPixel(NUMPIXELS_3, PIN_3, NEO_GRB + NEO_KHZ800);

#define PIN_1            10  // DI PIN to 10
#define NUMPIXELS_1      12 // 12 LEDs
Adafruit_NeoPixel pixels_1 = Adafruit_NeoPixel(NUMPIXELS_1, PIN_1, NEO_GRB + NEO_KHZ800);

const int NumLights_1 = NUMPIXELS_1;
const int NumLights_2 = NUMPIXELS_2;
const int NumLights_3 = NUMPIXELS_3;

const int NumColors = 6;
const uint32_t colorList[NumColors] =
{
  Adafruit_NeoPixel::Color(36,  0,  0,  0), // Red
  Adafruit_NeoPixel::Color( 0, 36,  0,  0), // Green
  Adafruit_NeoPixel::Color( 0,  0, 36,  0), // Blue
  Adafruit_NeoPixel::Color(36, 36,  0,  0), // Yellow
  Adafruit_NeoPixel::Color(36,  0, 36,  0), // Magenta
  Adafruit_NeoPixel::Color( 0, 36, 36,  0), // Cyan
};

//buttons config
const int button1 = 5; // IR sensor
const int button2 = 6; // push button
// initial state
int button1Pressed = LOW; 
int button2Pressed = LOW;
const uint32_t debounceTime = 50;  // debounce time in milliseconds
int menu1 = 0;
int menu2 = 0;
unsigned long previousMillis = 0;
unsigned long ledMillis = 0;
int counter = 0;

void setup() {
  Serial.begin(9600);
  
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
 
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels_1.begin();
  pixels_2.begin(); // This initializes the NeoPixel library.
  pixels_3.begin();

  // initially, the LEDs are Off
  pixels_1.fill(0x000000);
  pixels_1.show();

  pixels_2.fill(0x000000);
  pixels_2.show();

  pixels_3.fill(0x000000);
  pixels_3.show();

} // end setup

void loop()
{
  unsigned long currentMillis = millis();
  static uint32_t lastMillis;

  static int colorIndexLeft = 0;
  static int colorIndexRight = 0;
  static int lightIndexLeft = NUMPIXELS_1;
  static int lightIndexRight = 0;
  static int colorIndex_2 = 0;
  static int lightIndex_2 = 0;
  static int colorIndex_3 = 0;
  static int lightIndex_3 = NumLights_3;

  bool currentButtonState1 = digitalRead(button1);     // Reads the current state of the button and saves the result in a bool
  static bool lastButtonState1;

  bool currentButtonState2 = digitalRead(button2);     // Reads the current state of the button and saves the result in a bool
  static bool lastButtonState2;                         // Holds the previous debounced state of the button

  if ((lastButtonState1 != currentButtonState1) || (lastButtonState2 != currentButtonState2)) {
    // Checks to see if the button has been pressed or released, at this point the button has not been debounced
    if (currentMillis - lastMillis >= debounceTime) {
      // Checks to see if the state of the button has been stable for at least bounceTimeout duration
      lastButtonState2 = currentButtonState2;
      lastButtonState1 = currentButtonState1;
      previousMillis = currentMillis;

      // check if you press the SET button and increase the menu1 index
      if (currentButtonState1 == button1Pressed)
      {
        menu1 = menu1 + 1;
      }
      else if (currentButtonState2 == button2Pressed)
      {
        menu2 = menu2 + 1;
      }
    }
  } // if
  else {
    lastMillis = currentMillis; // Saves the current value of millis in last millis so the debounce timer starts from current millis
  }

  if (menu1 == 1)
  {
    ledMillis = millis(); // start counting

    //Serial.println("Short event started.");
    if (ledMillis - previousMillis <= 30000) // turn on the LED for 30s
    {
      Serial.println("LED is ON for short event");
      Wsb();
    }

    if (ledMillis - previousMillis > 30000) // after 30s turn off the LED
    {
      Serial.println("LED is OFF after short event");
      pixels_1.fill(0x000000);
      pixels_1.show();

      pixels_2.fill(0x000000);
      pixels_2.show();

      pixels_3.fill(0x000000);
      pixels_3.show();

      menu1 = 0;
    }
  }

  if (menu2 == 1)
  {
    Serial.println("Long event started.");
    Wsb();
  }

  if (menu2 == 2)
  {
    Serial.println("Long event finished.");

    pixels_1.fill(0x000000);
    pixels_1.show();

    pixels_2.fill(0x000000);
    pixels_2.show();

    pixels_3.fill(0x000000);
    pixels_3.show();

    menu2 = 0;
  }

  if ((menu1 == 2) || (menu2 == 3))
  {
    if (millis() >= 500) {
      menu1 = 0;
      menu2 = 0;
    }
  }

} // end loop

// Create LEDs patterns
void Wsb()
{
  unsigned long currentWsbMillis = millis();
  static unsigned long WsbMillis = 0;
  static int colorIndexLeft = 0;
  static int colorIndexRight = 0;
  static int lightIndexLeft = NUMPIXELS_1;
  static int lightIndexRight = 0;
  static int colorIndex_2 = 0;
  static int lightIndex_2 = 0;
  static int colorIndex_3 = 0;
  static int lightIndex_3 = NumLights_3;

  if (currentWsbMillis - WsbMillis >= 300)
  {
    WsbMillis = currentWsbMillis;
    
	// Pattern No 1
	
    if (lightIndexLeft < (NUMPIXELS_1 / 2) )
    {
      lightIndexLeft = NUMPIXELS_1;
      colorIndexLeft++;
      if (colorIndexLeft >= NumColors) {
        colorIndexLeft = 0;
      }
    }

    if (lightIndexRight > (NUMPIXELS_1 / 2) )
    {
      lightIndexRight = 0;
      colorIndexRight++;
      if (colorIndexRight >= NumColors) {
        colorIndexRight = 0;
      }
    }

    if ( (lightIndexLeft == 12) | (lightIndexRight == 0 ))
    {
      pixels_1.setPixelColor(6, 0);
    }

    // Pattern No 2
    if (lightIndex_2 >= NumLights_2)
    {
      lightIndex_2 = 0;
      colorIndex_2++;
      if (colorIndex_2 >= NumColors) {
        colorIndex_2 = 0;
      }
    }
	
    // Pattern No 3
    if (lightIndex_3 < 0)
    {
      lightIndex_3 = NumLights_3 - 1;
      colorIndex_3++;
      if (colorIndex_3 >= NumColors) {
        colorIndex_3 = 0;
      }
    }

    pixels_1.setPixelColor(lightIndexLeft, colorList[colorIndexLeft]);
    pixels_1.setPixelColor(((lightIndexLeft + 1) % NUMPIXELS_1), 0);
    pixels_1.setPixelColor(lightIndexRight, colorList[colorIndexRight]);
    pixels_1.setPixelColor(((lightIndexRight - 1) % NUMPIXELS_1), 0);
    pixels_1.show();

    pixels_2.setPixelColor(lightIndex_2, colorList[colorIndex_2]);
    pixels_2.show(); // This sends the updated pixel color to the hardware.

    pixels_3.setPixelColor(lightIndex_3, colorList[colorIndex_3]);
    pixels_3.setPixelColor(((lightIndex_3 + 1) % NumLights_3), 0);
    pixels_3.show();

    lightIndex_2++;
    lightIndex_3--;
    lightIndexLeft--;
    lightIndexRight++;

  } // BIG IF

}// Wsb

Credits

cris
4 projects • 0 followers
I started with an Arduino board now I try to build homemade circuits with components mostly salvaged from scrap boards.
Contact

Comments

Please log in or sign up to comment.