I don't know what "reset" does. I would like to stop sending a signal to the servos when my program ends. I guess I need to read the PCA9685 pdf a few more times.
Hopefully this helps someone. However, I am an amateur.
Mike
Moderators: adafruit_support_bill, adafruit
void PCA9685::reset() {
// Turn off all LED's
I2Cdev::writeByte(devAddr, ALLLED_ON_L, 0x00);
I2Cdev::writeByte(devAddr, ALLLED_ON_H, 0x00);
I2Cdev::writeByte(devAddr, ALLLED_OFF_L, 0x00);
I2Cdev::writeByte(devAddr, ALLLED_OFF_H, 0x10);
// oscillator off,ALLCALL off and restart PCA9685
I2Cdev::writeByte(devAddr, PCA9685_MODE1, 0x90);
}
/**
* Stop the internal oscillator by
* Changing bit 4 to a 1
*/
bool PCA9685::sleepMode() {
uint8_t oldmode;
I2Cdev::readByte(devAddr, PCA9685_MODE1, &oldmode);
// bitwise OR (|) if bit4 = 0 or 1 then bit4 = 1
oldmode |= 0x10;
return I2Cdev::writeByte(devAddr, PCA9685_MODE1, oldmode);
}void PCA9685::reset() {
// Turn off all LED's
I2Cdev::writeByte(devAddr, ALLLED_ON_L, 0x00);
I2Cdev::writeByte(devAddr, ALLLED_ON_H, 0x00);
I2Cdev::writeByte(devAddr, ALLLED_OFF_L, 0x00);
I2Cdev::writeByte(devAddr, ALLLED_OFF_H, 0x10);
// oscillator off and ALLCALL off
I2Cdev::writeByte(devAddr, PCA9685_MODE1, 0x10);
}void PCA9685::setPWMFreq(float freq) {
float prescaleval = 25000000;
prescaleval /= 4096;
prescaleval /= freq;
prescaleval -= 1;
uint8_t prescale = floor(prescaleval + 0.5);
uint8_t oldmode;
I2Cdev::readByte(devAddr, PCA9685_MODE1, &oldmode);
uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
I2Cdev::writeByte(devAddr, PCA9685_MODE1, newmode); // go to sleep
I2Cdev::writeByte(devAddr, PCA9685_PRESCALE, prescale); // set the prescaler
I2Cdev::writeByte(devAddr, PCA9685_MODE1, oldmode & 0x6F); // Oscillator on
sleep(0.005);
//I2Cdev::writeByte(devAddr, PCA9685_MODE1, oldmode | 0x80);
}Return to Adafruit Raspberry Pi® accessories
Users browsing this forum: No registered users and 2 guests