mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +00:00
Added scan_length to AddressableScanEffect (allow more than one LED)
This commit is contained in:
parent
ebe64e24f1
commit
308bfc3601
@ -145,12 +145,16 @@ class AddressableScanEffect : public AddressableLightEffect {
|
|||||||
void set_move_interval(uint32_t move_interval) { this->move_interval_ = move_interval; }
|
void set_move_interval(uint32_t move_interval) { this->move_interval_ = move_interval; }
|
||||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||||
it.all() = ESPColor::BLACK;
|
it.all() = ESPColor::BLACK;
|
||||||
it[this->at_led_] = current_color;
|
|
||||||
|
for (auto i = 0; i < this->scan_length_; i++) {
|
||||||
|
it[this->at_led_ + i] = current_color;
|
||||||
|
}
|
||||||
|
|
||||||
const uint32_t now = millis();
|
const uint32_t now = millis();
|
||||||
if (now - this->last_move_ > this->move_interval_) {
|
if (now - this->last_move_ > this->move_interval_) {
|
||||||
if (direction_) {
|
if (direction_) {
|
||||||
this->at_led_++;
|
this->at_led_++;
|
||||||
if (this->at_led_ == it.size() - 1)
|
if (this->at_led_ == it.size() - scan_length_)
|
||||||
this->direction_ = false;
|
this->direction_ = false;
|
||||||
} else {
|
} else {
|
||||||
this->at_led_--;
|
this->at_led_--;
|
||||||
@ -163,6 +167,7 @@ class AddressableScanEffect : public AddressableLightEffect {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t move_interval_{};
|
uint32_t move_interval_{};
|
||||||
|
uint32_t scan_length_{10}; //TODO check less than it.size()
|
||||||
uint32_t last_move_{0};
|
uint32_t last_move_{0};
|
||||||
int at_led_{0};
|
int at_led_{0};
|
||||||
bool direction_{true};
|
bool direction_{true};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user