So, im working on a new project, a small game, involving a cube,

So, im working on a new project, a small game, involving a cube, with leds on each side.

i have some code working to a degree, and id like a few pointers!

http://pastebin.com/VStxtCfh

i have an accelerometer giving me some xyz data, that ive mapped to 0-255, and used so if you turn the cube, whichever side is pointing up, the led fades in. this works fine.

my coding is rudimentary, and whilst ive tidied it up a bit, i have a lot of variables that ive used / experimented / deleted… ill sort this out later!

i could do with some help;

the main thing i have an issue with is when the cube is stationary (flag is state 12) for 5 seconds (breatheTime) the led will breathe (fade in and out). now the breathecode i stole from http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
and is;
float breathe = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
and this on its own works fine, but in the code i get a weird flickering, like its pulses in brightness to peak and then back down to 0.

also, the way i have the leds setup is a bit rudimentary, and theres probably a better way of doing it.

all the leds are lit all the time, but the code makes just 1 at full brightness.

  for (int i = 0; i < 2; i++) {
  leds[i]    =   CHSV( ledColour, 255, ba); // back
  leds[i+2]  =   CHSV( ledColour, 255, le); // left
  leds[i+4]  =   CHSV( ledColour, 255, fr); // front
  leds[i+6]  =   CHSV( ledColour, 255, ri); // right
  leds[i+8]  =   CHSV( ledColour, 255, to); // top
  leds[i+10] =   CHSV( ledColour, 255, bo); // bottom
FastLED.show();

i know this looks clumsy, and if it looks clumsy, it probably is!

(just to clarify, each side of the cube has 2 leds (and in the final product it will either have 4 leds, or 9 depending on power usage and cool factor, so some room for alteration is required!)

thanks!

Move FastLED.setBrightness() and FastLED.show() outside the for loop.

Ah ha! Doing this ive realised where im going wrong.

Im trying to multilply breathe*the current side

And then im changing the fastledbrightness(breathe)

So im trying to set the same led twice.

So ive got rid of the fastledbrightness, and changed the breathe formula so that it outputs a figure between 0-1 as opposed to 0-255.

Finally!

Its not as smooth as id like it, but i can work on that!

Thanks

Here’s some “breathing” fun I made last year to inspire you further. Looking forward to a video.

Also for fun, here’s what your breath function looks like graphed:

Fun to play with variables to quickly get a visual.

POW just stole your pulseSpeed*millis()… thats a really nice nugget of info! :slight_smile:

ill experiment with the hue changing!