Hello,
I've been trying to make small installation to work properly. I've connected 16 fans 12v 2 pins. I'm trying to control them with PCA9685 and Arduino setup. I've connected everything and i works well when i'm trying to send one code to all of them like this:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pca1(0x40);
Adafruit_PWMServoDriver pca2(0x41);
void setup() {
Serial.begin(9600);
Wire.begin();
pca1.begin();
pca1.setPWMFreq(1000);
pca2.begin();
pca2.setPWMFreq(1000);
}
void loop() {
pca1.setPin(0, 4095);
pca1.setPin(1, 4095);
pca1.setPin(2, 4095);
pca1.setPin(3, 4095);
pca1.setPin(4, 4095);
pca1.setPin(5, 4095);
pca1.setPin(6, 4095);
pca1.setPin(7, 4095);
pca1.setPin(8, 4095);
pca1.setPin(9, 4095);
pca1.setPin(10, 4095);
pca1.setPin(11, 4095);
pca1.setPin(12, 4095);
pca1.setPin(13, 4095);
pca1.setPin(14, 4095);
pca1.setPin(15, 4095);
}
This works perfectly, all of them start to rotate, everything is as intended. But when i want to add some steps so each fan is starting after certain amount of time, it stops responding at all.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pca1(0x40);
Adafruit_PWMServoDriver pca2(0x41);
unsigned long t0 = 0;
int step = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
pca1.begin();
pca1.setPWMFreq(1000);
pca2.begin();
pca2.setPWMFreq(1000);
}
void loop() {
if(step == 0) {
for(int i = 0; i < 16; i++) pca1.setPin(i,0);
t0 = millis();
step = 1;
}
if(step == 1 && millis() - t0 >= 5000) {
pca1.setPin(0, 4095); // fan0 kick-start
t0 = millis();
step = 2;
}
if(step == 2 && millis() - t0 >= 5000) {
pca1.setPin(0, 2048); // and then slowing it down. I want to have low rotation.
t0 = millis();
step = 3;
}
if(step == 3 && millis() - t0 >= 3000) {
pca1.setPin(1, 4095);
t0 = millis();
step = 4;
}
if(step == 4 && millis() - t0 >= 5000) {
pca1.setPin(1, 2048);
t0 = millis();
step = 5;
}
if(step == 5 && millis() - t0 >= 10000) {
t0 = millis();
step = 0;
}
}
What am i doing wrong? Is it even possible to make sequence like this work on arduino + pca. My whole setup have separate 12v supply, mosfets, condensers, resistors 330 Ohm and 10k Ohm soldered on the PCBs. Like i said, if i put the first code - it works. So i'm not sure if it is hardware issue. I'm not specialist, i'm musician, i can barely code so i guess that’s where the problem lies. I tried to do it with delay(); but with the same results. Whenever i'm adding certain steps it stops working. Thank you for any help!











