diff --git a/examples/OrangeLED/OrangeLED.ino b/examples/OrangeLED/OrangeLED.ino index 31b1e89..034539e 100644 --- a/examples/OrangeLED/OrangeLED.ino +++ b/examples/OrangeLED/OrangeLED.ino @@ -8,15 +8,15 @@ void pulseLED(OrangeLED& led) { // Fade in - for (uint8_t i = 0; i < 64; ++i) { + for (uint8_t i = 0; i < 255; ++i) { led.setBrightness(i); - delay(10); + delay(4); } // Fade out - for (int8_t i = 63; i >= 0; --i) { + for (int8_t i = 255; i >= 0; --i) { led.setBrightness(i); - delay(10); + delay(4); } } diff --git a/src/OrangeLED.cpp b/src/OrangeLED.cpp index 544e5b3..e28937b 100644 --- a/src/OrangeLED.cpp +++ b/src/OrangeLED.cpp @@ -7,17 +7,19 @@ OrangeLED::OrangeLED(uint8_t deviceAddress) : I2CDevice(deviceAddress) {} uint8_t OrangeLED::brightness() { // Read bits 0 - 5 from orange_led register uint8_t data = readFromRegister(ORANGE_LED_REGISTER_INFO); - return data & 63; + uint8_t brightness = data & 63; + return map(brightness, 0, 63, 0, 255); } void OrangeLED::setBrightness(uint8_t brightness) { - if (brightness > 63) { + if (brightness > 255) { return; // Invalid brightness value } + uint8_t mappedBrightness = map(brightness, 0, 255, 0, 63); uint8_t currentRegisterData = readFromRegister(ORANGE_LED_REGISTER_INFO); // Overwrite bits 0 - 5 with the new value - writeToRegister(ORANGE_LED_REGISTER_INFO, (currentRegisterData & ~63) | brightness); + writeToRegister(ORANGE_LED_REGISTER_INFO, (currentRegisterData & ~63) | mappedBrightness); } bool OrangeLED::errorStatusEnabled() { diff --git a/src/OrangeLED.h b/src/OrangeLED.h index d09941b..d79e2cb 100644 --- a/src/OrangeLED.h +++ b/src/OrangeLED.h @@ -26,7 +26,7 @@ class OrangeLED : public I2CDevice { /** * Gets the brightness of the orange LED. - * @return The brightness of the orange LED. Range is 0 to 63. + * @return The brightness of the orange LED. Range is 0 to 255. */ uint8_t brightness();