working version 1
This commit is contained in:
@@ -5,11 +5,15 @@ Pin::Pin(int pinNumber, bool isOutput, bool isLed, uint32_t ledFrequency, uint8_
|
||||
: pinNumber(pinNumber), output(isOutput), isLed(isLed), ledChannel(ledChannel) {
|
||||
pinMode(pinNumber, isOutput ? OUTPUT : INPUT);
|
||||
if (isLed) {
|
||||
ledcSetup(ledChannel, ledFrequency, 8); // Setup LEDC for PWM with 8-bit resolution
|
||||
ledcSetup(ledChannel, ledFrequency, ledResolutionBits); // Setup LEDC for PWM with 8-bit resolution
|
||||
ledcAttachPin(pinNumber, ledChannel); // Attach the pin to the LEDC channel
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t Pin::getLedResolutionBits() const {
|
||||
return ledResolutionBits;
|
||||
}
|
||||
|
||||
void Pin::setHigh() {
|
||||
if (output) {
|
||||
digitalWrite(pinNumber, HIGH);
|
||||
@@ -25,8 +29,12 @@ void Pin::setLow() {
|
||||
void Pin::setLedLevel(uint32_t level) {
|
||||
if (output && isLed) {
|
||||
ledcWrite(ledChannel, level);
|
||||
ledLevel = level;
|
||||
}
|
||||
// analogWrite(pinNumber, level); // Use analogWrite for PWM control
|
||||
}
|
||||
|
||||
uint32_t Pin::getLedLevel() const {
|
||||
return ledLevel;
|
||||
}
|
||||
|
||||
bool Pin::read() {
|
||||
|
||||
@@ -6,6 +6,8 @@ public:
|
||||
void setHigh();
|
||||
void setLow();
|
||||
void setLedLevel(uint32_t level);
|
||||
uint32_t getLedLevel() const;
|
||||
const uint8_t getLedResolutionBits() const;
|
||||
bool read();
|
||||
int getPinNumber() const;
|
||||
bool isOutput() const;
|
||||
@@ -13,6 +15,8 @@ public:
|
||||
private:
|
||||
uint8_t ledChannel = 0; // LED channel for PWM
|
||||
uint8_t pinNumber;
|
||||
uint32_t ledLevel = 0;
|
||||
const uint8_t ledResolutionBits = 12;
|
||||
bool output;
|
||||
bool isLed = false; // Flag to indicate if this pin is used for LED control
|
||||
};
|
||||
Reference in New Issue
Block a user