c++ - Neopixel arduino fading from colour to colour using a Sparkcore -



c++ - Neopixel arduino fading from colour to colour using a Sparkcore -

this question follow question asked here answered.

i have next function:

moticolor startcolor; moticolor endcolor; void setup() { // begin strip. strip.begin(); // initialize pixels 'off'. strip.show(); serial1.begin(9600); startcolor = moticolor(0, 0, 0); endcolor = moticolor(0, 0, 0); } void loop () { } int tinkersetcolour(string command) { strip.show(); int commaindex = command.indexof(','); int secondcommaindex = command.indexof(',', commaindex+1); int lastcommaindex = command.lastindexof(','); string reddish = command.substring(0, commaindex); string grn = command.substring(commaindex+1, secondcommaindex); string blu = command.substring(lastcommaindex+1); startcolor = moticolor(red.toint(), grn.toint(), blu.toint()); int16_t reddiff = endcolor.getr() - startcolor.getr(); int16_t greendiff = endcolor.getg() - startcolor.getg(); int16_t bluediff = endcolor.getb() - startcolor.getb(); int16_t _delay = 500; int16_t duration = 3500; int16_t steps = duration / _delay; int16_t redvalue, greenvalue, bluevalue; (int16_t = steps; >= 0; i--) { redvalue = (int16_t)startcolor.getr() + (reddiff * / steps); greenvalue = (int16_t)startcolor.getg() + (greendiff * / steps); bluevalue = (int16_t)startcolor.getb() + (bluediff * / steps); sprintf(rgbstring, "%i,%i,%i", redvalue, greenvalue, bluevalue); spark.publish("rgb", rgbstring); (uint16_t = 0; < strip.numpixels(); i++) { strip.setpixelcolor(i, strip.color(redvalue, greenvalue, bluevalue)); } delay(_delay); } delay(_delay); (uint16_t = 0; < strip.numpixels(); i++) { strip.setpixelcolor(i, strip.color(endcolor.getr(), endcolor.getg(), endcolor.getb())); } delay(_delay); endcolor = moticolor(startcolor.getr(), startcolor.getg(), startcolor.getb()); homecoming 1; }

i seeing published results correctly:

this off (0,0,0) -> reddish (255,0,0) -> greenish (0,255,0).

it works fine when publish results web console via spark.publish() event, actual neopixel led's don't fade colour colour expected. alter colour colour instead of fading nicely between themselves.

i'm wondering i'm going wrong or how can improve code see fading in real time.

you have phone call strip.show() in loop, so:

for (int16_t = steps; >= 0; i--) { redvalue = (int16_t)startcolor.getr() + (reddiff * / steps); greenvalue = (int16_t)startcolor.getg() + (greendiff * / steps); bluevalue = (int16_t)startcolor.getb() + (bluediff * / steps); sprintf(rgbstring, "%i,%i,%i", redvalue, greenvalue, bluevalue); spark.publish("rgb", rgbstring); (uint16_t = 0; < strip.numpixels(); i++) { strip.setpixelcolor(i, strip.color(redvalue, greenvalue, bluevalue)); } // !!! without this, you'll see result next time phone call // tinkersetcolor() !!! strip.show(); delay(_delay); }

to understand what's happening, can @ neopixel library source. you'll see strip.setpixelcolor() stores rgb value in memory (think of drawing buffer, can update whole strip @ once, makes sense if @ how controller chips work). calling strip.show() causes routine force values out each pixel in serial run.

c++ arduino rgb led

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -