Photon-Powered PC RGB Moodlight System

Today I built a neopixel RGB moodlight system and temperature monitor for my PC using a Photon, neopixel and a DS18B20

It is powered via usb and the color scheme can be reprogrammed over USB.

##Photo:

##External View:

##Internal View:

##Code:

#include "OneWire/OneWire.h"
#include "spark-dallas-temperature/spark-dallas-temperature.h"
#include "neopixel/neopixel.h"
#include "Particle.h"

SYSTEM_MODE(MANUAL);

// Init Dallas on pin digital pin D3
DallasTemperature dallas(new OneWire(D3));

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

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// Prototypes for local build, ok to leave in for Build IDE
void rainbow(uint8_t wait);
uint32_t Wheel(byte WheelPos);

void setup()
{
  RGB.control(true);
  RGB.brightness(0);
  strip.begin();
  dallas.begin();
  Serial.begin(115200);
  strip.show(); // Initialize all pixels to 'off'

    for(int i=0; i<strip.numPixels(); i++) // Start with neopixels red
    {
      strip.setPixelColor(i, strip.Color(255, 0, 0));
    }

  strip.show();
}

void loop()
{
    dallas.requestTemperatures();
    float celsius = dallas.getTempCByIndex(0);
    Serial.println(celsius);
    delay(250);
}

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((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

UPDATE:

I’ve now incorporated a DS18B20 into the project to get internal air temperature readings.

Here is the bash code to read the DS18B20:

case-temp()
{
  TEMP="$(head -1 "/dev/ttyACM0")"
  TEMP="${TEMP:: -1}"
  echo "$TEMP"
}

case-tempf()
{
  echo "$(case-temp) / 0.8 + 32.0" | bc
}

$ case-temp
28.06

$ case-tempf
67.0
3 Likes

Thanks for sharing!

1 Like