Make an internal function to change LED state
Closed this issue · 1 comments
ggoraa commented
Thoughts:
class MorsDuinoRgbLed {
private:
// Thos functions will save current state of LED
int _redColorBuffer;
int _greenColorBuffer;
int _blueColorBuffer;
// Actual function to turn off LED
void _changeState(bool state);
}
void MorsDuinoRgbLed::_changeState(bool state) {
if (state) {
analogWrite(_redPin, _redColorBuffer);
analogWrite(_greenPin, _greenColorBuffer);
analogWrite(_bluePin, _blueColorBuffer);
} else {
analogWrite(_redPin, 0);
analogWrite(_greenPin, 0);
analogWrite(_bluePin, 0);
}
}
And when it changes colors:
void MorsDuinoRgbLed::displayInt(int number, char color) {
String numbers = String(number);
size_t numberOfElements = sizeof(numbers) / sizeof(numbers[0]);
for (int i = 0; i <= numberOfElements; i++) {
MorsDuinoRgbLed::displayChar(numbers[i]);
}
}
void MorsDuinoRgbLed(char character, char color) {
/* "switch case" code that represents morse code table */
}
And a separate function that will be implemented in _dot()
and _dash()
functions:
void MorsDuinoRgbLed::_drawColor(char color) {
int redColor = ((color >> 16) & 0xFF) / 255.0; // Extract the RR byte
int greenColor = ((color >> 8) & 0xFF) / 255.0; // Extract the GG byte
int blueColor = ((color)&0xFF) / 255.0; // Extract the BB byte
// Save color values
_redColorBuffer = redColor;
_greenColorBuffer = greenColor;
_blueColorBuffer = blueColor;
// Show colors
analogWrite(_redPin, redColor);
analogWrite(_greenPin, greenColor);
analogWrite(_bluePin, blueColor);
}
Using this code you can turn LED on and off
ggoraa commented
Done