Added setOnColor to Pixel

Allows user to set the color to be used for Blinker
This commit is contained in:
Gregg 2022-09-03 16:47:02 -05:00
parent 355a2dfd4d
commit 546c87e3ec
4 changed files with 27 additions and 20 deletions

View File

@ -42,21 +42,6 @@ class Blinkable {
virtual int getPin()=0;
};
////////////////////////////////
// Generic_LED //
////////////////////////////////
class LED : public Blinkable {
int pin;
public:
LED(int pin) : pin{pin} {pinMode(pin,OUTPUT);digitalWrite(pin,0);}
void on() {digitalWrite(pin,HIGH);}
void off() {digitalWrite(pin,LOW);}
int getPin() {return(pin);}
};
////////////////////////////////
// Blinker //
////////////////////////////////

View File

@ -58,7 +58,9 @@ Pixel::Pixel(int pin, boolean isRGBW){
rmt_set_tx_intr_en(rf->getChannel(),false); // disable end-of-transmission interrupt
txEndMask=RMT.int_ena.val; // save interrupt enable vector
rmt_set_tx_intr_en(rf->getChannel(),true); // enable end-of-transmission interrupt
txEndMask^=RMT.int_ena.val; // find bit that flipped and save as end-of-transmission mask for this channel
txEndMask^=RMT.int_ena.val; // find bit that flipped and save as end-of-transmission mask for this channel
onColor.HSV(0,100,100,0);
}
///////////////////

View File

@ -132,13 +132,14 @@ class Pixel : public Blinkable {
uint32_t txEndMask; // mask for end-of-transmission interrupt
uint32_t txThrMask; // mask for threshold interrupt
uint32_t lastBit; // 0=RGBW; 8=RGB
Color onColor; // color used for on() command
const int memSize=sizeof(RMTMEM.chan[0].data32)/4; // determine size (in pulses) of one channel
static void loadData(void *arg); // interrupt handler
volatile static pixel_status_t status; // storage for volatile information modified in interupt handler
public:
public:
Pixel(int pin, boolean isRGBW=false); // creates addressable single-wire RGB (false) or RGBW (true) LED connected to pin (such as the SK68 or WS28)
void set(Color *c, int nPixels, boolean multiColor=true); // sets colors of nPixels based on array of Colors c; setting multiColor to false repeats Color in c[0] for all nPixels
void set(Color c, int nPixels=1){set(&c,nPixels,false);} // sets color of nPixels to be equal to specific Color c
@ -153,8 +154,9 @@ class Pixel : public Blinkable {
return(*rf);
}
void on() {set(RGB(255,0,0));}
void off() {set(RGB(0,0,0));}
void on() {set(onColor);}
void off() {set(RGB(0,0,0,0));}
Pixel *setOnColor(Color c){onColor=c;return(this);}
};
////////////////////////////////////////////

View File

@ -44,6 +44,7 @@
#include <Arduino.h>
#include <driver/ledc.h>
#include "Blinker.h"
#define DEFAULT_PWM_FREQ 5000
@ -80,7 +81,24 @@ class LedPin : public LedC {
static void HSVtoRGB(float h, float s, float v, float *r, float *g, float *b ); // converts Hue/Saturation/Brightness to R/G/B
};
/////////////////////////////////////
////////////////////////////////
// LED //
////////////////////////////////
class LED : public Blinkable {
int pin;
public:
LED(int pin) : pin{pin} {pinMode(pin,OUTPUT);digitalWrite(pin,0);}
void on() {digitalWrite(pin,HIGH);}
void off() {digitalWrite(pin,LOW);}
int getPin() {return(pin);}
};
////////////////////////////////
// ServoPin //
////////////////////////////////
class ServoPin : public LedC {
uint16_t minMicros;