I'm trying to run servo motors with the PCA9685 and the 12V DC motors from Arduino Mega2560 pins to run the H Bridge L298 drivers.
My project needs 19 PWM pins and the mega2560 only has 15.
Anyone know how to modify the Adafruit library to make it work?
My error: cannot convert 'Adafruit_PWMServoDriver to 'int' for argument '2'
On the line for the " analogWrite(enable1, pwm); " for the 12V motor enable
Thanks for the replies everyone. I think I'll junk the PCA, and just link an Uno to get the extra PWM pins I need. A lot simpler fix.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define MIN_PULSE_WIDTH 650
#define MAX_PULSE_WIDTH 2350
#define DEFAULT_PULSE_WIDTH 1500
#define FREQUENCY 50
const int rc_ch_9= 11;
const int SWC_Min = 0;
const int SWC_Max = 1550;
const int in1 = 39; // to in1 on driver
const int in2 =38; // to in2 on driver
const int enable1 = 6; // ~pwm to enable1 on driver
const int analogPin_1 = A2;
int threshold_Min;
int threshold_Max;
int range;
int val;
uint8_t servonum = 0;
void setup(){
pinMode(rc_ch_9, INPUT);
Serial.begin(9600);
Serial.println("16 channel Servo test!");
pwm.begin();
pwm.setPWMFreq(FREQUENCY);
}
int pulseWidth(int angle){
int pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
Serial.println(analog_value);
return analog_value;
}
void loop() {
val=0;
int SWC= pulseIn(rc_ch_9, HIGH, 25000);
int analogValue_1 = analogRead(analogPin_1);
//Serial.print(analogValue_1);
delay(10);
range = map( SWC, SWC_Min, SWC_Max, 0, 3); //map the pulse low and high for switch
switch (range){
case 0:
pwm.setPWM(0, 0, pulseWidth(200));
delay(10);
break;
case 1:
pwm.setPWM(0, 0, pulseWidth(-10));
delay(10);
break;
case 2:
pwm.setPWM(0, 0, pulseWidth(200));
break;
}
delay(10);
if (SWC < 1550 && analogValue_1 > threshold_Min){ // SWITCH OFF
threshold_Min=200;
threshold_Max=700;
pwm = map(SWC, 1550, 1000, 200, 255); //map speed
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enable1, pwm);
Serial.print(pwm);
delay(1);
}
if (SWC < 1550 && analogValue_1 <= threshold_Min){
threshold_Min=200;
threshold_Max=700;threshold_Min=200;
threshold_Max=700;
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enable1, 0);
delay(10);
}
if (SWC > 1550 && analogValue_1 < threshold_Max){ //SWITCH ON
threshold_Min=200;
threshold_Max=700;
pwm = map(SWC, 1550, 2000, 200, 255); //map speed
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enable1, pwm);
Serial.print(pwm);
delay(10);
}
if( SWC > 1550 && analogValue_1 >= threshold_Max){
threshold_Min=200;
threshold_Max=700;
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enable1, 0);
//Serial.println( " DRIVE ON " );
delay(10);
}
Serial.print(analogValue_1);
delay(10);
}
/code]