/// <summary> /// Draws an entire bitmap to a grid of NeoPixels /// </summary> /// <param name="bm">the bitmap to draw</param> /// <param name="GetIndexFunc">a "function pointer" so the user can specify how the grid is arranged. for generic arrangements, try using "GridArrangement" instead</param> public void Write(Bitmap bm, GetIndexDelegate GetIndexFunc) { // note: top left corner of a bitmap is (0,0) int count = bm.Width * bm.Height; byte[] barr = new byte[count * 3]; for (int x = 0; x < bm.Width; x++) { for (int y = 0; y < bm.Height; y++) { Color c = bm.GetPixel(x, y); int idx = GetIndexFunc(x, y, bm.Width, bm.Height); barr[idx * 3 + 0] = ColorUtility.GetGValue(c); barr[idx * 3 + 1] = ColorUtility.GetRValue(c); barr[idx * 3 + 2] = ColorUtility.GetBValue(c); } } NeoPixelNative.Write(barr, count, (UInt32)pin); /* // this is what the code would've looked like if I didn't care about RAM memory so much * Color[] pix = new Color[bm.Width * bm.Height]; * for (int x = 0; x < bm.Width; x++) * { * for (int y = 0; y < bm.Height; y++) * { * Color c = bm.GetPixel(x, y); * int idx = GetIndexFunc(x, y, bm.Width, bm.Height); * pix[idx] = c; * } * } * * Write(pix); * //*/ }
/// <summary> /// Updates a set of NeoPixels /// </summary> /// <param name="pixels">a list of NeoPixels to update, index 0 is the first NeoPixel connected to the MCU</param> /// <param name="count">the number of NeoPixels</param> public void Write(NeoPixel[] pixels, int count) { byte[] barr = new byte[count * 3]; for (int i = 0; i < count; i++) { // the order here is critical, it matches what the NeoPixels expect barr[i * 3 + 0] = pixels[i].Green; barr[i * 3 + 1] = pixels[i].Red; barr[i * 3 + 2] = pixels[i].Blue; } NeoPixelNative.Write(barr, count, (UInt32)pin); }
/// <summary> /// The "Color" enum is a used for generic graphic stuff inside Microsoft.SPOT /// This method allows you to set NeoPixels using Microsoft.SPOT's "Color" /// Note: the "Color" enum is a 32 bit integer but GRB is 24 bit, however there are no data types available for just 24 bits /// </summary> /// <param name="pixels">a list of colors to be written, index 0 is the first NeoPixel connected to the MCU</param> /// <param name="count">the number of colors to be written</param> public void Write(Color[] pixels, int count) { byte[] barr = new byte[count * 3]; for (int i = 0; i < count; i++) { // the order here is critical, it matches what the NeoPixels expect barr[i * 3 + 0] = ColorUtility.GetGValue(pixels[i]); barr[i * 3 + 1] = ColorUtility.GetRValue(pixels[i]); barr[i * 3 + 2] = ColorUtility.GetBValue(pixels[i]); } NeoPixelNative.Write(barr, count, (UInt32)pin); /* // this is what the code would've looked like if I didn't care about RAM memory so much * NeoPixel[] wsPixels = new NeoPixel[count]; * for (int i = 0; i < count; i++) * { * wsPixels[i] = new NeoPixel(pixels[i]); * } * Write(wsPixels, count); * //*/ }