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!!

```/*
Candle
Assignment 2 from Light and Interacitivty

Siman Li Feb.7 2017

There is one quesiton in the end

*/

#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:

void setup() {
strip.begin(); // initialize pixel strip
strip.clear(); // turn all LEDs off
pinMode(0, OUTPUT);
Serial.begin(9600);

}

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);}
strip.show(); // refresh the strip

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

Serial.println(level);
// }

delay(50);
if ((millis() - lastUpdate) > interval) //time to update
{
lastUpdate = millis();
count ++;
level = constrain((sin(rad) * 128) + 128, 80, 200);
if (count > 360) {
count = 0;
}
}
}