Ingo Lohs
Published © LGPL

(Colored) Light in the Dark

Transport colors and there brightness over a distance with the help of fibre optics.

BeginnerProtip1 hour562

Things used in this project

Hardware components

Photon
Particle Photon
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
it works with any light source available to you - in the simplest case a desk lamp or the internal status LED of the photon - not necessary to buy!
×1
Male/Male Jumper Wires
3 pieces for GND, VIN and Data In at D4
×1
Fibre Optics
1x Fibre Optic Wire
×1

Story

Read more

Code

Fibre Optics

C/C++
#include "neopixel.h"

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D4
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup()
{
    
  // take control of the Particle Device internal RGB LED
  RGB.control(true);
  RGB.brightness(0);
    
  // Neopixels
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  brighten_red();
    delay(1000);
  darken_red();
    delay(1000);
  brighten_green;
    delay(1000);
  darken_green();
    delay(1000);
  brighten_blue();
    delay(1000);
  darken_blue();
    delay(1000);
}

// 0 to 255
void brighten_red() {
  uint16_t i, r;

  for (r = 0; r < 255; r++) {
    //for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(2, r, 0, 0); // LED Number, R, G, B > only 1 LED with changing color red
    //}
    strip.show();
    delay(30);
  }
}

// 255 to 0
void darken_red() {
  uint16_t i, r;

  for (r = 255; r > 0; r--) {
    //for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(2, r, 0, 0);
    //}
    strip.show();
    delay(30);
  }
}

// 0 to 255
void brighten_green() {
  uint16_t i, g;

  for (g = 0; g < 255; g++) {
    //for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(2, 0, g, 0); // LED Number, R, G, B > only 1 LED with changing color green
    //}
    strip.show();
    delay(30);
  }
}

// 255 to 0
void darken_green() {
  uint16_t i, g;

  for (g = 255; g > 0; g--) {
    //for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(2, 0, g, 0);
    //}
    strip.show();
    delay(30);
  }
}

// 0 to 255
void brighten_blue() {
  uint16_t i, b;

  for (b = 0; b < 255; b++) {
    //for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(2, 0, 0, b); // LED Number, R, G, B > only 1 LED with changing color blue
    //}
    strip.show();
    delay(30);
  }
}

// 255 to 0
void darken_blue() {
  uint16_t i, b;

  for (b = 255; b > 0; b--) {
    //for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(2, 0, 0, b);
    //}
    strip.show();
    delay(30);
  }
}

Credits

Ingo Lohs

Ingo Lohs

182 projects • 194 followers
I am well over 50 years and come from the middle of Germany.

Comments