Added Pixel.h and Pixel.cpp and implemented SK68XX Addressable LED Class
Also add getPin() to RFControl (which is used by SK68XX Class) as well as boolean operator overrides for both RFControl and PwmPin/ServoPin so that instances can be checked for validity.
This commit is contained in:
parent
ec4312e2f6
commit
facba4c02a
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
#include "Pixel.h"
|
||||
|
||||
///////////////////
|
||||
|
||||
sk68xx::sk68xx(int pin){
|
||||
rf=new RFControl(pin,false);
|
||||
setRGB(0,0,0);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
|
||||
void sk68xx::setRGB(uint8_t r, uint8_t g, uint8_t b){
|
||||
|
||||
if(!*rf)
|
||||
return;
|
||||
|
||||
rf->clear();
|
||||
loadColor(g);
|
||||
loadColor(r);
|
||||
loadColor(b);
|
||||
rf->phase(6400,0); // add 80 usec end-marker delay
|
||||
rf->start();
|
||||
}
|
||||
|
||||
///////////////////
|
||||
|
||||
void sk68xx::loadColor(uint8_t c){
|
||||
|
||||
for(int i=7;i>=0;i--){
|
||||
if((c>>i)&1)
|
||||
rf->add(51,45);
|
||||
else
|
||||
rf->add(26,70);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
////////////////////////////////////
|
||||
// Addressable LED Pixel //
|
||||
////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RFControl.h"
|
||||
|
||||
class sk68xx {
|
||||
private:
|
||||
int pin=-1;
|
||||
RFControl *rf;
|
||||
void loadColor(uint8_t c);
|
||||
|
||||
public:
|
||||
sk68xx(int pin); // creates addressable SK68XX RGB LED on pin
|
||||
void setRGB(uint8_t r, uint8_t g, uint8_t b); // sets color to rgb values (0-255)
|
||||
int getPin(){return(rf->getPin());} // returns pin number
|
||||
|
||||
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
|
||||
return(*rf);
|
||||
}
|
||||
};
|
||||
|
|
@ -14,6 +14,8 @@
|
|||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <driver/ledc.h>
|
||||
|
||||
|
|
@ -34,6 +36,10 @@ class LedC {
|
|||
|
||||
public:
|
||||
int getPin(){return(channel?channel->gpio_num:-1);} // returns the pin number
|
||||
|
||||
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
|
||||
return(channel);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <soc/rmt_reg.h>
|
||||
|
||||
#include "RFControl.h"
|
||||
|
||||
///////////////////
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
// RF Control Module //
|
||||
////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <soc/rmt_reg.h>
|
||||
#include "driver/rmt.h"
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -27,6 +31,12 @@ class RFControl {
|
|||
void phase(uint32_t nTicks, uint8_t phase); // adds either a HIGH phase or LOW phase lasting numTicks ticks
|
||||
void enableCarrier(uint32_t freq, float duty=0.5); // enables carrier wave if freq>0, else disables carrier wave; duty is a fraction from 0-1
|
||||
void disableCarrier(){enableCarrier(0);} // disables carrier wave
|
||||
|
||||
int getPin(){return(config?config->gpio_num:-1);} // returns the pin number
|
||||
|
||||
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
|
||||
return(config);
|
||||
}
|
||||
};
|
||||
|
||||
// Helper macro for creating your own storage of uint32_t data array elements - used with first variation of start() above
|
||||
|
|
|
|||
|
|
@ -1,14 +1,6 @@
|
|||
/* HomeSpan Remote Control Example */
|
||||
/* HomeSpan Pixel Example */
|
||||
|
||||
#include "RFControl.h" // include RF Control Library
|
||||
|
||||
#define PRONTO_N 0.241246
|
||||
|
||||
uint16_t pronto[]={0000,0x006D,0x0000,0x0022,0x00AC,0x00AC,0x0015,0x0040,0x0015,0x0040,0x0015,0x0040,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0040,0x0015,0x0040,0x0015,0x0040,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0015,0x0040,0x0015,0x0015,0x0015,0x0015,0x0015,0x0040,0x0015,0x0040,0x0015,0x0015,0x0015,0x0015,0x0015,0x0040,0x0015,0x0015,0x0015,0x0040,0x0015,0x0040,0x0015,0x0015,0x0015,0x0015,0x0015,0x0040,0x0015,0x0040,0x0015,0x0015,0x0015,0x0689};
|
||||
//uint16_t pronto[]={0000,0x006D,0x0000,0x0022,0x00AC,0x00AC,0x0017,0x003E,0x0017,0x003E,0x0017,0x003E,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x003E,0x0017,0x003E,0x0017,0x003E,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x0013,0x0017,0x003E,0x0017,0x003E,0x0017,0x0013,0x0017,0x0013,0x0017,0x003E,0x0017,0x003E,0x0018,0x003E,0x0017,0x003E,0x0017,0x0013,0x0017,0x0013,0x0017,0x003E,0x0017,0x003E,0x0017,0x0013,0x0017,0x0746};
|
||||
//uint16_t pronto[]={0000,0x0067,0x0000,0x000d,0x0060,0x0018,0x0018,0x0018,0x0030,0x0018,0x0030,0x0018,0x0030,0x0018,0x0018,0x0018,0x0030,0x0018,0x0018,0x0018,0x0030,0x0018,0x0018,0x0018,0x0018,0x0018,0x0018,0x0018,0x0018,0x03f6};
|
||||
|
||||
uint32_t data[100];
|
||||
#include "Pixel.h"
|
||||
|
||||
void setup() {
|
||||
|
||||
|
|
@ -16,29 +8,27 @@ void setup() {
|
|||
Serial.flush();
|
||||
delay(1000); // wait for interface to flush
|
||||
|
||||
Serial.println("\n\nHomeSpan RF Transmitter Example\n\n");
|
||||
Serial.println("\n\nHomeSpan Pixel Example\n\n");
|
||||
|
||||
RFControl rf(17);
|
||||
rf.enableCarrier(38000,0.5);
|
||||
sk68xx px(8);
|
||||
sk68xx test7(7);
|
||||
sk68xx test6(6);
|
||||
|
||||
uint32_t code = 0xE0E019E6; // OFF
|
||||
// uint32_t code = 0xE0E09966; // ON
|
||||
Serial.printf("PX on Pin=%d check: %s\n",px.getPin(),px?"OKAY":"BAD");
|
||||
Serial.printf("Test 7 on Pin=%d check: %s\n",test7.getPin(),test7?"OKAY":"BAD");
|
||||
Serial.printf("Test 6 on Pin=%d check: %s\n",test6.getPin(),test6?"OKAY":"BAD");
|
||||
|
||||
int unit=563;
|
||||
|
||||
rf.add(4500,4500);
|
||||
|
||||
for(int i=31;i>=0;i--){
|
||||
rf.add(unit,unit*((code&(1<<i))?3:1));
|
||||
Serial.print((code&(1<<i))?1:0);
|
||||
if(!(i%8))
|
||||
Serial.print(" ");
|
||||
while(1){
|
||||
for(int i=0;i<50;i++){
|
||||
px.setRGB(i,0,0);
|
||||
delay(2);
|
||||
}
|
||||
for(int i=50;i>=0;i--){
|
||||
px.setRGB(i,0,0);
|
||||
delay(2);
|
||||
}
|
||||
}
|
||||
|
||||
rf.add(unit,45000);
|
||||
|
||||
rf.start(2);
|
||||
|
||||
Serial.println("Done!");
|
||||
|
||||
} // end of setup()
|
||||
|
|
|
|||
Loading…
Reference in New Issue