A neopixel light painting strip
Fork of LocalFileSystem_HelloWorld by
Diff: main.cpp
- Revision:
- 2:5021f3ba2043
- Parent:
- 1:cb842cdf5858
--- a/main.cpp Mon Jul 06 20:50:42 2015 +0000 +++ b/main.cpp Tue Nov 10 21:17:10 2015 +0000 @@ -44,6 +44,22 @@ return fn; } +void strip_off() { + for (int i=0; i<N; i++) { + strip.setPixel(i, 0); + } + strip.write(); +} + +void display_number(float f) { + for (int i=0; i<N; i++) { + if (i<(f*N)) + strip.setPixel(i, 0xffffff); + } + strip.write(); + wait(0.2); + strip_off(); +} void brightnessUp(void) { if (bright < 1) @@ -53,6 +69,7 @@ bright = 1; printf("increase brightness\r\n"); strip.setBrightness(bright); + display_number(bright); } } @@ -64,6 +81,7 @@ bright = 0; printf("decrease brightness\r\n"); strip.setBrightness(bright); + display_number(bright); } } @@ -72,6 +90,7 @@ if (file_index < 0) file_index = max_file; printf("fileDown to %i:%s\r\n", file_index, f_list[file_index]); + display_number(file_index/float(N)); } void fileUp(void) { @@ -79,12 +98,72 @@ if (file_index > max_file) file_index = 0; printf("fileUp to %i:%s\r\n", file_index, f_list[file_index]); + display_number(file_index/float(N)); } + +// Converts HSV to RGB with the given hue, assuming +// maximum saturation and value +int hueToRGB(float h) +{ + // lots of floating point magic from the internet and scratching my head + float r, g, b; + if (h > 360) + h -= 360; + if (h < 0) + h += 360; + int i = (int)(h / 60.0); + float f = (h / 60.0) - i; + float q = 1 - f; + + switch (i % 6) + { + case 0: r = 1; g = f; b = 0; break; + case 1: r = q; g = 1; b = 0; break; + case 2: r = 0; g = 1; b = f; break; + case 3: r = 0; g = q; b = 1; break; + case 4: r = f; g = 0; b = 1; break; + case 5: r = 1; g = 0; b = q; break; + default: r = 0; g = 0; b = 0; break; + } + + // scale to integers and return the packed value + uint8_t R = (uint8_t)(r * 255); + uint8_t G = (uint8_t)(g * 255); + uint8_t B = (uint8_t)(b * 255); + + return (R << 16) | (G << 8) | B; +} + + +void pattern1() +{ + static float dh = 360.0 / N; + static float x = 0; + printf("%f\r\n",x); + + for (int i = 0; i < N; i++) { + int c = hueToRGB((dh * i) - x); + //printf("R %i, G %i, B %i\r\n", (c>>16)&0xff, (c>>8)&0xff, c&0xff); + strip.setPixel(i, c); + } + + x += 1; + if (x > 360) + x = 0; +} + + void patternStart(void) { printf("file_index: %i\r\n", file_index); - if (file_index == 0) + if (file_index == 0) { + for ( int j=0; j<100; j++ ){ + pattern1(); + strip.write(); + wait_ms(20); + } return; + } printf("fn: %s\r\n", f_list[file_index]); @@ -104,13 +183,14 @@ for(int col = 0; col < MyBitmap->getWidth(); col++) { unsigned c = row_color[col] & 0xffffff; - strip.setPixel(col, c & 0xff0000, c & 0xff00, c & 0xff); + strip.setPixel(col, c); if ( c > 0xfff ) printf(" "); else printf("*"); } strip.write(); + wait_ms(20); printf("\r\n"); delete [] row_color; } @@ -119,9 +199,12 @@ printf("closed\r\n"); free(fn); free(path); + strip_off(); } + + int main() { b1.setAssertValue( 0 ); b2.setAssertValue( 0 );