. The pico c sdk datasheet has great info on this at page 33.
#include <NeoPixelConnect.h>
#define MAXIMUM_NUM_NEOPIXELS 24
// Create an instance of NeoPixelConnect and initialize it
// to use GPIO pin 4 (D12) as the control pin, for a string
// of 8 neopixels. Name the instance p
NeoPixelConnect p(4, MAXIMUM_NUM_NEOPIXELS, pio0, 0);
// this array will hold a pixel number and the rgb values
uint8_t random_pixel_setting[4];
uint8_t waiting_pixel_setting[4];
int adjDelay = 0;
uint16_t runner = 0;
uint16_t leadPixel = 0;
void waiting(){
for( int i = MAXIMUM_NUM_NEOPIXELS-1; i >= 0; i--){//leadPixel update
//leadPixel = i;
for(int j = 0; j < MAXIMUM_NUM_NEOPIXELS; j++){//pixel update
//Lead pixel will be i + j
uint8_t pixel = i + j;
while(pixel >= MAXIMUM_NUM_NEOPIXELS){
pixel -= MAXIMUM_NUM_NEOPIXELS;
}
waiting_pixel_setting[0] = pixel;
// Serial.print("Pixel:");
// Serial.println(pixel);
waiting_pixel_setting[3] = random( 255 - ((255 / MAXIMUM_NUM_NEOPIXELS) * j) - (255 / MAXIMUM_NUM_NEOPIXELS) ,255 - ((255 / MAXIMUM_NUM_NEOPIXELS) * j));
// Serial.print("B:");
// Serial.println(waiting_pixel_setting[3]);
waiting_pixel_setting[1] = waiting_pixel_setting[3] / random(3, 5);
// Serial.print("R:");
// Serial.println(waiting_pixel_setting[1]);
waiting_pixel_setting[2] = waiting_pixel_setting[3] / random(5, 10);
// Serial.print("G:");
// Serial.println(waiting_pixel_setting[2]);
p.neoPixelSetValue(pixel, waiting_pixel_setting[1], waiting_pixel_setting[2], waiting_pixel_setting[3], false);
}
p.neoPixelShow();
delay(adjDelay++);
if(adjDelay == 120){
adjDelay = 0;
Serial.println("Reset!");
}
}
Serial.println(urgb_u32(waiting_pixel_setting[1], waiting_pixel_setting[2], waiting_pixel_setting[3]) << 8u);
}
uint32_t urgb_u32(uint8_t r, uint8_t g, uint8_t b) {
return
((uint32_t)(r) << 8) |
((uint32_t)(g) << 16) |
(uint32_t)(b);
}
// select a random pixel number in the string
uint8_t get_pixel_number(){
if(runner == MAXIMUM_NUM_NEOPIXELS){
runner = 0;
}
return (uint16_t)runner++;
}
// select a random intensity
uint8_t get_pixel_intensity(){
return((uint8_t)random(25,100));
}
void get_random_pixel_and_color(){
random_pixel_setting[0] = get_pixel_number();
random_pixel_setting[1] = get_pixel_intensity();
random_pixel_setting[2] = get_pixel_intensity();
random_pixel_setting[3] = get_pixel_intensity();
}
void setup(){
Serial.begin(115200);
// while(!Serial){//Wait for serial to come up
// sleep_ms(100);
// }
Serial.println("In setup");
//waiting();
}
void loop(){
waiting();
//delay(1000);
}