GY-63_MS5611/libraries/PCA9685_RT/examples/PCA9685_test02/PCA9685_test02.ino

130 lines
2.2 KiB
Arduino
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
// FILE: PCA9685_test02.ino
// AUTHOR: Rob Tillaart
// DATE: 24-APR-2016
// PUPROSE: test PCA9685 library
2022-01-06 14:24:55 -05:00
#include "Arduino.h"
#include "Wire.h"
2021-01-29 06:31:58 -05:00
#include "PCA9685.h"
2022-01-06 14:24:55 -05:00
2021-01-29 06:31:58 -05:00
PCA9685 ledArray(0x40);
2021-12-23 05:18:10 -05:00
2021-01-29 06:31:58 -05:00
void setup()
{
Wire.begin();
ledArray.begin();
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCA9685 LIB version: ");
Serial.println(PCA9685_LIB_VERSION);
Serial.println();
testDigitalWrite(HIGH);
testPWM(0);
testPWMMode();
testFrequency();
delay(2000);
testDigitalWrite(LOW);
Serial.print(millis());
Serial.print("\t");
Serial.println("done...");
}
void testDigitalWrite(uint8_t mode)
{
Serial.print(millis());
Serial.print("\t");
Serial.println(__FUNCTION__);
2022-01-06 14:24:55 -05:00
for (int channel = 0; channel < ledArray.channelCount(); channel++)
2021-01-29 06:31:58 -05:00
{
ledArray.digitalWrite(channel, mode);
delay(100);
}
}
2021-12-23 05:18:10 -05:00
2021-01-29 06:31:58 -05:00
void testPWM(uint8_t channel)
{
Serial.print(millis());
Serial.print("\t");
Serial.println(__FUNCTION__);
uint16_t i = 0;
while (i < 4096)
{
ledArray.setPWM(channel, 0, i);
delay(1);
i++;
}
while (i > 0)
{
ledArray.setPWM(channel, 0, i);
delay(1);
i--;
}
}
2021-12-23 05:18:10 -05:00
2021-01-29 06:31:58 -05:00
void testPWMMode()
{
Serial.print(millis());
Serial.print("\t");
Serial.println(__FUNCTION__);
2022-01-06 14:24:55 -05:00
for (uint16_t channel = 1; channel < ledArray.channelCount(); channel++)
2021-01-29 06:31:58 -05:00
{
// every next line ~twice as much time
ledArray.setPWM(channel, channel * 127, channel * 255);
uint16_t a = 0, b = 0;
ledArray.getPWM(channel, &a, &b);
if (a != channel * 127 || b != channel * 255)
{
Serial.print("Error channel:\t");
Serial.println(channel);
}
}
}
2021-12-23 05:18:10 -05:00
2021-01-29 06:31:58 -05:00
void testFrequency()
{
Serial.print(millis());
Serial.print("\t");
Serial.println(__FUNCTION__);
ledArray.setPWM(0, 1000, 3000);
for (uint16_t freq = 12; freq < 2000; freq *= 2)
{
Serial.print(freq);
ledArray.setFrequency(freq);
// if freq is out of range => report
if (ledArray.getFrequency() != freq)
{
Serial.print("\tconstrained to : ");
Serial.println(ledArray.getFrequency());
}
else
{
Serial.println("\tOK");
}
delay(2000);
}
ledArray.setOFF(0);
Serial.println();
}
void loop()
{
//testPWM(0);
}
2021-12-23 05:18:10 -05:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-12-23 05:18:10 -05:00