snapshot
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Adafruit NeoPixel GFX Example
|
||||
* This is a simple GFX example for Adafruit_NeoPixel
|
||||
*
|
||||
* Dependent libraries:
|
||||
* Adafruit_NeoPixel: https://github.com/adafruit/Adafruit_NeoPixel.git
|
||||
******************************************************************************/
|
||||
#include <Arduino_GFX_Library.h>
|
||||
|
||||
// all settings in header file
|
||||
#include "Adafruit_NeoPixel_GFX.h"
|
||||
Arduino_GFX *gfx = new Adafruit_NeoPixel_GFX();
|
||||
int16_t x;
|
||||
uint16_t w, tw;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
// Serial.setDebugOutput(true);
|
||||
// while(!Serial);
|
||||
Serial.println("Arduino_GFX Adafruit_NeoPixel example");
|
||||
|
||||
// Init Display
|
||||
if (!gfx->begin())
|
||||
{
|
||||
Serial.println("gfx->begin() failed!");
|
||||
}
|
||||
gfx->fillScreen(RGB565_BLACK);
|
||||
|
||||
x = 0;
|
||||
gfx->setCursor(x, 0);
|
||||
gfx->setTextColor(RGB565_RED);
|
||||
gfx->println("Hello World!");
|
||||
|
||||
int16_t x1, y1;
|
||||
uint16_t h;
|
||||
gfx->getTextBounds("Hello World!", 0, 0, &x1, &y1, &w, &h);
|
||||
tw = w;
|
||||
w = gfx->width();
|
||||
|
||||
delay(1000); // 1 seconds
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
x--;
|
||||
if (x < (-tw))
|
||||
{
|
||||
x = w - 1;
|
||||
}
|
||||
gfx->setCursor(x, 0);
|
||||
gfx->setTextColor(random(0xffff), RGB565_BLACK);
|
||||
gfx->println("Hello World!");
|
||||
|
||||
delay(100); // 0.1 second
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#ifndef _ADAFRUIT_NEOPIXEL_GFX_H_
|
||||
#define _ADAFRUIT_NEOPIXEL_GFX_H_
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <Arduino_GFX.h>
|
||||
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||
#endif
|
||||
|
||||
// Which pin on the Arduino is connected to the NeoPixels?
|
||||
#define NEOPIXEL_PIN 1 // On Trinket or Gemma, suggest changing this to 1
|
||||
|
||||
#define NEOPIXEL_WIDTH 30
|
||||
#define NEOPIXEL_HEIGHT 8
|
||||
#define NUMPIXELS (NEOPIXEL_WIDTH * NEOPIXEL_HEIGHT)
|
||||
#define NEOPIXEL_BRIGHTNESS 3 // 1-255
|
||||
|
||||
// Pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define NEOPIXEL_TYPE (NEO_GRB + NEO_KHZ800)
|
||||
|
||||
class Adafruit_NeoPixel_GFX : public Arduino_GFX
|
||||
{
|
||||
public:
|
||||
Adafruit_NeoPixel_GFX() : Arduino_GFX(NEOPIXEL_WIDTH, NEOPIXEL_HEIGHT)
|
||||
{
|
||||
wrap = false;
|
||||
}
|
||||
|
||||
bool begin(int32_t speed = GFX_NOT_DEFINED) override
|
||||
{
|
||||
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||
// Any other board, you can remove this part (but no harm leaving it):
|
||||
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||
clock_prescale_set(clock_div_1);
|
||||
#endif
|
||||
// END of Trinket-specific code.
|
||||
_pixels = new Adafruit_NeoPixel(NUMPIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE);
|
||||
_pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||
_pixels->show(); // Turn OFF all pixels ASAP
|
||||
_pixels->setBrightness(NEOPIXEL_BRIGHTNESS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void writePixelPreclipped(int16_t x, int16_t y, uint16_t color) override
|
||||
{
|
||||
// select you matrix mode
|
||||
int32_t i = (x * NEOPIXEL_HEIGHT) + y; // vertical strip start from left top
|
||||
// int32_t i = (x * NEOPIXEL_HEIGHT) + ((x % 2) ? y : (NEOPIXEL_HEIGHT - y - 1)); // vertical zigzag strip start from left top
|
||||
// int32_t i = (x * NEOPIXEL_HEIGHT) + (NEOPIXEL_HEIGHT - y - 1); // vertical strip start from left bottom
|
||||
// int32_t i = (x * NEOPIXEL_HEIGHT) + ((x % 2) ? (NEOPIXEL_HEIGHT - y - 1) : y); // vertical zigzag strip start from left bottom
|
||||
// int32_t i = x + (y * NEOPIXEL_WIDTH); // horizontal strip start from left top
|
||||
// int32_t i = ((y % 2) ? x : (NEOPIXEL_WIDTH - x - 1)) + (y * NEOPIXEL_WIDTH); // horizontal zigzag strip start from left top
|
||||
// int32_t i = (NEOPIXEL_WIDTH - x - 1) + (y * NEOPIXEL_WIDTH); // horizontal strip start from right top
|
||||
// int32_t i = ((y % 2) ? (NEOPIXEL_WIDTH - x - 1) : x) + (y * NEOPIXEL_WIDTH); // horizontal zigzag strip start from right top
|
||||
|
||||
_pixels->setPixelColor(i, RGB16TO24(color));
|
||||
}
|
||||
|
||||
void endWrite(void) override
|
||||
{
|
||||
_pixels->show();
|
||||
}
|
||||
|
||||
Adafruit_NeoPixel *_pixels;
|
||||
};
|
||||
|
||||
#endif // _ADAFRUIT_NEOPIXEL_GFX_H_
|
||||
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* FastLED GFX Example
|
||||
* This is a simple GFX example for FastLED
|
||||
*
|
||||
* Dependent libraries:
|
||||
* FastLED: https://github.com/FastLED/FastLED.git
|
||||
******************************************************************************/
|
||||
#include <Arduino_GFX_Library.h>
|
||||
|
||||
// all settings in header file
|
||||
#include "FastLED_GFX.h"
|
||||
Arduino_GFX *gfx = new FastLED_GFX();
|
||||
int16_t x;
|
||||
uint16_t w, tw;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
// Serial.setDebugOutput(true);
|
||||
// while(!Serial);
|
||||
Serial.println("Arduino_GFX FastLED example");
|
||||
|
||||
// Init Display
|
||||
if (!gfx->begin())
|
||||
{
|
||||
Serial.println("gfx->begin() failed!");
|
||||
}
|
||||
gfx->fillScreen(RGB565_BLACK);
|
||||
|
||||
x = 0;
|
||||
gfx->setCursor(x, 0);
|
||||
gfx->setTextColor(RGB565_RED);
|
||||
gfx->println("Hello World!");
|
||||
|
||||
int16_t x1, y1;
|
||||
uint16_t h;
|
||||
gfx->getTextBounds("Hello World!", 0, 0, &x1, &y1, &w, &h);
|
||||
tw = w;
|
||||
w = gfx->width();
|
||||
|
||||
delay(1000); // 1 seconds
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
x--;
|
||||
if (x < (-tw))
|
||||
{
|
||||
x = w - 1;
|
||||
}
|
||||
gfx->setCursor(x, 0);
|
||||
gfx->setTextColor(random(0xffff), RGB565_BLACK);
|
||||
gfx->println("Hello World!");
|
||||
|
||||
delay(100); // 0.1 second
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef _FASTLED_GFX_H_
|
||||
#define _FASTLED_GFX_H_
|
||||
|
||||
#include <FastLED.h>
|
||||
#include <Arduino_GFX.h>
|
||||
|
||||
// Which pin on the Arduino is connected to the NeoPixels?
|
||||
#define NEOPIXEL_PIN 1
|
||||
|
||||
#define NEOPIXEL_WIDTH 30
|
||||
#define NEOPIXEL_HEIGHT 8
|
||||
#define NUMPIXELS (NEOPIXEL_WIDTH * NEOPIXEL_HEIGHT)
|
||||
#define NEOPIXEL_BRIGHTNESS 3 // 1-255
|
||||
|
||||
#define LED_TYPE WS2811
|
||||
#define COLOR_ORDER GRB
|
||||
|
||||
CRGB leds[NUMPIXELS];
|
||||
|
||||
class FastLED_GFX : public Arduino_GFX
|
||||
{
|
||||
public:
|
||||
FastLED_GFX() : Arduino_GFX(NEOPIXEL_WIDTH, NEOPIXEL_HEIGHT)
|
||||
{
|
||||
wrap = false;
|
||||
}
|
||||
|
||||
bool begin(int32_t speed = GFX_NOT_DEFINED) override
|
||||
{
|
||||
FastLED.addLeds<LED_TYPE, NEOPIXEL_PIN, COLOR_ORDER>(leds, NUMPIXELS).setCorrection(TypicalLEDStrip);
|
||||
FastLED.setBrightness(NEOPIXEL_BRIGHTNESS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void writePixelPreclipped(int16_t x, int16_t y, uint16_t color) override
|
||||
{
|
||||
// select you matrix mode
|
||||
int32_t i = (x * NEOPIXEL_HEIGHT) + y; // vertical strip start from left top
|
||||
// int32_t i = (x * NEOPIXEL_HEIGHT) + ((x % 2) ? y : (NEOPIXEL_HEIGHT - y - 1)); // vertical zigzag strip start from left top
|
||||
// int32_t i = (x * NEOPIXEL_HEIGHT) + (NEOPIXEL_HEIGHT - y - 1); // vertical strip start from left bottom
|
||||
// int32_t i = (x * NEOPIXEL_HEIGHT) + ((x % 2) ? (NEOPIXEL_HEIGHT - y - 1) : y); // vertical zigzag strip start from left bottom
|
||||
// int32_t i = x + (y * NEOPIXEL_WIDTH); // horizontal strip start from left top
|
||||
// int32_t i = ((y % 2) ? x : (NEOPIXEL_WIDTH - x - 1)) + (y * NEOPIXEL_WIDTH); // horizontal zigzag strip start from left top
|
||||
// int32_t i = (NEOPIXEL_WIDTH - x - 1) + (y * NEOPIXEL_WIDTH); // horizontal strip start from right top
|
||||
// int32_t i = ((y % 2) ? (NEOPIXEL_WIDTH - x - 1) : x) + (y * NEOPIXEL_WIDTH); // horizontal zigzag strip start from right top
|
||||
|
||||
leds[i] = RGB16TO24(color);
|
||||
}
|
||||
|
||||
void endWrite(void) override
|
||||
{
|
||||
FastLED.show();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _FASTLED_GFX_H_
|
||||
Reference in New Issue
Block a user