STEMpedia
Published © CC BY

DIY Lightsaber

In this project you'll learn how to make your very own lightsaber using evive and other objects around around you.

IntermediateFull instructions provided3 hours1,090
DIY Lightsaber

Things used in this project

Hardware components

evive
STEMpedia evive
×1
LilyPad Rainbow LED (strip of 7 colors)
SparkFun LilyPad Rainbow LED (strip of 7 colors)
×1
Thick Cardboard
×1
Glue Gun and Glue Sticks
×1
Butter Paper
×1
Foam Sheet
×1
Acrylic Bar
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing Diagram for connecting RGB LED light

Code

Different Pattern of RGB for the Lightsaber

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

#define neo_pixel_led_pin  3
#define button 38
#define number_of_neo_pixel_leds 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(number_of_neo_pixel_leds,neo_pixel_led_pin, NEO_GRB + NEO_KHZ800);

unsigned char temp=0;
unsigned char temp2 =0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
 strip.begin();
 strip.show(); 

 tft_init(INITR_GREENTAB);
 tft.setRotation(1);
 tft.fillScreen(ST7735_BLACK);

  tft.setCursor(25,10);
  tft.setTextSize(2);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.print("STEMpedia");

   tft.setCursor(15,50);
  tft.setTextSize(2);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.print("LIGHTSABER ");

  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.setCursor(0,95);
  tft.setTextSize(1.8);
  tft.print("FOR MORE INFORMATION VISIT");
  tft.setCursor(30,110);
  tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
  tft.print("thestempedia.com");
}

void loop() {
  // put your main code here, to run repeatedly:
  
  while(1)
  {
    
       if(digitalRead(button)==HIGH)
         {
          delay(1000);
           break;
         }
       if(temp2==0)
         {
             for(unsigned int i=0;i<number_of_neo_pixel_leds;i++)
                 {
                     strip.setPixelColor(i,strip.Color(0,210,0));
                 }
             strip.show();
             temp2=1;
            
         }
 
   }
   temp2=0;
    while(1)
  {
    
       if(digitalRead(button)==HIGH)
         {
          delay(1000);
           break;
         }
       if(temp2==0)
         {
             for(unsigned int i=0;i<number_of_neo_pixel_leds;i++)
                 {
                     strip.setPixelColor(i,strip.Color(210,0,0));
                 }
             strip.show();
             temp2=1;
            
         }
 
   }
   temp2=0;
    while(1)
  {
    
       if(digitalRead(button)==HIGH)
         {
          delay(1000);
           break;
         }
       if(temp2==0)
         {
             for(unsigned int i=0;i<number_of_neo_pixel_leds;i++)
                 {
                     strip.setPixelColor(i,strip.Color(0,0,210));
                 }
             strip.show();
             temp2=1;
            
         }
 
   }
   Clear();
   temp=0;
   while(1)
   {
    if(temp==1)
    {
       delay(1000);
      break;
    }
    rainbow(20);
     
   }
    Clear();
   temp=0;
   while(1)
   {
    if(temp==1)
    {
       delay(1000);
      break;
    }
    rainbowCycle(20);
   }
    Clear();
   temp=0;
   while(1)
   {
    if(temp==1)
    {
       delay(1000);
      break;
    }
    theaterChase(strip.Color(210,0,0), 20);
   }
  
    Clear();
   temp=0;
   while(1)
   {
    if(temp==1)
    {
       delay(1000);
      break;
    }
    theaterChase(strip.Color(0,210,0), 20);
   }
    Clear();
   temp=0;
   while(1)
   {
    if(temp==1)
    {
      delay(1000);
      break;
    }
    theaterChase(strip.Color(0,0,210), 20);
   }
   temp=0;
   Clear();
   temp2=0;
   

}

void rainbow(uint8_t wait)
       {
         uint16_t i, j;
         if(temp!=1)
           {
             for(j=0; j<256; j++)
                 {
                   if(temp!=1)
                       {
                           for(i=0; i<strip.numPixels(); i++)
                               {
                                 strip.setPixelColor(i, Wheel((i+j) & 255));
                               }
                           strip.show();
                           delay_ms(wait);
                        }
                  }
            }  
      }

void rainbowCycle(uint8_t wait)
     {
        uint16_t i, j;
        if(temp!=1)
           {
              for(j=0; j<256*5; j++)
                  {
                     if(temp!=1)
                        {
                            for(i=0; i< strip.numPixels(); i++) 
                                  {
                                     strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
                                  }
                            strip.show();
                            delay_ms(wait);
                        }
   
                   }
           }
 
     }

void theaterChase(uint32_t c, uint8_t wait)
      {
         if(temp!=1)
            {
              for (int j=0; j<10; j++)
                  { 
                    if(temp!=1)
                           {
                               for (int q=0; q < 3; q++)
                                    {
                                        for (uint16_t i=0; i < strip.numPixels(); i=i+3)
                                             {
                                                strip.setPixelColor(i+q, c);    //turn every third pixel on
                                             }
                                        strip.show();
                                        delay_ms(wait);
          
                                        for (uint16_t i=0; i < strip.numPixels(); i=i+3)
                                             {
                                                 strip.setPixelColor(i+q, 0);        //turn every third pixel off
                                             }
                                    }
                           }
                   }
           }
 
     }

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

void delay_ms(uint8_t Time)
{
  for(unsigned int i=0;i<Time;i++)
  {
    delay(1);
    check_pressed();
  }
}

void check_pressed()
{
  if(digitalRead(button)==HIGH)
  {
    temp=1;
  }
}
void Clear()
{
  for(unsigned int i=0;i<number_of_neo_pixel_leds;i++)
  {
    strip.setPixelColor(i,strip.Color(0,0,0));
  }
  strip.show();
}

evive Library

C/C++
No preview (download only).

Credits

STEMpedia

STEMpedia

42 projects • 169 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.

Comments