Alvaro Morales
Published © GPL3+

Bed light neopixel

Create a bed light with neopixel and an encoder to select the color and britghness

BeginnerFull instructions provided2 hours55
Bed light neopixel

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1
5V 4000mA Switching Power Supply
Digilent 5V 4000mA Switching Power Supply
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematics

Code

Encoder_neopixel.ino

Arduino
#include <Adafruit_NeoPixel.h>
#define PIN            6
#define NUMPIXELS      115  
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


 int val; 
 int encoder0PinA = 2;
 int encoder0PinB = 3;
 int encoder0Key = 4;
 int encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;
 int arcoiris;
 int r;
 int g;
 int b;
 int brillo = 5;
 int pulsador = 9;
 int i=0;
 int j;

 unsigned long timer;
 unsigned long timeroff;


 void setup() { 
   pinMode (encoder0PinA,INPUT);
   pinMode (encoder0PinB,INPUT);
   pinMode (encoder0Key, INPUT_PULLUP);
   pinMode (5, OUTPUT);
   pinMode (6, OUTPUT);
   digitalWrite (5, HIGH);
   digitalWrite (6, LOW );
   Serial.begin (9600);   
   pixels.begin(); // This initializes the NeoPixel library.
   pixels.setBrightness(10);
   Serial.println("Iniciado");
   for(i=0; i<NUMPIXELS; i++){
   pixels.setPixelColor(i, pixels.Color(0, 0, 0));
   pixels.show();}
   randomSeed(analogRead(A0)); //Seed for generating random values
//   timeroff=30000;
 } 

 void loop() {

  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
      brillo = brillo-10;
       if(brillo<5){
        brillo=5; }
       pixels.setBrightness(brillo);
       Serial.println(brillo);
      pixels.show();
    } else {
      encoder0Pos++;
      brillo = brillo+10;
       if(brillo>255){
        brillo=255; }
       pixels.setBrightness(brillo);
       Serial.println(brillo);
      pixels.show();
     }delay(10);
    }
//    Serial.print (encoder0Pos);
//    Serial.print ("/");

   encoder0PinALast = n;

  timer = millis();

   //OPCIONES PULSADORES
   if(digitalRead(encoder0Key) == LOW){
  timeroff = timer + 60000; //Strap shutdown in 1 minute
  
   pixels.clear();
    if(pulsador==0){
      Serial.println("Red");
      for(i=0; i<NUMPIXELS; i++){
      pixels.setPixelColor(i, pixels.Color(255, 0, 0));
      pixels.show();}
      delay(250);
      }

      
    if(pulsador==1){
      Serial.println("Purple");
      for(i=0; i<NUMPIXELS; i++){
      pixels.setPixelColor(i, pixels.Color(255, 0, 255));
      pixels.show();}
      delay(250);
      }

    if(pulsador==4){
      Serial.print("Random: "); 
      r=random(0,255);
      g=random(0,255);
      b=random(0,255);
      Serial.print(r);
      Serial.print(", ");
      Serial.print(g);
      Serial.print(", ");
      Serial.println(b);
          for(i=0; i<NUMPIXELS; i++){
            pixels.setPixelColor(i, pixels.Color(r, g, b));
            pixels.show();
            delay(5);
              for(j=(NUMPIXELS-i); j>i; j--){ //Efecto
                          pixels.setPixelColor(j, pixels.Color(r, g, b));
                          pixels.show();
                          delay(1);
                          pixels.setPixelColor(j, pixels.Color(0, 0, 0));
                          pixels.show();
                           }
              pixels.setPixelColor(i, pixels.Color(r, g, b));
              pixels.show();
              }
      delay(250);
   }


if(pulsador==5){
      Serial.println("Rainbow");
      for(i=0; i<NUMPIXELS; i++){
      pixels.setPixelColor(i, pixels.ColorHSV(arcoiris));
      pixels.show();
      arcoiris = map(i,0,115,0,65535);}
      delay(250);   
   }


    if(pulsador==6){
      Serial.println("White");
      for(i=0; i<NUMPIXELS; i++){
      pixels.setPixelColor(i, pixels.Color(255,255,255));
      pixels.show();} 
      delay(250);
   }



    if(pulsador==7){
      Serial.println("Off"); 
      for(i=0; i<NUMPIXELS; i++){
      pixels.setPixelColor(i, pixels.Color(0, 0, 0));
      pixels.show();}
      delay(250);   
   }
   
   pulsador = pulsador+1;
   if(pulsador>7){
    pulsador=0;
   }
   
  }
   if(timeroff < timer){
//    Serial.println("Shutdown");
    for(i=0; i<NUMPIXELS; i++){
      pixels.setPixelColor(i, pixels.Color(0, 0, 0));
      pixels.show();}
   }
//   delay(10);
 }

Credits

Alvaro Morales

Alvaro Morales

1 project • 0 followers

Comments

Add projectSign up / Login