Skip to content

Instantly share code, notes, and snippets.

@tablatronix
Last active October 6, 2016 20:17
Show Gist options
  • Save tablatronix/9957ab3fadcfe8354120fef06b45d82f to your computer and use it in GitHub Desktop.
Save tablatronix/9957ab3fadcfe8354120fef06b45d82f to your computer and use it in GitHub Desktop.
uint8_t *pixels; // global pixel array
uint8_t NUMPIXELS = 8; // number of leds/pixels
uint8_t NUMBYTES = 3; // bytes per pixel, RGBW = 4, RGB = 3
uint16_t BUFFBYTES = NUMPIXELS*NUMBYTES; // bytes to allocate for pixel array
void allocPixelArray(uint8_t numPixels,uint8_t numBytes){
NUMPIXELS = numPixels;
NUMBYTES = numBytes;
BUFFBYTES = numPixels*numBytes;
Serial.println("allocating " + (String)BUFFBYTES + " bytes");
if(pixels) free(pixels); // free memory
pixels = (uint8_t *)malloc(BUFFBYTES); // allocate new memory
memset(pixels, 0, BUFFBYTES );
}
void allocPixelArray(){
allocPixelArray(NUMPIXELS,NUMBYTES);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment