Last active
August 29, 2015 14:01
-
-
Save AlexJWayne/931bf0f97094ed6b24e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 375 loops per second | |
// – Arduino Uno R3 - | |
// Thanks to FastLED Math library: | |
// https://github.com/FastLED/FastLED/wiki/High-performance-math | |
void sinePixels() { | |
uint8_t timeScale = 20; | |
long time = millis() * timeScale; | |
long r, g, b; | |
for (uint8_t x = 0; x < 8; x++) { | |
for (uint8_t y = 0; y < 5; y++) { | |
// x 16 bit normalized | |
uint16_t x16 = x * 0x10000/8; // 1/8 16 bit | |
// y 8 bit normalized | |
uint8_t y8 = y * 0x100/5; // 1/4 8 bit | |
r = (sin16(x16 - time) >> 8) + 128; | |
r = 255 - abs(y8 - r); | |
r = dim8_raw(r); | |
g = (sin16(x16 - time * 2) >> 8) + 128; | |
g = 255 - abs(y8 - g); | |
g = dim8_raw(g); | |
b = (sin16(x16 + time * 3) >> 8) + 128; | |
b = 255 - abs(y8 - b); | |
b = dim8_raw(b); | |
strip.setPixelColor(x + y*8, r, g, b); | |
} | |
} | |
strip.show(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 20 loops per second | |
// – Arduino Uno R3 - | |
void sinePixels() { | |
float brightness = .5; | |
float timeScale = 3.0; | |
float time = (float)millis() / 1000.0; | |
float r, g, b; | |
for (uint8_t x = 0; x < 8; x++) { | |
for (uint8_t y = 0; y < 5; y++) { | |
r = sin(x - time*timeScale*3.0) * 0.15 + 0.5; | |
r = 1.0 - abs((float)y / 4.0 - r); | |
r = pow(r, 3); | |
g = sin(x + time*timeScale*2.1) * 0.2 + 0.5; | |
g = 1.0 - abs((float)y / 4.0 - g); | |
g = pow(g, 3); | |
b = sin(x - time*timeScale*1.3) * 0.4 + 0.5; | |
b = 1.0 - abs((float)y / 4.0 - b); | |
b = pow(b, 3); | |
setPixelColor( | |
x, y, | |
r * brightness, | |
g * brightness, | |
b * brightness | |
); | |
} | |
} | |
strip.show(); | |
} | |
void setPixelColor(uint8_t x, uint8_t y, float r, float g, float b) { | |
strip.setPixelColor(x + y*8, (uint8_t)(r*255), (uint8_t)(g*255), (uint8_t)(b*255)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment