SHARE
TWEET

darylrobotproject.wordpress.com Adafruit 16-Channel PWM

a guest Apr 1st, 2013 434 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <Adafruit_PWMServoDriver.h>
  3.  
  4. // called this way, it uses the default address 0x40 Channel 0 to 4095
  5. Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
  6.  
  7. int CH_OREILLE[] = {0, 1};
  8. // 0 Oreille gauche
  9. // 1 Oreille droite
  10. // 0 1
  11.  
  12. void setup() {
  13.  
  14.   pwm.begin();
  15.   pwm.setPWMFreq(1600); // This is the maximum PWM frequency
  16.   uint8_t twbrbackup = TWBR; // save I2C bitrate
  17.   TWBR = 12; // upgrade to 400KHz!
  18.  
  19.    for (int i=0; i <= 4095; i=i+5){
  20.    
  21.       setLight(CH_OREILLE, i,2);
  22.      
  23.       delay(1);
  24.    }
  25.    
  26. }
  27.  
  28. void loop() {
  29.  
  30.   delay(10);
  31.    
  32. }
  33.  
  34. void setLight(int module[],int val, int nbVal)
  35. {
  36.   for (int i=0; i<(nbVal);i++) {
  37.       pwm.setPWM(module[i], 0, val);    
  38.     }
  39. }
RAW Paste Data
Top