Glowing_Mirror_Mask.ino
1 // SPDX-FileCopyrightText: 2018 Erin St Blaine for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 // Glowing Mirror Mask using the Adafruit Hallowing 6 // Full tutorial available on the Adafruit Learning System. 7 // Code by Phil Burgess & Erin St. Blaine for Adafruit Industries. 8 9 10 #include <Adafruit_GFX.h> 11 #include <Adafruit_ST7735.h> 12 #include <Adafruit_NeoPixel.h> 13 #include <FastLED.h> 14 15 // Enable ONE of these lines to select an animation, 16 // others MUST be commented out! 17 18 //#include "fire.h" 19 #include "butterfly.h" 20 21 #define TFT_CS 39 22 #define TFT_RST 37 23 #define TFT_DC 38 24 #define TFT_BACKLIGHT 7 25 26 #define LED_PIN 4 // Hallowing's neopixel port is on pin 4 27 #define NUM_LEDS 30 // Change this to reflect how many LEDs you have 28 #define LED_TYPE WS2812 // Neopixels 29 #define COLOR_ORDER GRB 30 CRGB leds[NUM_LEDS]; 31 32 int indexinc = 1; 33 uint8_t brightness = 150; 34 uint8_t updates_per_second = 30; 35 36 CRGBPalette16 currentPalette; 37 TBlendType currentBlending; 38 39 Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); 40 41 void setup(void) { 42 tft.initR(INITR_144GREENTAB); 43 tft.setRotation(2); // change between 0-3 to set the rotation of the image on the screen 44 tft.fillScreen(0); // screen background brightness 45 46 pinMode(TFT_BACKLIGHT, OUTPUT); 47 digitalWrite(TFT_BACKLIGHT, HIGH); 48 49 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); // WS2812B 50 FastLED.setBrightness(brightness); 51 52 currentPalette = RainbowColors_p; //Uncomment ONE of these lines to choose your Neopixel color palette 53 //currentPalette = HeatColors_p; 54 //currentPalette = PartyColors_p; 55 //currentPalette = CloudColors_p; 56 //currentPalette = RainbowStripeColors_p; 57 //currentPalette = ForestColors_p; 58 //currentPalette = OceanColors_p; 59 } 60 61 uint8_t frameNum = 0; 62 63 void loop() { 64 tft.startWrite(); 65 tft.setAddrWindow( 66 (tft.width() - IMG_WIDTH ) / 2, 67 (tft.height() - IMG_HEIGHT) / 2, 68 IMG_WIDTH, IMG_HEIGHT); 69 tft.writePixels((uint16_t *)frames[frameNum], IMG_WIDTH * IMG_HEIGHT); 70 tft.endWrite(); 71 delay(IMG_DELAY); 72 if(++frameNum >= IMG_FRAMES) frameNum = 0; 73 74 colorwaves( leds, NUM_LEDS, currentPalette); 75 76 FastLED.show(); 77 } 78 79 80 void FillLEDsFromPaletteColors(uint8_t colorIndex) { 81 for (int i = 0; i < NUM_LEDS; i++) { 82 leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); 83 colorIndex += indexinc; 84 } 85 } 86 87 // This function draws color waves with an ever-changing, 88 // widely-varying set of parameters, using a color palette. 89 void colorwaves( CRGB* ledarray, uint16_t numleds, CRGBPalette16& palette) 90 { 91 static uint16_t sPseudotime = 0; 92 static uint16_t sLastMillis = 0; 93 static uint16_t sHue16 = 0; 94 95 uint8_t sat8 = beatsin88( 87, 220, 250); 96 uint8_t brightdepth = beatsin88( 341, 96, 224); 97 uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256)); 98 uint8_t msmultiplier = beatsin88(147, 23, 60); 99 100 uint16_t hue16 = sHue16;//gHue * 256; 101 uint16_t hueinc16 = beatsin88(113, 300, 1500); 102 103 uint16_t ms = millis(); 104 uint16_t deltams = ms - sLastMillis ; 105 sLastMillis = ms; 106 sPseudotime += deltams * msmultiplier; 107 sHue16 += deltams * beatsin88( 400, 5,9); 108 uint16_t brightnesstheta16 = sPseudotime; 109 110 for( uint16_t i = 0 ; i < numleds; i++) { 111 hue16 += hueinc16; 112 uint8_t hue8 = hue16 / 256; 113 uint16_t h16_128 = hue16 >> 7; 114 if( h16_128 & 0x100) { 115 hue8 = 255 - (h16_128 >> 1); 116 } else { 117 hue8 = h16_128 >> 1; 118 } 119 120 brightnesstheta16 += brightnessthetainc16; 121 uint16_t b16 = sin16( brightnesstheta16 ) + 32768; 122 123 uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536; 124 uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536; 125 bri8 += (255 - brightdepth); 126 127 uint8_t index = hue8; 128 //index = triwave8( index); 129 index = scale8( index, 240); 130 131 CRGB newcolor = ColorFromPalette( palette, index, bri8); 132 133 uint16_t pixelnumber = i; 134 pixelnumber = (numleds-1) - pixelnumber; 135 136 nblend( ledarray[pixelnumber], newcolor, 128); 137 } 138 }