224 lines
4.7 KiB
Arduino
Raw Normal View History

2016-04-24 08:26:22 +02:00
//
// FILE: PCA9635_test01.ino
// AUTHOR: Rob Tillaart
// DATE: 23-APR-2016
2022-05-16 18:25:10 +02:00
// PURPOSE: test PCA9635 library
2021-12-23 10:41:42 +01:00
2016-04-24 08:26:22 +02:00
2022-01-06 20:19:35 +01:00
#include "Arduino.h"
#include "Wire.h"
2016-04-24 08:26:22 +02:00
#include "PCA9635.h"
2022-01-06 20:19:35 +01:00
2016-04-24 08:26:22 +02:00
PCA9635 ledArray(0x20);
2021-12-23 10:41:42 +01:00
2016-04-24 08:26:22 +02:00
void setup()
{
2020-11-27 11:28:57 +01:00
Serial.begin(115200);
Serial.print("PCA9635 LIB version: ");
Serial.println(PCA9635_LIB_VERSION);
Serial.println();
ledArray.begin();
testSetLedDriverModeLEDON();
testPWMMode();
testWrite1();
testWrite3();
testWriteN();
testSetGroupPWM_FREQ();
testSetAndReadMode();
testSetLedDriverModeLEDOFF();
Serial.print(millis());
Serial.print("\t");
Serial.println("done...");
2016-04-24 08:40:38 +02:00
}
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testSetLedDriverModeLEDON()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - Switch all on");
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2020-11-27 11:28:57 +01:00
{
ledArray.setLedDriverMode(channel, PCA9635_LEDON);
if (ledArray.getLedDriverMode(channel) != PCA9635_LEDON)
2016-04-24 08:40:38 +02:00
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.print("Channel: ");
Serial.println(channel);
2016-04-24 08:40:38 +02:00
}
2020-11-27 11:28:57 +01:00
}
2016-04-24 08:40:38 +02:00
}
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testPWMMode()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - set pwm mode");
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2020-11-27 11:28:57 +01:00
{
ledArray.setLedDriverMode(channel, PCA9635_LEDON);
delay(200);
ledArray.setLedDriverMode(channel, PCA9635_LEDPWM);
if (ledArray.getLedDriverMode(channel) != PCA9635_LEDPWM)
2016-04-24 08:26:22 +02:00
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.print("Channel: ");
Serial.println(channel);
2016-04-24 08:26:22 +02:00
}
2020-11-27 11:28:57 +01:00
}
2016-04-24 08:40:38 +02:00
}
2016-04-24 08:26:22 +02:00
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testWrite1()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - write1 - I");
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2020-11-27 11:28:57 +01:00
{
for (int pwm = 0; pwm < 256; pwm++)
2016-04-24 08:26:22 +02:00
{
2020-11-27 11:28:57 +01:00
ledArray.write1(channel, pwm);
2016-04-24 08:26:22 +02:00
}
2020-11-27 11:28:57 +01:00
}
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - write 1 - II");
for (int pwm = 0; pwm < 256; pwm++)
{
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2016-04-24 08:26:22 +02:00
{
2020-11-27 11:28:57 +01:00
ledArray.write1(channel, pwm);
2016-04-24 08:26:22 +02:00
}
2020-11-27 11:28:57 +01:00
}
2016-04-24 08:40:38 +02:00
}
2016-04-24 08:26:22 +02:00
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testWrite3()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - write3 - random RGB");
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < (ledArray.channelCount() - 3); channel++) // 13 = 16 -3 !!!
2020-11-27 11:28:57 +01:00
{
uint8_t R = random(256);
uint8_t G = random(256);
uint8_t B = random(256);
ledArray.write3(channel, R, G, B);
}
2016-04-24 08:40:38 +02:00
}
2016-04-24 08:26:22 +02:00
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testWriteN()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - writeN ");
uint8_t arr[16] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 255};
2022-06-02 12:11:57 +02:00
ledArray.writeN(0, arr, 16); // 16 == ledArray.channelCount()
2016-04-24 08:40:38 +02:00
}
2016-04-24 08:26:22 +02:00
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testSetGroupPWM_FREQ()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - GroupPWM");
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2020-11-27 11:28:57 +01:00
{
ledArray.setLedDriverMode(channel, PCA9635_LEDGRPPWM);
}
for (int pwm = 0; pwm < 256; pwm++)
{
ledArray.setGroupPWM(pwm);
uint8_t p = ledArray.getGroupPWM();
if (p != pwm)
2016-04-24 08:26:22 +02:00
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.print("pwm: ");
Serial.println(pwm);
2016-04-24 08:26:22 +02:00
}
2020-11-27 11:28:57 +01:00
}
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)
2016-04-24 08:26:22 +02:00
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.print("frq: ");
Serial.println(frq);
2016-04-24 08:26:22 +02:00
}
2020-11-27 11:28:57 +01:00
}
2016-04-24 08:26:22 +02:00
2020-11-27 11:28:57 +01:00
// reset to LEDPWM
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2020-11-27 11:28:57 +01:00
{
ledArray.setLedDriverMode(channel, PCA9635_LEDPWM);
}
2016-04-24 08:40:38 +02:00
}
2016-04-24 08:26:22 +02:00
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testSetAndReadMode()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - readMode");
uint8_t regval = ledArray.readMode(PCA9635_MODE1);
ledArray.writeMode(PCA9635_MODE1, regval); // non destructive;
Serial.print(millis());
Serial.print("\t");
Serial.print("PCA9635_MODE1: ");
Serial.println(regval);
regval = ledArray.readMode(PCA9635_MODE2);
ledArray.writeMode(PCA9635_MODE2, regval);
Serial.print(millis());
Serial.print("\t");
Serial.print("PCA9635_MODE2: ");
Serial.println(regval);
2016-04-24 08:40:38 +02:00
}
2016-04-24 08:26:22 +02:00
2021-12-23 10:41:42 +01:00
2016-04-24 08:40:38 +02:00
void testSetLedDriverModeLEDOFF()
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.println("Test - Switch all off");
2022-06-02 12:11:57 +02:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2020-11-27 11:28:57 +01:00
{
ledArray.setLedDriverMode(channel, PCA9635_LEDOFF);
if (ledArray.getLedDriverMode(channel) != PCA9635_LEDOFF)
2016-04-24 08:26:22 +02:00
{
2020-11-27 11:28:57 +01:00
Serial.print(millis());
Serial.print("\t");
Serial.print("Channel: ");
Serial.println(channel);
2016-04-24 08:26:22 +02:00
}
2020-11-27 11:28:57 +01:00
}
2016-04-24 08:26:22 +02:00
}
2021-12-23 10:41:42 +01:00
2016-04-24 08:26:22 +02:00
void loop()
{
}
2020-11-27 11:28:57 +01:00
2021-12-23 10:41:42 +01:00
2020-11-27 11:28:57 +01:00
// -- END OF FILE --
2021-12-23 10:41:42 +01:00