These are chat archives for Makuna/NeoPixelBus

2nd
Jun 2015
sticilface
@sticilface
Jun 02 2015 09:29
I'll try to create a simple INO file that is not sprawling (i have many files)... in terms of libs I'm not using anything weird and wonderful. Its the EEPROMUtil that has special functions in it for handling doubles... and some other stuff...
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WifiUDP.h>
#include <PubSubClient.h>
#include <EEPROM.h>
#include <EepromUtil.h>
#include <SimpleTimer.h>

#include <ESP.h> 
#include <NeoPixelBus.h>
#include <RgbColor.h>
I do have another question.. Lets say that I want to shift pixels around, moving pixel 1 to pixel 2, 2 to 3, 3 to 4. etc.. what is the best way to do it... I guess that I could write a loop starting at the second last, and moving it and doing this for all of them, or is their a fast way to use pointers and the original array of bytes? I'm wanting to use an MSGEQ7 to create visual effects from sound.
Michael Miller
@Makuna
Jun 02 2015 16:04
A key to what you are wanting is a classic programming question. Due to the data shift is to the right, the key is starting at the end and copy backward. The function would be something like
void RotatePixelsRight()
{
    uint8_t* pFront = strip.Pixels();
    uint8_t* pStop = pFront + 2; // the last component of the first pixel
    uint8_t* pData = pFront + strip.Count() * 3 - 1; // the last component of the last pixel
    uint8_t lastPixel[3]; // temp storage for the last pixel

    // copy the last pixel into a temp buffer
    for (uint8_t* pLast = pData, uint8_t* pTemp = &lastPixel[2]; pLast > pData - 3; pLast--, pTemp--)
    {
        *pTemp = *pLast;
    }

    // shift copy all pixels (which are 3 bytes) right to left
    while (pData != pStop)
    {
        *pData = *(pData - 3);
        pData--;
    }

    // copy the temp buffer back into the first place, pData is already in place to continue the copy
    for (uint8_t* pTemp = &lastPixel[2]; pTemp >= &lastPixel[0]; pData--, pTemp--)
    {
        *pData = *pTemp;
    }
}
There is an optimization you can do with that inner loop, have another variable for the already offset by -3 that you also decrement which would get rid of the subtraction on every loop; but I will leave that to you.
sticilface
@sticilface
Jun 02 2015 17:09
You're a star! cheers... I shall study this in detail...