Permalink
Browse files

woot examples!

  • Loading branch information...
1 parent a372b95 commit 45b7d67e231f439f40fc2c9f74eb5e089e9938a1 @ladyada ladyada committed May 2, 2012
Showing with 85 additions and 0 deletions.
  1. +10 −0 Adafruit_PWMServoDriver.cpp
  2. +75 −0 examples/pwmtest/pwmtest.pde
@@ -55,6 +55,16 @@ void Adafruit_PWMServoDriver::setPWMFreq(float freq) {
}
void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
+ /*
+ // hmm doesnt work, whyso?
+ Wire.beginTransmission(_i2caddr);
+ Wire.write(LED0_ON_L+4*num);
+ Wire.write(on);
+ Wire.write(on>>8);
+ Wire.write(off);
+ Wire.write(off>>8);
+ Wire.endTransmission();
+ */
write8(LED0_ON_L+4*num, on);
write8(LED0_ON_H+4*num, on >> 8);
write8(LED0_OFF_L+4*num, off);
@@ -0,0 +1,75 @@
+/***************************************************
+ 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 displays use I2C to communicate, 2 pins are required to
+ interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4
+
+ 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);
+
+void setup() {
+ Serial.begin(9600);
+ Serial.println("16 channel PWM test!");
+
+ // 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!
+
+ // save I2C bitrate
+ uint8_t twbrbackup = TWBR;
+ TWBR = 12; // upgrade to 400KHz!
+
+ pwm.begin();
+ pwm.setPWMFreq(1600); // This is the maximum PWM frequency
+}
+
+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 );
+ }
+ }
+}
+it_PWMServoDriver();
+// you can also call it with a different address you want
+//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
+
+void setup() {
+ Serial.begin(9600);
+ Serial.println("16 channel PWM test!");
+
+ // 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!
+
+ // save I2C bitrate
+ uint8_t twbrbackup = TWBR;
+ TWBR = 12; // upgrade to 400KHz!
+
+ pwm.begin();
+ pwm.setPWMFreq(1600); // This is the maximum PWM frequency
+}
+
+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 + (

0 comments on commit 45b7d67

Please sign in to comment.