Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define NUM_LEDS_EXT 116
- #define NUM_LEDS_MIL 68
- #define NUM_LEDS_INT 48
- #define DATA_PIN_EXT 6
- #define DATA_PIN_MIL 7
- #define DATA_PIN_INT 8
- CRGB ledsExt[NUM_LEDS_EXT];
- CRGB ledsMil[NUM_LEDS_MIL];
- CRGB ledsInt[NUM_LEDS_INT];
- uint8_t ihue = 0;
- void setup() {
- FastLED.delay(2000);
- FastLED.addLeds<WS2812, DATA_PIN_EXT, GRB>(ledsExt, NUM_LEDS_EXT).setDither(0);
- FastLED.addLeds<WS2812, DATA_PIN_MIL, GRB>(ledsMil, NUM_LEDS_MIL).setDither(0);
- FastLED.addLeds<WS2812, DATA_PIN_INT, GRB>(ledsInt, NUM_LEDS_INT).setDither(0);
- }
- void loop() {
- testAntiAliasedSinus() ;
- }
- void fillAll(CRGB color)
- {
- fill_solid(ledsExt, NUM_LEDS_EXT, color);
- fill_solid(ledsMil, NUM_LEDS_MIL, color);
- fill_solid(ledsInt, NUM_LEDS_INT, color);
- }
- CRGB getBackgroundColor()
- {
- return CHSV(ihue, 255, 255) ;
- }
- uint16_t getSinValue()
- {
- uint16_t w16 = (millis() * 5) % 65536 ;
- return sin16(w16) + 32768 ;
- }
- void testAntiAliasedSinus()
- {
- fillAll(getBackgroundColor()) ;
- antiAliasedSinusHelper(ledsExt, NUM_LEDS_EXT) ;
- antiAliasedSinusHelper(ledsMil, NUM_LEDS_MIL) ;
- antiAliasedSinusHelper(ledsInt, NUM_LEDS_INT) ;
- FastLED.show() ;
- }
- void antiAliasedSinusHelper(CRGB* heart, int nbPixels)
- {
- int width = nbPixels / 14 ;
- int pixelGauche = get16PixelPosition(nbPixels / 2, width) ;
- int pixelDroit = nbPixels * 16 - pixelGauche - 16 * width;
- drawFractionalBar(heart, pixelGauche, width) ;
- drawFractionalBar(heart, pixelDroit, width) ;
- }
- int get16PixelPosition(int nbPixels, int width)
- {
- return getSinValue() * (nbPixels * 16 - 16 * width) / 65536;
- }
- void drawFractionalBar(CRGB* heart, int pos16, int width )
- {
- int i = pos16 / 16;
- uint8_t frac = pos16 & 0x0F;
- uint8_t firstpixelbrightness = 255 - (frac * 16);
- uint8_t lastpixelbrightness = 255 - firstpixelbrightness;
- uint8_t bright;
- for( int n = 0; n <= width; n++) {
- if( n == 0 ) {
- // first pixel in the bar
- bright = firstpixelbrightness;
- } else if( n == width ) {
- // last pixel in the bar
- bright = lastpixelbrightness;
- } else {
- // middle pixels
- bright = 255;
- }
- heart[i] += CHSV( 0, 0, bright);
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment