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