-->
Page 1 of 2

Neo pixel Commands

PostPosted: Tue May 10, 2016 7:13 am
by drhaitch
The neo() command works well, but if you want to update a series of neopixels you can see it happening which can be annoying. This happens as each time you use neo() is updates all the pixels, for if you want to update 20 pixels, it will update 20 times which is quite slow.

I have added a neoq () command to Eval file. Its exactly like the neo command but doesnt update the pixel.
then when I use the neo() command next all the pixels are updated.
This is about 200% or more faster when updating a lot of pixels and appears to be instantaneous.

I dont know if neoq() is a good name for a command however, maybe neoset() ?.
Also would be nice to have a neoshift() command that will shift all the neopixels that amount.
ie neoshift(-1) would move them all down 1. This would allow much faster rolling animations, which at present are not really possible.
neoshift(1) would move them up 1. neoshift(5) would move them up 5. etc.
Thanks for considering this. Im not a good enough programmer to try adding this to Github etc, :(
Hamish


----------my code- all I did was add a command name and comment out pixels->show()
else if ( fname == F("neoq") && num_args > 0 ) {
// function neo(led no, r, g, b)
if (pixels == NULL)
{
pixels = new Adafruit_NeoPixel(512, 15, NEO_GRB + NEO_KHZ800);
pixels->begin();
}
pixels->setPixelColor(args[0], pixels->Color(args[1], args[2], args[3]));
//pixels->show();
return PARSER_STRING;
}

Re: Neo pixel Commands

PostPosted: Wed May 11, 2016 7:45 am
by drhaitch
Hi MMISCOOL,
So I have learnt quite a lot about arduino programming, here is a suggested addition for the basic. This code goes in the Eval section.
neo( pixelnumber, r, g, b, hide)
Works just like the neo command, but if the last value is 1 then the neopixel color is set but not displayed.
In my tests this is about 80% faster than just setting neopixels and displaying them. It also lets you set a number of pixels then show then at once.

The second command is
neoshift( firstpixel , lastpixel , dirrection)
ie
neoshift(0,20,1)
will move all the pixels from 0 to 20 up one. This allows some nice scrolling animations with very little effort.
Dirrection is either 1 or -1




Code: Select all else if ( fname == F("neo") && num_args > 0 ) {
    // function neo(led no, r, g, b ,flag)
    // if flag == 1 then dont display neopixel, just set it in memory
    if (pixels == NULL)
    {
      pixels = new Adafruit_NeoPixel(512, 15, NEO_GRB + NEO_KHZ800);
      pixels->begin();
    }
    pixels->setPixelColor(args[0], pixels->Color(args[1], args[2], args[3]));
    if (args[4] != 1)
    {
    pixels->show();
    }
    return PARSER_STRING;
  }
   
   else if ( fname == F("neoshift") && num_args > 0 ) {
    // ****
    // neoshift(first pixel 0 -511,last pixel 0 to 511 ,direction -1 or +1)
    // *****

    //test if args[] out of range
    if (args[0] > args[1] || args[0]>511 || args[1]>511)
    {
      PrintAndWebOut(F("Neoshift error"));
      return PARSER_FALSE;
    }
    if (pixels == NULL)
    {
      pixels = new Adafruit_NeoPixel(512, 15, NEO_GRB + NEO_KHZ800);
      pixels->begin();
    }
    // move pixels
   
    if (args[2] > 0){
    //move pixels up one
    for (int zz = args[1]; zz>= args[0] ; zz--){
      uint32_t oldp = pixels->getPixelColor(zz);
      pixels->setPixelColor(zz+1,oldp);
      delay(0);
    }
    }
    else if (args[2]<0){
      // move down one
      for ( int zz = args[0]; zz <= args[1] ; zz++){
        uint32_t oldp = pixels->getPixelColor(zz);
      pixels->setPixelColor(zz-1,oldp);
      delay(0);
      }
    }
    pixels->show();
    return PARSER_STRING;
  }






here is a sample esp8266basic code for a color wheel type animation , similar to the one in the adafruit neopixel demo. Runs quite respectably fast for a basic :)
Code: Select allneocls()
for c = 0 to 2
for t = 0 to 60
if t < 20 then
r = t
g = 20 - t

goto [jump]
end if
if t>40 then
g = t - 40
b = 60 - t

goto [jump]
end if
b = t - 20
r = 40 - t

[jump]
neo(0,r,g,b,1)
neoshift(0,59,1)
if c > 0 then
neo(0,0,0,0,1)
for cc = 0 to c * 2

neoshift(0,59,1)
next cc
end if
next t
next c

end

Re: Neo pixel Commands

PostPosted: Wed Jun 01, 2016 7:27 am
by drhaitch
a video of neoshift command and setting neopixels .(Can you add this or something similar in MM?)

https://www.youtube.com/watch?v=FHp6czaJCx8&feature=youtube_gdata

Re: Neo pixel Commands

PostPosted: Wed Jun 01, 2016 5:18 pm
by Mmiscool
Thanks for the code and the video.

This function has been added to the interpreter and the docs for the 3.0 branch.