1. Christopher De Vries
  2. pov

Commits

Christopher De Vries  committed 0c24ef4

Arduino naming conventions... grr...

  • Participants
  • Parent commits dbae459
  • Branches default

Comments (0)

Files changed (2)

File pov_bm-color/pov_bm-color.pde

  • Ignore whitespace
-/*****************************************************************************
-POV Test 2
-*****************************************************************************/
-#include <SPI.h>
-const unsigned int BLACK = 0x00;
-const unsigned int RED = 0x01;
-const unsigned int GREEN = 0x02;
-const unsigned int BLUE = 0x04;
-const unsigned int WHITE = 0x07;
-
-const int inverse_velocity=25; // Inverse of pixels per millisecond motion
-const int overshoot=15; // Pixel overshoot from edge on motion
-
-const int FORWARD=0;
-const int BACKWARD=1;
-
-const int STRANDS=2;
-
-/* position of strands, measured in pixels */
-int strand_pos[STRANDS] = {
-  12,
-  37
-};
-/* pixel starts of strands in LED chain */
-int strand_start[STRANDS] = {
-  0,
-  100
-};
-
-/* rabbit information */
-int rabbit_length = 50; /* Length of rabbit in pixels */
-int rabbit_start = 50; /* Start of rabbit strand in pixels */
-int rabbit_offset = 17; /* Location of X-center of image */
-
-const int MAX_LEDS=150;
-
-int pix_min; // Lowest distance
-int pix_max; // Highest distance
-
-/* Image data is stored in an array of unsigned integers. The first 15 bits
- * of the integer store 5 colors using bits in the order RGBRGBRGBRGBRGB for
- * pixels 0,1,2,3,4 of that integer. Those integers are stored with y-values
- * incrementing quickly, and x values incrementing every ny_int integers in y.
- * There is no bounds checking.
- */
-struct image {
-  int nx;
-  int ny;
-  int ny_int;
-  unsigned int *data;
-};
-
-struct image pov_image;
-struct image strand_image;
-
-/* POV Image Data */
-unsigned int imagedata[]={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-  0x1200, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1200, 0x1, 0x0, 0x0,
-  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1000, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-  0x0, 0x0, 0x49, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1248, 0x0,
-  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1240, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0,
-  0x0, 0x0, 0x0, 0x1200, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x240, 0x0, 0x1000,
-  0x49, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1000, 0x1249, 0x0, 0x0, 0x1248, 0x0, 0x0,
-  0x0, 0x0, 0x0, 0x1248, 0x249, 0x0, 0x0, 0x1240, 0x1, 0x0, 0x0, 0x0, 0x1000,
-  0x1249, 0x1, 0x0, 0x0, 0x1200, 0x49, 0x0, 0x0, 0x0, 0x1248, 0x49, 0x0, 0x0,
-  0x92, 0x0, 0x1249, 0x0, 0x0, 0x1248, 0x1249, 0x0, 0x0, 0x2000, 0x2492, 0x0,
-  0x1240, 0x249, 0x1249, 0x1249, 0x9, 0x0, 0x0, 0x2400, 0x2492, 0x2, 0x1000,
-  0x1249, 0x1249, 0x49, 0x0, 0x0, 0x0, 0x2480, 0x2402, 0x92, 0x0, 0x1248,
-  0x249, 0x0, 0x0, 0x0, 0x0, 0x2480, 0x0, 0x2492, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-  0x0, 0x490, 0x0, 0x2480, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x490, 0x0,
-  0x2490, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2480, 0x2000, 0x492, 0x0, 0x0,
-  0x0, 0x0, 0x0, 0x0, 0x0, 0x2400, 0x2402, 0x12, 0x0, 0x4924, 0x4924, 0x0, 0x0,
-  0x0, 0x0, 0x2000, 0x2492, 0x2, 0x4800, 0x4924, 0x4924, 0x924, 0x0, 0x0, 0x0,
-  0x0, 0x492, 0x0, 0x4920, 0x24, 0x4800, 0x4924, 0x24, 0x0, 0x0, 0x0, 0x12,
-  0x0, 0x924, 0x0, 0x0, 0x4900, 0x4924, 0x0, 0x0, 0x0, 0x0, 0x4800, 0x24, 0x0,
-  0x0, 0x0, 0x4920, 0x924, 0x0, 0x0, 0x0, 0x4920, 0x4, 0x0, 0x0, 0x0, 0x4000,
-  0x4924, 0x24, 0x0, 0x0, 0x924, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4900, 0x924, 0x0,
-  0x4000, 0x124, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4924, 0x0, 0x4800, 0x24, 0x0,
-  0x0, 0x0, 0x0, 0x0, 0x0, 0x800, 0x0, 0x4900, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-  0x0, 0x0, 0x0, 0x920, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4000, 0x124,
-  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4800, 0x24, 0x0, 0x0, 0x0, 0x0,
-  0x0, 0x0, 0x0, 0x0, 0x4900, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-  0x4800, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
-
-void setup() {
-  int i;
-  
-  SPI.begin();
-  SPI.setBitOrder(MSBFIRST);
-  SPI.setDataMode(SPI_MODE0);
-  SPI.setClockDivider(SPI_CLOCK_DIV2);
-
-  /* POV Image Setup */
-  pov_image.nx=35;
-  pov_image.ny=50;
-  pov_image.ny_int=10;
-  pov_image.data = imagedata;
- 
-  allocate_image(&strand_image,1,MAX_LEDS);
-  if(strand_image.nx==0) {
-    error_state();
-  }
-  
-  pix_min=strand_pos[0];
-  pix_max=strand_pos[0];
-  for(i=1;i<STRANDS;i++) {
-    if(strand_pos[i]<pix_min) {
-      pix_min=strand_pos[i];
-    }
-    else if(strand_pos[i]>pix_max) {
-      pix_max=strand_pos[i];
-    }
-  }
-  pix_min-=pov_image.nx+overshoot;
-  pix_max+=overshoot;
-  
-  lightStrand_SendEmptyFrame();
-  for(i=0;i<MAX_LEDS;i++) {
-    lightStrand_SendColor(0x00,0x00,0x00);
-  }
-  lightStrand_SendEmptyFrame();
-}
-
-void loop() {
-  static long int tnot=0;
-  long int tcurr;
-  long int t;
-  static int direction=FORWARD;
-  int i;
-  int j;
-  byte red;
-  byte green;
-  byte blue;
-  int x; /* Position of left corner of image in pixels */
-  int pix_column;
-  int rabbit_pos;
-
-  tcurr = millis();
-  t=tcurr-tnot;
-  
-  if(direction==FORWARD) {
-    x = pix_min+t/inverse_velocity;
-    if(x>pix_max) {
-      tnot=tcurr;
-      direction=BACKWARD;
-    }
-  }
-  else {
-    x = pix_max-t/inverse_velocity;
-    if(x<pix_min) {
-      tnot=tcurr;
-      direction=FORWARD;
-    }
-  }
-  
-  /* Draw the strands */
-  for(i=0;i<STRANDS;i++) {
-    pix_column = strand_pos[i]-x;
-    if(pix_column>-1 && pix_column<pov_image.nx) {
-      for(j=0;j<pov_image.ny;j++) {
-        if(i%2!=0) {
-          set_pixel(&strand_image,0,strand_start[i]+j,get_pixel(&pov_image,pix_column,j));
-        }
-        else {
-          set_pixel(&strand_image,0,strand_start[i]+pov_image.ny-j-1,get_pixel(&pov_image,pix_column,j));
-        }
-      }
-    }
-    else {
-      for(j=0;j<pov_image.ny;j++) {
-        set_pixel(&strand_image,0,pov_image.ny*i+j,BLACK);
-      }
-    }
-  }
-  
-  /* Draw the rabbit */
-  rabbit_pos = x+rabbit_offset;
-  if(rabbit_pos>=0 && rabbit_pos<rabbit_length) {
-    set_pixel(&strand_image,0,rabbit_start+rabbit_pos,RED);
-  }
-
-  lightStrand_SendEmptyFrame();
-  for(i=0;i<STRANDS*pov_image.ny;i++) {
-    get_pixel_rgb(&strand_image,0,i,&red,&green,&blue);
-    lightStrand_SendColor(red,green,blue);
-  }
-  lightStrand_SendEmptyFrame();
-}
-
-void error_state() {
-  while(true) {
-    lightStrand_SendEmptyFrame();
-    lightStrand_SendColor(0x00,0x00,0x00);
-    lightStrand_SendEmptyFrame();
-    delay(500);
-    lightStrand_SendEmptyFrame();
-    lightStrand_SendColor(0xff,0x00,0x00);
-    lightStrand_SendEmptyFrame();
-    delay(500);
-  }
-}
-
-void allocate_image(struct image *bit_image, int x, int y) {
-  bit_image->ny_int = ((y-1)/5)+1;
-  
-  bit_image->data = (unsigned int*)malloc(x*bit_image->ny_int*sizeof(unsigned int));
-  if(bit_image->data==NULL) {
-    bit_image->nx=0;
-    bit_image->ny=0;
-  }
-  else {
-    bit_image->nx=x;
-    bit_image->ny=y;
-  }
-  
-  return;
-}
-
-void set_pixel(struct image *bit_image, int x, int y, unsigned int pix) {
-  int y_int = y/5;
-  int y_within_int = y%5;
-  int datanum;
-  
-  /* Find the unsigned int we need */
-  datanum = x*bit_image->ny_int+y_int;
-  bit_image->data[datanum]&=~(WHITE<<(y_within_int*3));
-  bit_image->data[datanum]|=pix<<(y_within_int*3);
-}
-
-unsigned int get_pixel(struct image *bit_image, int x, int y) {
-  int y_int = y/5;
-  int y_within_int=y%5;
-  int datanum;
-  unsigned int data_int;
-  
-  datanum = x*bit_image->ny_int+y_int;
-  data_int = bit_image->data[datanum];
-  
-  data_int>>=y_within_int*3;
-  data_int&=WHITE;
-  
-  return data_int;
-}
-
-void get_pixel_rgb(struct image *bit_image, int x, int y, byte *red, byte *green, byte *blue) {
-  int y_int = y/5;
-  int y_within_int=y%5;
-  int datanum;
-  unsigned int data_int;
-  
-  datanum = x*bit_image->ny_int+y_int;
-  data_int = bit_image->data[datanum];
-  
-  data_int>>=y_within_int*3;
-  if(data_int&RED) {
-    *red = 0xff;
-  }
-  else {
-    *red = 0x00;
-  }
-  
-  if(data_int&GREEN) {
-    *green = 0xff;
-  }
-  else {
-    *green = 0x00;
-  }
-  
-  if(data_int&BLUE) {
-    *blue = 0xff;
-  }
-  else {
-    *blue = 0x00;
-  }
-}
-
-//Light Strand utility: make required flag for color packet
-byte lightStrand_MakeFlag(byte  red, byte green, byte blue){
-  byte flag = 0;
-  flag = (red&0xC0)>>6;
-  flag |= ((green&0xC0)>>4);
-  flag |= ((blue&0xC0)>>2);
-  return ~flag;
-}
-
-// Send a frame to the LED light strang
-void lightStrand_SendFrame(byte flag, byte red, byte green, byte blue) {
-  SPI.transfer(flag);
-  SPI.transfer(blue);
-  SPI.transfer(green);
-  SPI.transfer(red);
-}
-
-void lightStrand_SendEmptyFrame() {
-  lightStrand_SendFrame(0x00,0x00,0x00,0x00);
-}
-
-void lightStrand_SendColor(byte red, byte green, byte blue) {
-  byte flag = lightStrand_MakeFlag(red,green,blue);
-  
-  lightStrand_SendFrame(flag,red,green,blue);
-}
-  

File pov_bm_color/pov_bm_color.pde

View file
  • Ignore whitespace
+/*****************************************************************************
+POV Test 2
+*****************************************************************************/
+#include <SPI.h>
+const unsigned int BLACK = 0x00;
+const unsigned int RED = 0x01;
+const unsigned int GREEN = 0x02;
+const unsigned int BLUE = 0x04;
+const unsigned int WHITE = 0x07;
+
+const int inverse_velocity=25; // Inverse of pixels per millisecond motion
+const int overshoot=15; // Pixel overshoot from edge on motion
+
+const int FORWARD=0;
+const int BACKWARD=1;
+
+const int STRANDS=2;
+
+/* position of strands, measured in pixels */
+int strand_pos[STRANDS] = {
+  12,
+  37
+};
+/* pixel starts of strands in LED chain */
+int strand_start[STRANDS] = {
+  0,
+  100
+};
+
+/* rabbit information */
+int rabbit_length = 50; /* Length of rabbit in pixels */
+int rabbit_start = 50; /* Start of rabbit strand in pixels */
+int rabbit_offset = 17; /* Location of X-center of image */
+
+const int MAX_LEDS=150;
+
+int pix_min; // Lowest distance
+int pix_max; // Highest distance
+
+/* Image data is stored in an array of unsigned integers. The first 15 bits
+ * of the integer store 5 colors using bits in the order RGBRGBRGBRGBRGB for
+ * pixels 0,1,2,3,4 of that integer. Those integers are stored with y-values
+ * incrementing quickly, and x values incrementing every ny_int integers in y.
+ * There is no bounds checking.
+ */
+struct image {
+  int nx;
+  int ny;
+  int ny_int;
+  unsigned int *data;
+};
+
+struct image pov_image;
+struct image strand_image;
+
+/* POV Image Data */
+unsigned int imagedata[]={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+  0x1200, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1200, 0x1, 0x0, 0x0,
+  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1000, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+  0x0, 0x0, 0x49, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1248, 0x0,
+  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1240, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0,
+  0x0, 0x0, 0x0, 0x1200, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x240, 0x0, 0x1000,
+  0x49, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1000, 0x1249, 0x0, 0x0, 0x1248, 0x0, 0x0,
+  0x0, 0x0, 0x0, 0x1248, 0x249, 0x0, 0x0, 0x1240, 0x1, 0x0, 0x0, 0x0, 0x1000,
+  0x1249, 0x1, 0x0, 0x0, 0x1200, 0x49, 0x0, 0x0, 0x0, 0x1248, 0x49, 0x0, 0x0,
+  0x92, 0x0, 0x1249, 0x0, 0x0, 0x1248, 0x1249, 0x0, 0x0, 0x2000, 0x2492, 0x0,
+  0x1240, 0x249, 0x1249, 0x1249, 0x9, 0x0, 0x0, 0x2400, 0x2492, 0x2, 0x1000,
+  0x1249, 0x1249, 0x49, 0x0, 0x0, 0x0, 0x2480, 0x2402, 0x92, 0x0, 0x1248,
+  0x249, 0x0, 0x0, 0x0, 0x0, 0x2480, 0x0, 0x2492, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+  0x0, 0x490, 0x0, 0x2480, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x490, 0x0,
+  0x2490, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2480, 0x2000, 0x492, 0x0, 0x0,
+  0x0, 0x0, 0x0, 0x0, 0x0, 0x2400, 0x2402, 0x12, 0x0, 0x4924, 0x4924, 0x0, 0x0,
+  0x0, 0x0, 0x2000, 0x2492, 0x2, 0x4800, 0x4924, 0x4924, 0x924, 0x0, 0x0, 0x0,
+  0x0, 0x492, 0x0, 0x4920, 0x24, 0x4800, 0x4924, 0x24, 0x0, 0x0, 0x0, 0x12,
+  0x0, 0x924, 0x0, 0x0, 0x4900, 0x4924, 0x0, 0x0, 0x0, 0x0, 0x4800, 0x24, 0x0,
+  0x0, 0x0, 0x4920, 0x924, 0x0, 0x0, 0x0, 0x4920, 0x4, 0x0, 0x0, 0x0, 0x4000,
+  0x4924, 0x24, 0x0, 0x0, 0x924, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4900, 0x924, 0x0,
+  0x4000, 0x124, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4924, 0x0, 0x4800, 0x24, 0x0,
+  0x0, 0x0, 0x0, 0x0, 0x0, 0x800, 0x0, 0x4900, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+  0x0, 0x0, 0x0, 0x920, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4000, 0x124,
+  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4800, 0x24, 0x0, 0x0, 0x0, 0x0,
+  0x0, 0x0, 0x0, 0x0, 0x4900, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+  0x4800, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
+
+void setup() {
+  int i;
+  
+  SPI.begin();
+  SPI.setBitOrder(MSBFIRST);
+  SPI.setDataMode(SPI_MODE0);
+  SPI.setClockDivider(SPI_CLOCK_DIV2);
+
+  /* POV Image Setup */
+  pov_image.nx=35;
+  pov_image.ny=50;
+  pov_image.ny_int=10;
+  pov_image.data = imagedata;
+ 
+  allocate_image(&strand_image,1,MAX_LEDS);
+  if(strand_image.nx==0) {
+    error_state();
+  }
+  
+  pix_min=strand_pos[0];
+  pix_max=strand_pos[0];
+  for(i=1;i<STRANDS;i++) {
+    if(strand_pos[i]<pix_min) {
+      pix_min=strand_pos[i];
+    }
+    else if(strand_pos[i]>pix_max) {
+      pix_max=strand_pos[i];
+    }
+  }
+  pix_min-=pov_image.nx+overshoot;
+  pix_max+=overshoot;
+  
+  lightStrand_SendEmptyFrame();
+  for(i=0;i<MAX_LEDS;i++) {
+    lightStrand_SendColor(0x00,0x00,0x00);
+  }
+  lightStrand_SendEmptyFrame();
+}
+
+void loop() {
+  static long int tnot=0;
+  long int tcurr;
+  long int t;
+  static int direction=FORWARD;
+  int i;
+  int j;
+  byte red;
+  byte green;
+  byte blue;
+  int x; /* Position of left corner of image in pixels */
+  int pix_column;
+  int rabbit_pos;
+
+  tcurr = millis();
+  t=tcurr-tnot;
+  
+  if(direction==FORWARD) {
+    x = pix_min+t/inverse_velocity;
+    if(x>pix_max) {
+      tnot=tcurr;
+      direction=BACKWARD;
+    }
+  }
+  else {
+    x = pix_max-t/inverse_velocity;
+    if(x<pix_min) {
+      tnot=tcurr;
+      direction=FORWARD;
+    }
+  }
+  
+  /* Draw the strands */
+  for(i=0;i<STRANDS;i++) {
+    pix_column = strand_pos[i]-x;
+    if(pix_column>-1 && pix_column<pov_image.nx) {
+      for(j=0;j<pov_image.ny;j++) {
+        if(i%2!=0) {
+          set_pixel(&strand_image,0,strand_start[i]+j,get_pixel(&pov_image,pix_column,j));
+        }
+        else {
+          set_pixel(&strand_image,0,strand_start[i]+pov_image.ny-j-1,get_pixel(&pov_image,pix_column,j));
+        }
+      }
+    }
+    else {
+      for(j=0;j<pov_image.ny;j++) {
+        set_pixel(&strand_image,0,pov_image.ny*i+j,BLACK);
+      }
+    }
+  }
+  
+  /* Draw the rabbit */
+  rabbit_pos = x+rabbit_offset;
+  if(rabbit_pos>=0 && rabbit_pos<rabbit_length) {
+    set_pixel(&strand_image,0,rabbit_start+rabbit_pos,RED);
+  }
+
+  lightStrand_SendEmptyFrame();
+  for(i=0;i<STRANDS*pov_image.ny;i++) {
+    get_pixel_rgb(&strand_image,0,i,&red,&green,&blue);
+    lightStrand_SendColor(red,green,blue);
+  }
+  lightStrand_SendEmptyFrame();
+}
+
+void error_state() {
+  while(true) {
+    lightStrand_SendEmptyFrame();
+    lightStrand_SendColor(0x00,0x00,0x00);
+    lightStrand_SendEmptyFrame();
+    delay(500);
+    lightStrand_SendEmptyFrame();
+    lightStrand_SendColor(0xff,0x00,0x00);
+    lightStrand_SendEmptyFrame();
+    delay(500);
+  }
+}
+
+void allocate_image(struct image *bit_image, int x, int y) {
+  bit_image->ny_int = ((y-1)/5)+1;
+  
+  bit_image->data = (unsigned int*)malloc(x*bit_image->ny_int*sizeof(unsigned int));
+  if(bit_image->data==NULL) {
+    bit_image->nx=0;
+    bit_image->ny=0;
+  }
+  else {
+    bit_image->nx=x;
+    bit_image->ny=y;
+  }
+  
+  return;
+}
+
+void set_pixel(struct image *bit_image, int x, int y, unsigned int pix) {
+  int y_int = y/5;
+  int y_within_int = y%5;
+  int datanum;
+  
+  /* Find the unsigned int we need */
+  datanum = x*bit_image->ny_int+y_int;
+  bit_image->data[datanum]&=~(WHITE<<(y_within_int*3));
+  bit_image->data[datanum]|=pix<<(y_within_int*3);
+}
+
+unsigned int get_pixel(struct image *bit_image, int x, int y) {
+  int y_int = y/5;
+  int y_within_int=y%5;
+  int datanum;
+  unsigned int data_int;
+  
+  datanum = x*bit_image->ny_int+y_int;
+  data_int = bit_image->data[datanum];
+  
+  data_int>>=y_within_int*3;
+  data_int&=WHITE;
+  
+  return data_int;
+}
+
+void get_pixel_rgb(struct image *bit_image, int x, int y, byte *red, byte *green, byte *blue) {
+  int y_int = y/5;
+  int y_within_int=y%5;
+  int datanum;
+  unsigned int data_int;
+  
+  datanum = x*bit_image->ny_int+y_int;
+  data_int = bit_image->data[datanum];
+  
+  data_int>>=y_within_int*3;
+  if(data_int&RED) {
+    *red = 0xff;
+  }
+  else {
+    *red = 0x00;
+  }
+  
+  if(data_int&GREEN) {
+    *green = 0xff;
+  }
+  else {
+    *green = 0x00;
+  }
+  
+  if(data_int&BLUE) {
+    *blue = 0xff;
+  }
+  else {
+    *blue = 0x00;
+  }
+}
+
+//Light Strand utility: make required flag for color packet
+byte lightStrand_MakeFlag(byte  red, byte green, byte blue){
+  byte flag = 0;
+  flag = (red&0xC0)>>6;
+  flag |= ((green&0xC0)>>4);
+  flag |= ((blue&0xC0)>>2);
+  return ~flag;
+}
+
+// Send a frame to the LED light strang
+void lightStrand_SendFrame(byte flag, byte red, byte green, byte blue) {
+  SPI.transfer(flag);
+  SPI.transfer(blue);
+  SPI.transfer(green);
+  SPI.transfer(red);
+}
+
+void lightStrand_SendEmptyFrame() {
+  lightStrand_SendFrame(0x00,0x00,0x00,0x00);
+}
+
+void lightStrand_SendColor(byte red, byte green, byte blue) {
+  byte flag = lightStrand_MakeFlag(red,green,blue);
+  
+  lightStrand_SendFrame(flag,red,green,blue);
+}
+