2022-01-06 14:09:06 -05:00
|
|
|
//
|
|
|
|
// FILE: PCA9634_test01.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-05-16 12:24:33 -04:00
|
|
|
// PURPOSE: test PCA9634 library
|
2023-12-11 07:54:15 -05:00
|
|
|
// URL: https://github.com/RobTillaart/PCA9634
|
2022-01-06 14:09:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
#include "PCA9634.h"
|
|
|
|
|
|
|
|
|
|
|
|
PCA9634 ledArray(0x20);
|
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2023-12-11 07:54:15 -05:00
|
|
|
Serial.println(__FILE__);
|
2022-01-06 14:09:06 -05:00
|
|
|
Serial.print("PCA9634 LIB version: ");
|
|
|
|
Serial.println(PCA9634_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
|
2023-12-11 07:54:15 -05:00
|
|
|
Wire.begin();
|
|
|
|
|
2022-01-06 14:09:06 -05:00
|
|
|
ledArray.begin();
|
|
|
|
|
|
|
|
testSetLedDriverModeLEDON();
|
|
|
|
testPWMMode();
|
|
|
|
testWrite1();
|
|
|
|
testWrite3();
|
|
|
|
testWriteN();
|
|
|
|
testSetGroupPWM_FREQ();
|
|
|
|
testSetAndReadMode();
|
|
|
|
testSetLedDriverModeLEDOFF();
|
|
|
|
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("done...");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testSetLedDriverModeLEDON()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - Switch all on");
|
|
|
|
for (int channel = 0; channel < ledArray.channelCount(); channel++)
|
|
|
|
{
|
2023-05-07 12:57:37 -04:00
|
|
|
ledArray.setLedDriverMode(channel, PCA963X_LEDON);
|
|
|
|
if (ledArray.getLedDriverMode(channel) != PCA963X_LEDON)
|
2022-01-06 14:09:06 -05:00
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print("Channel: ");
|
|
|
|
Serial.println(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testPWMMode()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - set pwm mode");
|
|
|
|
for (int channel = 0; channel < ledArray.channelCount(); channel++)
|
|
|
|
{
|
2023-05-07 12:57:37 -04:00
|
|
|
ledArray.setLedDriverMode(channel, PCA963X_LEDON);
|
2022-01-06 14:09:06 -05:00
|
|
|
delay(200);
|
2023-05-07 12:57:37 -04:00
|
|
|
ledArray.setLedDriverMode(channel, PCA963X_LEDPWM);
|
|
|
|
if (ledArray.getLedDriverMode(channel) != PCA963X_LEDPWM)
|
2022-01-06 14:09:06 -05:00
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print("Channel: ");
|
|
|
|
Serial.println(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testWrite1()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - write1 - I");
|
|
|
|
for (int channel = 0; channel < ledArray.channelCount(); channel++)
|
|
|
|
{
|
|
|
|
for (int pwm = 0; pwm < 256; pwm++)
|
|
|
|
{
|
|
|
|
ledArray.write1(channel, pwm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - write 1 - II");
|
|
|
|
for (int pwm = 0; pwm < 256; pwm++)
|
|
|
|
{
|
|
|
|
for (int channel = 0; channel < ledArray.channelCount(); channel++)
|
|
|
|
{
|
|
|
|
ledArray.write1(channel, pwm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testWrite3()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - write3 - random RGB");
|
|
|
|
for (int channel = 0; channel < ledArray.channelCount() - 3; channel++)
|
|
|
|
{
|
|
|
|
uint8_t R = random(256);
|
|
|
|
uint8_t G = random(256);
|
|
|
|
uint8_t B = random(256);
|
|
|
|
ledArray.write3(channel, R, G, B);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testWriteN()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
2022-05-19 06:33:49 -04:00
|
|
|
Serial.println("Test - writeN");
|
|
|
|
uint8_t arr[8] = {16, 32, 64, 96, 128, 160, 192, 255};
|
|
|
|
ledArray.writeN(0, arr, 8); // 8 == ledArray.channelCount()
|
2022-01-06 14:09:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testSetGroupPWM_FREQ()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - GroupPWM");
|
|
|
|
for (int channel = 0; channel < ledArray.channelCount(); channel++)
|
|
|
|
{
|
2023-05-07 12:57:37 -04:00
|
|
|
ledArray.setLedDriverMode(channel, PCA963X_LEDGRPPWM);
|
2022-01-06 14:09:06 -05:00
|
|
|
}
|
|
|
|
for (int pwm = 0; pwm < 256; pwm++)
|
|
|
|
{
|
|
|
|
ledArray.setGroupPWM(pwm);
|
|
|
|
uint8_t p = ledArray.getGroupPWM();
|
|
|
|
if (p != pwm)
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print("pwm: ");
|
|
|
|
Serial.println(pwm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ledArray.setGroupPWM(127);
|
|
|
|
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - groupFRQ");
|
|
|
|
for (int frq = 0; frq < 256; frq++)
|
|
|
|
{
|
|
|
|
ledArray.setGroupFREQ(frq);
|
|
|
|
uint8_t f = ledArray.getGroupFREQ();
|
|
|
|
if (f != frq)
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print("frq: ");
|
|
|
|
Serial.println(frq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 06:37:16 -04:00
|
|
|
// reset to LEDPWM
|
2022-01-06 14:09:06 -05:00
|
|
|
for (int channel = 0; channel < ledArray.channelCount(); channel++)
|
|
|
|
{
|
2023-05-07 12:57:37 -04:00
|
|
|
ledArray.setLedDriverMode(channel, PCA963X_LEDPWM);
|
2022-01-06 14:09:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testSetAndReadMode()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - readMode");
|
2023-05-07 12:57:37 -04:00
|
|
|
uint8_t regval = ledArray.readMode(PCA963X_MODE1);
|
|
|
|
ledArray.writeMode(PCA963X_MODE1, regval); // non destructive;
|
2022-01-06 14:09:06 -05:00
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
2023-05-07 12:57:37 -04:00
|
|
|
Serial.print("PCA963X_MODE1: ");
|
2022-01-06 14:09:06 -05:00
|
|
|
Serial.println(regval);
|
2023-05-07 12:57:37 -04:00
|
|
|
regval = ledArray.readMode(PCA963X_MODE2);
|
|
|
|
ledArray.writeMode(PCA963X_MODE2, regval);
|
2022-01-06 14:09:06 -05:00
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
2023-05-07 12:57:37 -04:00
|
|
|
Serial.print("PCA963X_MODE2: ");
|
2022-01-06 14:09:06 -05:00
|
|
|
Serial.println(regval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testSetLedDriverModeLEDOFF()
|
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println("Test - Switch all off");
|
|
|
|
for (int channel = 0; channel < ledArray.channelCount(); channel++)
|
|
|
|
{
|
2023-05-07 12:57:37 -04:00
|
|
|
ledArray.setLedDriverMode(channel, PCA963X_LEDOFF);
|
|
|
|
if (ledArray.getLedDriverMode(channel) != PCA963X_LEDOFF)
|
2022-01-06 14:09:06 -05:00
|
|
|
{
|
|
|
|
Serial.print(millis());
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print("Channel: ");
|
|
|
|
Serial.println(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-14 06:37:16 -04:00
|
|
|
// -- END OF FILE --
|
2022-01-06 14:09:06 -05:00
|
|
|
|