Stingraykncw
Published © GPL3+

Full Color LED Miniature Lantern

How to make a miniature lantern by using a light bulb bottle, PVC pipes and Digispark.

BeginnerShowcase (no instructions)2 hours1,879
Full Color LED Miniature Lantern

Things used in this project

Hardware components

DigiSpark
DigiSpark
×1
Full color led PL9823-F5
×1
Coin Cell Battery CR2032
Coin Cell Battery CR2032
×2
6V battery case with slide switch
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Capacitor 10 pF
Capacitor 10 pF
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

Code

Code

Arduino
//Miniatule LED lantern
//Copyright Stingraykncw, 2018

#include <Adafruit_NeoPixel.h>

// RGBLED outpin
#define RGBLED_OUTPIN    0
// RGBLED on Arduino
#define NUMRGBLED        1

#define NUMBUF 20
#define NUMBUFD 10

Adafruit_NeoPixel RGBLED = Adafruit_NeoPixel(NUMRGBLED, RGBLED_OUTPIN, NEO_RGB + NEO_KHZ800);

int red = 0;
int green = 85;
int blue = 170;
int stpr = 1;
int stpg = 1;
int stpb = 1;
int sel = 0;
int jo = 0;
int oldjo = 0;
int btnsum = 0;
int btnpin = 2;
int btnstate[NUMBUF];
int i = 0;
int akaru = 1;

void setup()
{
     RGBLED.begin() ;                   
     RGBLED.setBrightness(50) ;         
     RGBLED.setPixelColor(0, 150,0,0) ; 
     RGBLED.show() ;                    
     pinMode(btnpin, INPUT);
     for (i = 0; i <= NUMBUF; i++) btnstate[i] = 0;
}
void loop()
{
   btnstate[0] = digitalRead(btnpin);
   for(i = NUMBUF; i > 0; i--)
      btnstate[i] = btnstate[i-1];
   btnsum = 0;
   for(i = 0; i <= NUMBUF; i++)
      btnsum = btnsum + btnstate[i];
      
   if (btnstate[0] == HIGH){
     if (btnsum < NUMBUF * 0.3){
        switch(sel){
           case 0:
              red = 255;
              green = 0;
              blue = 0;
              jo = 1;
              sel++;
              break;
           case 1:
              red = 0;
              green = 255;
              blue = 0;
              jo = 1;
              sel++;
              break;
           case 2:
              red = 0;
              green = 0;
              blue = 255;
              jo = 1;
              sel++;
              break;
           case 3:
              red = 255;
              green = 255;
              blue = 0;
              jo = 1;
              sel++;
              break;
           case 4:
              red = 0;
              green = 255;
              blue = 255;
              jo = 1;
              sel++;
              break;
           case 5:
              red = 255;
              green = 0;
              blue = 255;
              jo = 1;
              sel = 0;
              break;
        }
     }
     else if (btnsum < NUMBUF * 0.9 && btnsum >= NUMBUF * 0.3){
        if (akaru == 1){
           akaru = 4;
        }
        else{
           akaru = 1;
        }
        
        RGBLED.setBrightness(akaru * 50) ;  
     }
     else{
        if(oldjo == 1){
           red = 0;
           green = 85;
           blue = 170;
        }        
        red = red + stpr;
        green = green + stpg;
        blue = blue + stpb;
        if (red % 255 == 0) stpr = stpr * -1;
        if (green % 255 == 0) stpg = stpg * -1;
        if (blue % 255 == 0) stpb = stpb * -1;
        jo = 0;
     }
   }
   RGBLED.setPixelColor(0, red, green, blue);
   RGBLED.show() ;
   oldjo = jo;
   delay(10);
}

Credits

Stingraykncw

Stingraykncw

2 projects • 0 followers

Comments