A feature complete driver for the PCA9952/55 LED driver from NXP.
Dependents: PCA9955_HelloWorld
Diff: PCA9955.cpp
- Revision:
- 9:a9f91f91633b
- Parent:
- 8:12a800c51b35
- Child:
- 10:c8c96c894ec6
--- a/PCA9955.cpp Tue Apr 08 20:31:22 2014 +0000 +++ b/PCA9955.cpp Mon Apr 28 04:52:08 2014 +0000 @@ -320,19 +320,19 @@ float PCA9955::groupDuty() { //Return the value as a float - return groupDuty_char() / 255.0f; + return groupDuty_char() / 255.0; } void PCA9955::groupDuty(float duty, int altAddr) { //Range check the value - if (duty < 0.0f) - duty = 0.0f; - if (duty > 1.0f) - duty = 1.0f; + if (duty < 0.0) + duty = 0.0; + if (duty > 1.0) + duty = 1.0; //Convert the value to a char and write it - groupDuty_char((char)(duty * 255.0f), altAddr); + groupDuty_char((char)(duty * 255.0), altAddr); } char PCA9955::groupDuty_char() @@ -354,11 +354,11 @@ //Return the period in seconds if (value == 0x00) - return 0.067f; + return 0.067; else if (value == 0xFF) - return 16.8f; + return 16.8; else - return (value + 1) / 15.26f; + return (value + 1) / 15.26; } void PCA9955::groupBlinkPeriod(float period, int altAddr) @@ -366,9 +366,9 @@ char value = 0; //Do a smart conversion - if (period > 0.067f) { - if (period < 16.8f) - value = (char)((period * 15.26f) - 1); + if (period > 0.067) { + if (period < 16.8) + value = (char)((period * 15.26) - 1); else value = 0xFF; } @@ -392,19 +392,19 @@ float PCA9955::outputDuty(Output output) { //Return the value as a float - return outputDuty_char(output) / 255.0f; + return outputDuty_char(output) / 255.0; } void PCA9955::outputDuty(Output output, float duty, int altAddr) { //Range check the value - if (duty < 0.0f) - duty = 0.0f; - if (duty > 1.0f) - duty = 1.0f; + if (duty < 0.0) + duty = 0.0; + if (duty > 1.0) + duty = 1.0; //Convert the value to a char and write it - outputDuty_char(output, (char)(duty * 255.0f), altAddr); + outputDuty_char(output, (char)(duty * 255.0), altAddr); } char PCA9955::outputDuty_char(Output output) @@ -422,19 +422,19 @@ float PCA9955::outputCurrent(Output output) { //Return the value as a float - return outputCurrent_char(output) / 255.0f; + return outputCurrent_char(output) / 255.0; } void PCA9955::outputCurrent(Output output, float iref, int altAddr) { //Range check the value - if (iref < 0.0f) - iref = 0.0f; - if (iref > 1.0f) - iref = 1.0f; + if (iref < 0.0) + iref = 0.0; + if (iref > 1.0) + iref = 1.0; //Convert the value to a char and write it - outputCurrent_char(output, (char)(iref * 255.0f), altAddr); + outputCurrent_char(output, (char)(iref * 255.0), altAddr); } char PCA9955::outputCurrent_char(Output output) @@ -538,7 +538,7 @@ //Convert all of the duty cycles to percents for (int i = 0; i < 16; i++) { - duties[i] = buff[i] / 255.0f; + duties[i] = buff[i] / 255.0; } } @@ -550,13 +550,13 @@ buff[0] = REG_PWM0 | REG_AUTO_INC; for (int i = 1; i < 17; i++) { //Range check the value - if (duties[i - 1] < 0.0f) - duties[i - 1] = 0.0f; - if (duties[i - 1] > 1.0f) - duties[i - 1] = 1.0f; + if (duties[i - 1] < 0.0) + duties[i - 1] = 0.0; + if (duties[i - 1] > 1.0) + duties[i - 1] = 1.0; //Convert the value to a char and write it - buff[i] = duties[i - 1] * 255.0f; + buff[i] = duties[i - 1] * 255.0; } //Send the array @@ -566,13 +566,13 @@ void PCA9955::allOutputDuties(float duty, int altAddr) { //Range check the value - if (duty < 0.0f) - duty = 0.0f; - if (duty > 1.0f) - duty = 1.0f; + if (duty < 0.0) + duty = 0.0; + if (duty > 1.0) + duty = 1.0; //Convert the value to a char and write it - allOutputDuties_char((char)(duty * 255.0f), altAddr); + allOutputDuties_char((char)(duty * 255.0), altAddr); } void PCA9955::getOutputDuties_char(char* duties) @@ -608,7 +608,7 @@ //Convert all of the duty cycles to percents for (int i = 0; i < 16; i++) { - irefs[i] = buff[i] / 255.0f; + irefs[i] = buff[i] / 255.0; } } @@ -620,13 +620,13 @@ buff[0] = REG_IREF0 | REG_AUTO_INC; for (int i = 1; i < 17; i++) { //Range check the value - if (irefs[i - 1] < 0.0f) - irefs[i - 1] = 0.0f; - if (irefs[i - 1] > 1.0f) - irefs[i - 1] = 1.0f; + if (irefs[i - 1] < 0.0) + irefs[i - 1] = 0.0; + if (irefs[i - 1] > 1.0) + irefs[i - 1] = 1.0; //Convert the value to a char and write it - buff[i] = irefs[i - 1] * 255.0f; + buff[i] = irefs[i - 1] * 255.0; } //Send the array @@ -636,13 +636,13 @@ void PCA9955::allOutputCurrents(float iref, int altAddr) { //Range check the value - if (iref < 0.0f) - iref = 0.0f; - if (iref > 1.0f) - iref = 1.0f; + if (iref < 0.0) + iref = 0.0; + if (iref > 1.0) + iref = 1.0; //Convert the value to a char and write it - allOutputCurrents_char((char)(iref * 255.0f), altAddr); + allOutputCurrents_char((char)(iref * 255.0), altAddr); } void PCA9955::getOutputCurrents_char(char* irefs)