acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

Adafruit_NeoPixel_GFX.h (3059B)

      1 #ifndef _ADAFRUIT_NEOPIXEL_GFX_H_
      2 #define _ADAFRUIT_NEOPIXEL_GFX_H_
      3 
      4 #include <Adafruit_NeoPixel.h>
      5 #include <Arduino_GFX.h>
      6 
      7 #ifdef __AVR__
      8 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
      9 #endif
     10 
     11 // Which pin on the Arduino is connected to the NeoPixels?
     12 #define NEOPIXEL_PIN 1 // On Trinket or Gemma, suggest changing this to 1
     13 
     14 #define NEOPIXEL_WIDTH 30
     15 #define NEOPIXEL_HEIGHT 8
     16 #define NUMPIXELS (NEOPIXEL_WIDTH * NEOPIXEL_HEIGHT)
     17 #define NEOPIXEL_BRIGHTNESS 3 // 1-255
     18 
     19 // Pixel type flags, add together as needed:
     20 // NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
     21 // NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
     22 // NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
     23 // NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
     24 // NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
     25 #define NEOPIXEL_TYPE (NEO_GRB + NEO_KHZ800)
     26 
     27 class Adafruit_NeoPixel_GFX : public Arduino_GFX
     28 {
     29 public:
     30   Adafruit_NeoPixel_GFX() : Arduino_GFX(NEOPIXEL_WIDTH, NEOPIXEL_HEIGHT)
     31   {
     32     wrap = false;
     33   }
     34 
     35   bool begin(int32_t speed = GFX_NOT_DEFINED) override
     36   {
     37     // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
     38     // Any other board, you can remove this part (but no harm leaving it):
     39 #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
     40     clock_prescale_set(clock_div_1);
     41 #endif
     42     // END of Trinket-specific code.
     43     _pixels = new Adafruit_NeoPixel(NUMPIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE);
     44     _pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
     45     _pixels->show();  // Turn OFF all pixels ASAP
     46     _pixels->setBrightness(NEOPIXEL_BRIGHTNESS);
     47 
     48     return true;
     49   }
     50 
     51   void writePixelPreclipped(int16_t x, int16_t y, uint16_t color) override
     52   {
     53     // select you matrix mode
     54     int32_t i = (x * NEOPIXEL_HEIGHT) + y;                                         // vertical strip start from left top
     55     // int32_t i = (x * NEOPIXEL_HEIGHT) + ((x % 2) ? y : (NEOPIXEL_HEIGHT - y - 1)); // vertical zigzag strip start from left top
     56     // int32_t i = (x * NEOPIXEL_HEIGHT) + (NEOPIXEL_HEIGHT - y - 1);                 // vertical strip start from left bottom
     57     // int32_t i = (x * NEOPIXEL_HEIGHT) + ((x % 2) ? (NEOPIXEL_HEIGHT - y - 1) : y); // vertical zigzag strip start from left bottom
     58     // int32_t i = x + (y * NEOPIXEL_WIDTH);                                          // horizontal strip start from left top
     59     // int32_t i = ((y % 2) ? x : (NEOPIXEL_WIDTH - x - 1)) + (y * NEOPIXEL_WIDTH);   // horizontal zigzag strip start from left top
     60     // int32_t i = (NEOPIXEL_WIDTH - x - 1) + (y * NEOPIXEL_WIDTH);                   // horizontal strip start from right top
     61     // int32_t i = ((y % 2) ? (NEOPIXEL_WIDTH - x - 1) : x) + (y * NEOPIXEL_WIDTH);   // horizontal zigzag strip start from right top
     62 
     63     _pixels->setPixelColor(i, RGB16TO24(color));
     64   }
     65 
     66   void endWrite(void) override
     67   {
     68     _pixels->show();
     69   }
     70 
     71   Adafruit_NeoPixel *_pixels;
     72 };
     73 
     74 #endif // _ADAFRUIT_NEOPIXEL_GFX_H_