forked from patrickjahns/RGBWWLed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRGBWWLedOutput.h
More file actions
96 lines (74 loc) · 2.14 KB
/
RGBWWLedOutput.h
File metadata and controls
96 lines (74 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* RGBWWLed - simple Library for controlling RGB WarmWhite ColdWhite LEDs via PWM
* @file
* @author Patrick Jahns http://github.com/patrickjahns
*
* All files of this project are provided under the LGPL v3 license.
*/
#ifndef RGBWWLedOutput_h
#define RGBWWLedOutput_h
#include "RGBWWLed.h"
#ifdef RGBWW_USE_ESP_HWPWM
/*
* Use PWM Code from espressif sdk
* Provides a more stable pwm implementation compared to arduino esp
* framework
*/
extern "C" {
#include <pwm.h>
}
class PWMOutput
{
public:
PWMOutput(uint8_t redPin, uint8_t greenPin, uint8_t bluePin, uint8_t wwPin, uint8_t cwPin, uint16_t freq = 200);
void setFrequency(int freq);
int getFrequency();
void setRed(int value, bool update = true);
int getRed();
void setGreen(int value, bool update = true);
int getGreen();
void setBlue(int value, bool update = true);
int getBlue();
void setWarmWhite(int value, bool update = true);
int getWarmWhite();
void setColdWhite(int value, bool update = true);
int getColdWhite();
void setOutput(int red, int green, int blue, int warmwhite, int coldwhite);
private:
int parseDuty(int duty);
int _freq;
int _duty[RGBWW_CHANNELS::NUM_CHANNELS];
int _maxduty;
};
#else
/*
* If not using pwm implementation from espressif esp sdk
* we fallback to the standard arduino pwm implementation
*
*/
class PWMOutput
{
public:
PWMOutput(uint8_t redPin, uint8_t greenPin, uint8_t bluePin, uint8_t wwPin, uint8_t cwPin, uint16_t freq = 200);
void setFrequency(int freq);
int getFrequency();
void setRed(int value, bool update = true);
int getRed();
void setGreen(int value, bool update = true);
int getGreen();
void setBlue(int value, bool update = true);
int getBlue();
void setWarmWhite(int value, bool update = true);
int getWarmWhite();
void setColdWhite(int value, bool update = true);
int getColdWhite();
void setOutput(int red, int green, int blue, int warmwhite, int coldwhite);
private:
int _freq;
int _pins[RGBWW_CHANNELS::NUM_CHANNELS];
int _duty[RGBWW_CHANNELS::NUM_CHANNELS];
int _maxduty;
int parseDuty(int duty);
};
#endif //RGBWW_USE_ESP_HWPWM
#endif //RGBWWLedOutput_h