Hans Uwe Neve
Published © GPL3+

NightLight for my kids

A colorful light in the dark.

IntermediateShowcase (no instructions)962
NightLight for my kids

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
×1
ws2812b
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
ISP Programmer

Story

Read more

Schematics

Schematic

Code

NightLight.ino

C/C++
paste into Arduino IDE
#define Blue  0x0000FF
#define Brown 0xA52A2A
#define Green  0x008000
#define Orange  0xFFA500
#define Purple  0x800080
#define Red  0xFF0000
#define Violet  0xEE82EE
#define Yellow  0xFFFF00
#define Indigo  0x4B0082
#define Black 0x000000
#define White 0xffffff

#include <Adafruit_NeoPixel.h>
//#include <avr/power.h>

#define PIN 3
#define PIXELS 1
#define LIGHTLEVEL 255

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_GRB + NEO_KHZ800);


void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop()
{
  rainbow(50);
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((j) & 255));
    }
    
    if(analogRead(3) > LIGHTLEVEL) return;
  
    strip.show();
    delay(wait);
        
  }
}

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

Credits

Hans Uwe Neve

Hans Uwe Neve

1 project • 3 followers
Thanks to Adafruit.

Comments