Light and Interactivity

Making a Candle

A candle is romantic, it’s warm, it has magic that makes people wanna stare at, I remember when I was studying Hatha yoga, there was a type of meditation called Trataka, we shut down all the light and sitting on the floor in a circle, and staring at the candle in the middle, try not to blink, try not to think, until the tears filled up our eyes.

Having something like the light of candle to stare at is a rather relaxing thing, it is not too boring, because the tiny light is flickering and dancing around organically, while in the same time, it is not too active, to a degree that you got tired easily by just watching for a while. This kind of balance is something that makes candle light so intriguing.

If try to look at it clearly, the middle part is the brightest with a pure white color, (though during middle school science that I learned that actually the middle part is actually the coldest in the candle light) the top is warm and usually came with a orange light.

So what I want to do in the code is to make the candle has:

  1. warm color
  2. flickering effect
  3. constantly changing

The color in the video is so different from the one that actually looks in real life. The white is so much cooler in the video.

Here is my code below, I get the original code from Tom’s github.

What I did is that to make the pixel in the middle to fading in fading out using Sin(), so it has this very natural fading, the other 6 pixels are redish and flickering.(one using Interval.h, others using random()), actually I think I’m not using Interval.h correctly.

I’m using the RGBW pixel but somehow in the code the sequence is GRBW??

Special thanks to Hayley who helped me understanding the code!!

Assignment 2 from Light and Interacitivty

Siman Li Feb.7 2017

There is one quesiton in the end


#include <Adafruit_NeoPixel.h>
#include "Interval.h"
Interval ledTimer; // set a timer for the LED

const int neoPixelPin = 5; // control pin
const int numPixels = 7; // number of pixels
int level = 255; // the white LED color for the whole strip
int difference = 1; // the fading difference in each loop
//breathing effect
int count = 0;
const long interval = 10;
long lastUpdate;

//try to use Interval
int blinkState = HIGH; // the LED state, HIGH or LOW

// set up strip:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, neoPixelPin, NEO_RGBW + NEO_KHZ800);

void setup() {
 strip.begin(); // initialize pixel strip
 strip.clear(); // turn all LEDs off
 pinMode(0, OUTPUT);
 ledTimer.setInterval(blink, 200);


void loop() {
 // middle pixel
 strip.setPixelColor(0, 0, random(150,190), random(20,50), level);// set the color for this pixel
 //other pixels
 for (int pixel = 1; pixel < numPixels; pixel++) { //for every pixels G,R,B,white
strip.setPixelColor(6, 0, 0, 0, random(40,100)); 
strip.setPixelColor(5, 0, 150, 0, 255); 
strip.setPixelColor(5, 0, 200, 0, level); 
strip.setPixelColor(4, 0, 150, 0, random(160,200));
strip.setPixelColor(2, 0, 0, 0, level);
strip.setPixelColor(1, 0, 0, 0, level);}; // refresh the strip

// delay(500);
 ledTimer.check(); // check the LED timer

// }

 if ((millis() - lastUpdate) > interval) //time to update
 lastUpdate = millis();
 count ++;
 float rad = DEG_TO_RAD * count;
 level = constrain((sin(rad) * 128) + 128, 80, 200);
 if (count > 360) {
 count = 0;
void blink() {
 blinkState = !blinkState;
strip.setPixelColor(3, 0, 150, 0, blinkState); 
//this is may not the right way to use blinkState, for it is only range 0 or one????

One thought on “Making a Candle

  1. You’re using interval correctly if you want a 200ms delay between calls to blink(). In the code, blinkState is alternately 0 or 1, so you’re setting the blue to 0 or 1 every 200ms. It’s probably not visible. You might want to fade the hint of blue in every 200ms or so instead; was that your intention?

    Some neoPixels are RGBW and some are RGBW. That’s why it’s good to run a test before you get started, to check the sequence.

Leave a Reply

Your email address will not be published. Required fields are marked *