/* PCA9685LEDv1 04/05/2022 Very basic sketch to blink an LED and then do a slow increase in brightness for leds on all pins. sketch tested on Arduino Uno and ESP32 Dev Module For connections and pin outs for ESP32, Arduino UNO and Mega see http://www.digitaltown.co.uk/components16-PCA9685LED.php */ //Libraries required #include "Wire.h" #include "Adafruit_PWMServoDriver.h" Adafruit_PWMServoDriver PCA9685 = Adafruit_PWMServoDriver(0x40, Wire); //2nd board example at address 50 //Adafruit_PWMServoDriver 2ndPCA9685 = Adafruit_PWMServoDriver(0x50, Wire); void setup() { Serial.begin(9600); Serial.println("PCA9685LEDv1"); Wire.begin(); PCA9685.begin(); PCA9685.setPWMFreq(1600); // This is the maximum PWM frequency and suited to LED's } void loop() { int q; int w; //Simple blink style sketch for (w = 0; w < 5; w++) { for (q = 0; q < 16; q++) { PCA9685.setPWM(q, 0, 4095);//Fully On //PCA9685.setPWM(q, 0, 1000);// 25% on /* * PCA9685.setPWM(q, 0, 4095);//Fully On * * q = channel of the PCA9685 marked just above the yellow pin * 0 = the part of the cycle we want the LED to turn on...best to leave as 0 if you are a beginner * 4095 (out of a value of 0 to 4095 is the point in the cycle you want to turn OFF the led, higher the number the brighter the LED */ } Serial.println("On"); delay(1000); for (q = 0; q < 16; q++) { PCA9685.setPWM(q, 0, 4096);//fully OFF...setting value to 4096 takes number out of range // PCA9685.setPWM(q, 0, 1000);//on at 25% brightness } Serial.println("Off"); delay(1000); } //LED's slowly increase in brightness for(w=0;w<4096;w++){ for(q=0;q<16;q++){ PCA9685.setPWM(q, 0, w);//fully OFF } delay(5); } }