initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/***************************************************
|
||||
This is an example for our Adafruit 16-channel PWM & Servo driver
|
||||
GPIO test - this will set a pin high/low
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/815
|
||||
|
||||
These drivers use I2C to communicate, 2 pins are required to
|
||||
interface.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_PWMServoDriver.h>
|
||||
|
||||
// called this way, it uses the default address 0x40
|
||||
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
|
||||
// you can also call it with a different address you want
|
||||
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
|
||||
// you can also call it with a different address and I2C interface
|
||||
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("GPIO test!");
|
||||
|
||||
pwm.begin();
|
||||
pwm.setPWMFreq(1000); // Set to whatever you like, we don't use it in this demo!
|
||||
|
||||
// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
|
||||
// some i2c devices dont like this so much so if you're sharing the bus, watch
|
||||
// out for this!
|
||||
Wire.setClock(400000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Drive each pin in a 'wave'
|
||||
for (uint8_t pin=0; pin<16; pin++) {
|
||||
pwm.setPWM(pin, 4096, 0); // turns pin fully on
|
||||
delay(100);
|
||||
pwm.setPWM(pin, 0, 4096); // turns pin fully off
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/***************************************************
|
||||
This is an example for our Adafruit 16-channel PWM & Servo driver
|
||||
PWM test - this will drive 16 PWMs in a 'wave'
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/815
|
||||
|
||||
These drivers use I2C to communicate, 2 pins are required to
|
||||
interface.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_PWMServoDriver.h>
|
||||
|
||||
// called this way, it uses the default address 0x40
|
||||
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
|
||||
// you can also call it with a different address you want
|
||||
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
|
||||
// you can also call it with a different address and I2C interface
|
||||
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("16 channel PWM test!");
|
||||
|
||||
pwm.begin();
|
||||
pwm.setPWMFreq(1600); // This is the maximum PWM frequency
|
||||
|
||||
// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
|
||||
// some i2c devices dont like this so much so if you're sharing the bus, watch
|
||||
// out for this!
|
||||
Wire.setClock(400000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Drive each PWM in a 'wave'
|
||||
for (uint16_t i=0; i<4096; i += 8) {
|
||||
for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) {
|
||||
pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 );
|
||||
}
|
||||
#ifdef ESP8266
|
||||
yield(); // take a breather, required for ESP8266
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/***************************************************
|
||||
This is an example for our Adafruit 16-channel PWM & Servo driver
|
||||
Servo test - this will drive 8 servos, one after the other on the
|
||||
first 8 pins of the PCA9685
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/815
|
||||
|
||||
These drivers use I2C to communicate, 2 pins are required to
|
||||
interface.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_PWMServoDriver.h>
|
||||
|
||||
// called this way, it uses the default address 0x40
|
||||
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
|
||||
// you can also call it with a different address you want
|
||||
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
|
||||
// you can also call it with a different address and I2C interface
|
||||
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);
|
||||
|
||||
// Depending on your servo make, the pulse width min and max may vary, you
|
||||
// want these to be as small/large as possible without hitting the hard stop
|
||||
// for max range. You'll have to tweak them as necessary to match the servos you
|
||||
// have!
|
||||
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
|
||||
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)
|
||||
|
||||
// our servo # counter
|
||||
uint8_t servonum = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("8 channel Servo test!");
|
||||
|
||||
pwm.begin();
|
||||
|
||||
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// you can use this function if you'd like to set the pulse length in seconds
|
||||
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
|
||||
void setServoPulse(uint8_t n, double pulse) {
|
||||
double pulselength;
|
||||
|
||||
pulselength = 1000000; // 1,000,000 us per second
|
||||
pulselength /= 60; // 60 Hz
|
||||
Serial.print(pulselength); Serial.println(" us per period");
|
||||
pulselength /= 4096; // 12 bits of resolution
|
||||
Serial.print(pulselength); Serial.println(" us per bit");
|
||||
pulse *= 1000000; // convert to us
|
||||
pulse /= pulselength;
|
||||
Serial.println(pulse);
|
||||
pwm.setPWM(n, 0, pulse);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Drive each servo one at a time
|
||||
Serial.println(servonum);
|
||||
for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
|
||||
pwm.setPWM(servonum, 0, pulselen);
|
||||
}
|
||||
|
||||
delay(500);
|
||||
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
|
||||
pwm.setPWM(servonum, 0, pulselen);
|
||||
}
|
||||
|
||||
delay(500);
|
||||
|
||||
servonum ++;
|
||||
if (servonum > 7) servonum = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user