|
| 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 | +} |
0 commit comments