Compare commits
4 Commits
989eabee4a
...
3edbf6b252
Author | SHA1 | Date | |
---|---|---|---|
3edbf6b252 | |||
dc40653fea | |||
b65afde142 | |||
02b3bbcea8 |
@ -18,7 +18,10 @@ public:
|
|||||||
void clear(CRGB* color);
|
void clear(CRGB* color);
|
||||||
void setPixel(uint8_t x, uint8_t y, CRGB* color);
|
void setPixel(uint8_t x, uint8_t y, CRGB* color);
|
||||||
void setPixelByIndex(uint16_t index, CRGB* color);
|
void setPixelByIndex(uint16_t index, CRGB* color);
|
||||||
void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color, bool antialias=false);
|
void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color);
|
||||||
|
void lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t length, CRGB* color);
|
||||||
|
void lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t startdist, uint8_t length, CRGB* color);
|
||||||
|
void circle(uint8_t x, uint8_t y, uint8_t r, CRGB* color);
|
||||||
uint16_t coordsToGlobalIndex(uint8_t x, uint8_t y);
|
uint16_t coordsToGlobalIndex(uint8_t x, uint8_t y);
|
||||||
uint16_t localToGlobalIndex(uint16_t);
|
uint16_t localToGlobalIndex(uint16_t);
|
||||||
void drawChar(Font* f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
void drawChar(Font* f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
||||||
|
@ -30,9 +30,11 @@ public:
|
|||||||
|
|
||||||
class MatrixEffect : public Effect {
|
class MatrixEffect : public Effect {
|
||||||
private:
|
private:
|
||||||
MatrixEffectColumn columns[LED_WIDTH];
|
MatrixEffectColumn* _columns;
|
||||||
public:
|
public:
|
||||||
boolean can_be_shown_with_clock();
|
boolean can_be_shown_with_clock();
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
MatrixEffect();
|
MatrixEffect();
|
||||||
void loop();
|
void loop();
|
||||||
};
|
};
|
||||||
|
16
include/effect_pixelclock.h
Normal file
16
include/effect_pixelclock.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Effect.h"
|
||||||
|
#include "my_fastled.h"
|
||||||
|
|
||||||
|
class PixelClockEffect : public Effect {
|
||||||
|
private:
|
||||||
|
CRGB* _color_seconds;
|
||||||
|
CRGB* _color_minutes;
|
||||||
|
public:
|
||||||
|
PixelClockEffect();
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
void loop();
|
||||||
|
bool can_be_shown_with_clock();
|
||||||
|
};
|
@ -11,8 +11,6 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
lib_dir = lib
|
lib_dir = lib
|
||||||
env_default = ota
|
env_default = ota
|
||||||
lib_ldf_mode = chain+
|
|
||||||
|
|
||||||
|
|
||||||
[extra]
|
[extra]
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
@ -60,3 +60,75 @@ void Window::fadeToBlackBy(fract8 speed) {
|
|||||||
leds[coordsToGlobalIndex(x, y)].nscale8(255 - speed);
|
leds[coordsToGlobalIndex(x, y)].nscale8(255 - speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color) {
|
||||||
|
// Bresenham algorithm
|
||||||
|
int16_t dx = abs(x2-x1);
|
||||||
|
int16_t dy = abs(y2-y1);
|
||||||
|
int8_t sx = x1<x2 ? 1 : -1;
|
||||||
|
int8_t sy = y1<y2 ? 1 : -1;
|
||||||
|
int16_t err = dx + dy;
|
||||||
|
int16_t e2;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
setPixel(x1, y1, color);
|
||||||
|
if (x1==x2 && y1==y2) break;
|
||||||
|
e2 = 2*err;
|
||||||
|
if (e2 > dy) { err += dy; x1 += sx; }
|
||||||
|
if (e2 < dx) { err += dx; y1 += sy; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::circle(uint8_t x0, uint8_t y0, uint8_t radius, CRGB* color) {
|
||||||
|
// Again, Bresenham
|
||||||
|
uint8_t f = 1 - radius;
|
||||||
|
int16_t ddF_x = 0;
|
||||||
|
int16_t ddF_y = -2 * radius;
|
||||||
|
uint8_t x = 0;
|
||||||
|
uint8_t y = radius;
|
||||||
|
|
||||||
|
setPixel(x0, y0 + radius, color);
|
||||||
|
setPixel(x0, y0 - radius, color);
|
||||||
|
setPixel(x0 + radius, y0, color);
|
||||||
|
setPixel(x0 - radius, y0, color);
|
||||||
|
|
||||||
|
while (x < y) {
|
||||||
|
if (f >= 0) {
|
||||||
|
y--;
|
||||||
|
ddF_y += 2;
|
||||||
|
f += ddF_y;
|
||||||
|
}
|
||||||
|
x++;
|
||||||
|
ddF_x += 2;
|
||||||
|
f += ddF_x + 1;
|
||||||
|
|
||||||
|
setPixel(x0 + x, y0 + y, color);
|
||||||
|
setPixel(x0 - x, y0 + y, color);
|
||||||
|
setPixel(x0 + x, y0 - y, color);
|
||||||
|
setPixel(x0 - x, y0 - y, color);
|
||||||
|
|
||||||
|
setPixel(x0 + y, y0 + x, color);
|
||||||
|
setPixel(x0 - y, y0 + x, color);
|
||||||
|
setPixel(x0 + y, y0 - x, color);
|
||||||
|
setPixel(x0 - y, y0 - x, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t length, CRGB* color) {
|
||||||
|
lineWithAngle(x, y, angle, 0, length, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t startdist, uint8_t length, CRGB* color) {
|
||||||
|
int16_t x1 = x;
|
||||||
|
int16_t y1 = y;
|
||||||
|
|
||||||
|
if (startdist > 0) {
|
||||||
|
x1 = x + scale8(startdist, cos8(angle));
|
||||||
|
y1 = y + scale8(startdist, sin8(angle));
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t x2 = x + scale8(startdist + length, cos8(angle));
|
||||||
|
int16_t y2 = y + scale8(startdist + length, sin8(angle));
|
||||||
|
|
||||||
|
line(x1, y1, x2, y2, color);
|
||||||
|
}
|
||||||
|
@ -55,10 +55,18 @@ void MatrixEffectColumn::loop() {
|
|||||||
boolean MatrixEffect::can_be_shown_with_clock() { return true; };
|
boolean MatrixEffect::can_be_shown_with_clock() { return true; };
|
||||||
|
|
||||||
MatrixEffect::MatrixEffect() {
|
MatrixEffect::MatrixEffect() {
|
||||||
for (int i=0; i<LED_WIDTH; i++) columns[i] = MatrixEffectColumn(window, i);
|
}
|
||||||
|
|
||||||
|
void MatrixEffect::start() {
|
||||||
|
_columns = new MatrixEffectColumn[LED_WIDTH];
|
||||||
|
for (int i=0; i<LED_WIDTH; i++) _columns[i] = MatrixEffectColumn(window, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MatrixEffect::stop() {
|
||||||
|
delete[] _columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MatrixEffect::loop() {
|
void MatrixEffect::loop() {
|
||||||
window->clear();
|
window->clear();
|
||||||
for (int i=0; i<window->width; i++) columns[i].loop();
|
for (int i=0; i<window->width; i++) _columns[i].loop();
|
||||||
}
|
}
|
||||||
|
37
src/effect_pixelclock.cpp
Normal file
37
src/effect_pixelclock.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "effect_pixelclock.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
|
||||||
|
PixelClockEffect::PixelClockEffect() {
|
||||||
|
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-7);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelClockEffect::start() {
|
||||||
|
_color_seconds = new CRGB(0x00FF00);
|
||||||
|
_color_minutes = new CRGB(0xFFFF00);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelClockEffect::stop() {
|
||||||
|
delete _color_seconds;
|
||||||
|
delete _color_minutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelClockEffect::loop() {
|
||||||
|
uint8_t x, y; // Temporary variables for calculating positions
|
||||||
|
window->clear();
|
||||||
|
// Seconds
|
||||||
|
uint8_t seconds = ntpClient.getSeconds();
|
||||||
|
for (uint8_t s=0; s<60; s++) {
|
||||||
|
x = window->width - 1 - s/10;
|
||||||
|
y = window->height - 1 - (s % 10);
|
||||||
|
if (s<=seconds) window->setPixel(x, y, _color_seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t minutes = ntpClient.getMinutes();
|
||||||
|
for (uint8_t m=0; m<60; m++) {
|
||||||
|
x = 6 - m/10;
|
||||||
|
y = window->height - 1 - (m % 10);
|
||||||
|
if (m<=minutes) window->setPixel(x, y, _color_seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PixelClockEffect::can_be_shown_with_clock() { return true; }
|
@ -17,6 +17,7 @@
|
|||||||
#include "effect_fire.h"
|
#include "effect_fire.h"
|
||||||
#include "effect_firework.h"
|
#include "effect_firework.h"
|
||||||
#include "effect_gol.h"
|
#include "effect_gol.h"
|
||||||
|
#include "effect_pixelclock.h"
|
||||||
|
|
||||||
SimpleList<EffectEntry>* effects;
|
SimpleList<EffectEntry>* effects;
|
||||||
SimpleList<Effect*>* cycle_effects;
|
SimpleList<Effect*>* cycle_effects;
|
||||||
@ -41,6 +42,7 @@ SnakeEffect effect_snake;
|
|||||||
FireEffect effect_fire;
|
FireEffect effect_fire;
|
||||||
FireworkEffect effect_firework;
|
FireworkEffect effect_firework;
|
||||||
GolEffect effect_gol;
|
GolEffect effect_gol;
|
||||||
|
PixelClockEffect effect_pixelclock;
|
||||||
|
|
||||||
Effect* current_effect;
|
Effect* current_effect;
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ void setup_effects() {
|
|||||||
effects->add((EffectEntry){"firework", (Effect *)&effect_firework});
|
effects->add((EffectEntry){"firework", (Effect *)&effect_firework});
|
||||||
effects->add((EffectEntry){"gol", (Effect *)&effect_gol});
|
effects->add((EffectEntry){"gol", (Effect *)&effect_gol});
|
||||||
effects->add((EffectEntry){"cake", (Effect *)&effect_anim_cake});
|
effects->add((EffectEntry){"cake", (Effect *)&effect_anim_cake});
|
||||||
|
effects->add((EffectEntry){"pixel_clock", (Effect *)&effect_pixelclock});
|
||||||
|
|
||||||
cycle_effects->add(&effect_sinematrix3);
|
cycle_effects->add(&effect_sinematrix3);
|
||||||
cycle_effects->add(&effect_multi_dynamic);
|
cycle_effects->add(&effect_multi_dynamic);
|
||||||
|
Loading…
Reference in New Issue
Block a user