Skip to content

Commit 4154413

Browse files
committed
add gpio pulsing demo, fix some typos
1 parent f232a12 commit 4154413

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

Adafruit_PWMServoDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
134134

135135
/**************************************************************************/
136136
/*!
137-
@brief Helper to set pin PWM output. Sets pin without having to deal with on/off tick placement and properly handles a zero value as completely off. Optional invert parameter supports inverting the pulse for sinking to ground.
137+
@brief Helper to set pin PWM output. Sets pin without having to deal with on/off tick placement and properly handles a zero value as completely off and 4095 as completely on. Optional invert parameter supports inverting the pulse for sinking to ground.
138138
@param num One of the PWM output pins, from 0 to 15
139139
@param val The number of ticks out of 4096 to be active, should be a value from 0 to 4095 inclusive.
140140
@param invert If true, inverts the output, defaults to 'false'

examples/gpiotest/gpiotest.ino

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************
2+
This is an example for our Adafruit 16-channel PWM & Servo driver
3+
GPIO test - this will set a pin high/low
4+
5+
Pick one up today in the adafruit shop!
6+
------> http://www.adafruit.com/products/815
7+
8+
These drivers use I2C to communicate, 2 pins are required to
9+
interface.
10+
11+
Adafruit invests time and resources providing this open source code,
12+
please support Adafruit and open-source hardware by purchasing
13+
products from Adafruit!
14+
15+
Written by Limor Fried/Ladyada for Adafruit Industries.
16+
BSD license, all text above must be included in any redistribution
17+
****************************************************/
18+
19+
#include <Wire.h>
20+
#include <Adafruit_PWMServoDriver.h>
21+
22+
// called this way, it uses the default address 0x40
23+
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
24+
// you can also call it with a different address you want
25+
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
26+
// you can also call it with a different address and I2C interface
27+
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);
28+
29+
void setup() {
30+
Serial.begin(9600);
31+
Serial.println("GPIO test!");
32+
33+
pwm.begin();
34+
pwm.setPWMFreq(1000); // Set to whatever you like, we don't use it in this demo!
35+
36+
// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
37+
// some i2c devices dont like this so much so if you're sharing the bus, watch
38+
// out for this!
39+
Wire.setClock(400000);
40+
}
41+
42+
void loop() {
43+
// Drive each pin in a 'wave'
44+
for (uint8_t pin=0; pin<16; pin++) {
45+
pwm.setPWM(pin, 4096, 0); // turns pin fully on
46+
delay(100);
47+
pwm.setPWM(pin, 0, 4096); // turns pin fully off
48+
}
49+
}

examples/servo/servo.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/***************************************************
22
This is an example for our Adafruit 16-channel PWM & Servo driver
3-
Servo test - this will drive 16 servos, one after the other
3+
Servo test - this will drive 8 servos, one after the other on the
4+
first 8 pins of the PCA9685
45
56
Pick one up today in the adafruit shop!
67
------> http://www.adafruit.com/products/815
@@ -38,7 +39,7 @@ uint8_t servonum = 0;
3839

3940
void setup() {
4041
Serial.begin(9600);
41-
Serial.println("16 channel Servo test!");
42+
Serial.println("8 channel Servo test!");
4243

4344
pwm.begin();
4445

0 commit comments

Comments
 (0)