hi,
i'm trying control ws2801 led stript without library. googling found following example: click me
this code working fine. but, don't idea of code, mean, don't understand why work. of code figured out, there 1 piece don't @ all. method post_frame not clear me.
here code i'm talking about:
the first loop quite straightforward, loops on leds. second loop isn't clear me. reason start byte has value of 23 , stops, don't know why exactly. send data, clock has low first, send data, , set clock high. after 2 loops, there delay (500us) result 'showed'.
within second loop there long, called mask. don't havy idea why used. after that, there if else statement uses mask. , reason, somethimes sdi pin high, , low. don't have idea why should this.
could explain me piece of code?
i'm trying control ws2801 led stript without library. googling found following example: click me
this code working fine. but, don't idea of code, mean, don't understand why work. of code figured out, there 1 piece don't @ all. method post_frame not clear me.
here code i'm talking about:
code: [select]
void post_frame (void) {
//each led requires 24 bits of data
//msb: r7, r6, r5..., g7, g6..., b7, b6... b0
//once 24 bits have been delivered, ic relays these bits neighbor
//pulling clock low 500us or more causes ic post data.
for(int led_number = 0 ; led_number < strip_length ; led_number++) {
long this_led_color = strip_colors[led_number]; //24 bits of color data
for(byte color_bit = 23 ; color_bit != 255 ; color_bit--) {
//feed color bit 23 first (red data msb)
digitalwrite(cki, low); //only change data when clock low
long mask = 1l << color_bit;
//the 1'l' forces 1 start 32 bit number, otherwise defaults 16-bit.
if(this_led_color & mask)
digitalwrite(sdi, high);
else
digitalwrite(sdi, low);
digitalwrite(cki, high); //data latched when clock goes high
}
}
the first loop quite straightforward, loops on leds. second loop isn't clear me. reason start byte has value of 23 , stops, don't know why exactly. send data, clock has low first, send data, , set clock high. after 2 loops, there delay (500us) result 'showed'.
within second loop there long, called mask. don't havy idea why used. after that, there if else statement uses mask. , reason, somethimes sdi pin high, , low. don't have idea why should this.
could explain me piece of code?
mask allows isolate individual bits in variable using bitwise , (&)
Arduino Forum > Using Arduino > LEDs and Multiplexing > WS2801 LED strip without library
arduino
Comments
Post a Comment