Candle on ATtiny

This week I built a candle light with an ATtiny85 running a Jewel 7 neopixels (https://www.adafruit.com/product/2858).

The project is based on the guide here for building my own circuit for the Arduino from scratch. 

http://homemadehardware.com/guides/arduino-uno-components/

And here

Making a jig for programming the ATTiny and using the Arduino to program it: http://homemadehardware.com/guides/programming-an-attiny85/ 

I am using the following in the circuit:

ATtiny85. 

Jewel 7.

Larger capacitor between 4.7-22uF (micro-farad) between power and ground. I’m using a 100uF. 

Smaller capacitor between 0.047-0.2uF (micro-farad) as close to one of the microcontroller’s power pins. Im using a 104)

The jewel is connected to pin 2 on the ATtiny85. Power and ground. 

I am not using a voltage regulator, because the adapter outputs 5V, when I put in the LM7805 to the circuit it lowered the voltage to 3.6V which is too low for the jewel to run correctly. 

Process:

I programmed the light to run from the Arduino first, as part of my Light and Interactivity class (link). 

Then used my jig to put the same code on the ATTiny.

Finally I soldered everything onto a protoboard from Adafruit.

Issues:

I ran into issues for programming the ATTiny, since I could not get the code to run properly. Its would light up some LED’s but not really run the code I had made in a  stable way. I found out that it was the neopixels library that needed to be updated. Then it ran like it should. (Thank you Alvaro!). 

Code 

This code is using 80% of the memory on the ATTiny.

I used the ColorConverter library (https://github.com/tigoe/ColorConverter)from Tom Igoe to implement the hue, saturation and intensity. 

#include <Adafruit_NeoPixel.h>
#include <ColorConverter.h>
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket

const int neoPixelPin = 2;   // control pin
const int pixelCount = 7;    // number of pixels
int change_h = 1;              // increment to change hue by
int change_mi = 1;              // increment to change hue by

// set up strip:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, neoPixelPin, NEO_GRBW + NEO_KHZ800);
ColorConverter converter;

int h = 14;         // hue
int s = 100;        // saturation
int i = 100;        // intensity
int mi = 20;

int max_h = 15;
int min_h = 13;
int min_mi = 2;
int max_mi = 100;

int counter = 0;
bool left = true;
int ran = 30;

RGBColor color;

void setup() {
  Serial.begin(9600);

  strip.begin();    // initialize pixel strip
  strip.clear();    // turn all LEDs off
  strip.show();     // update strip

  // create colors
  color = converter.HSItoRGB(h, s, i);
}

void loop() {
  /*
   * //blink
  // Set just one led
  strip.setPixelColor(0, 0, 255, 0);
  strip.show();   // update the strip
  delay(100);

  strip.clear();    // turn all LEDs off
  strip.show();   // update the strip
  delay(100);
*/

  // loop over all the pixels:
  for (int pixel = 0; pixel < pixelCount; pixel++) {

    if (left) {
      // center is blue
      if (pixel == 0) {
        //color = converter.HSItoRGB(h, s, mi);
        color = converter.HSItoRGB(208, s, 10);
      }
      // flicker a pixel
      if (pixel == 1 || pixel == 3 || pixel == 4) {
        color = converter.HSItoRGB(h, s, mi);
        Serial.println(mi);
      }
      else {
        color = converter.HSItoRGB(h, s, i);
      }
    } else {
      // center is blue
      if (pixel == 0) {
        //color = converter.HSItoRGB(h, s, mi);
        color = converter.HSItoRGB(208, s, 10);
      }
      // flicker a pixel
      if (pixel == 2 || pixel == 5 || pixel == 6) {
        color = converter.HSItoRGB(h, s, mi);
        Serial.println(mi);
      }
      else {
        color = converter.HSItoRGB(h, s, i);
      }
    }

    strip.setPixelColor(pixel, color.red, color.green, color.blue);    // set the color for this pixel
    strip.show();   // update the strip
  }
  delay(100);

  // increment hue
  h = h + change_h;
  if (h < min_h || h > max_h) {
    change_h = -change_h;
  }

  // intensity for edge pixels
  mi = mi + change_mi;
  if (mi < min_mi || mi > max_mi) {
    change_mi = -change_mi;
  }

  // random control
  counter++;
  if (counter % 30 < 1) {
    mi = 0;//random(0, min_mi);
    Serial.println("new");
    change_mi = random (1, 8);
  }
  if (counter % ran < 1) {
    left = !left;
    ran = random(5, 30);
  }
  if (counter % 100 < 1) {
    strip.clear();    // turn all LEDs off
    strip.show();   // update the strip
  }
  
}