View difference between Paste ID: cGCw8azZ and SnTU5nFe
SHOW: | | - or go back to the newest paste.
1
include <Wire.h>
2
#include <Adafruit_PWMServoDriver.h>
3
 
4
Adafruit_PWMServoDriver driver = Adafruit_PWMServoDriver(0x40);
5
6
const int PWM_MAX_COUNT = 4095;
7-
    // Call begin before using any other functions
7+
int getOn(double duty) {
8
    return duty * PWM_MAX_COUNT;
9
}
10-
    // Set the frequency of the PWM output
10+
int getOff(double duty) {
11-
    // The frequency can go from 40 to 1600.
11+
    // Give this a shot?
12-
    // Try some stuff out and see if you notice a difference
12+
13
14
void setup() {
15-
    // Sets the PWM duty cycle
15+
16-
    // There are 4096 ticks in one cycle
16+
17-
    // Play around a bit with the on and off values for fun
17+
18-
    int channel = 0; // Your LED is hooked up to channel 0
18+
19-
    int on = 0;      // Turn from off to on at 0 ticks
19+
20-
    int off = 2047;  // Turn from on to off at 2047 ticks, to give us a 50% duty cycle
20+
    driver.setPWM(0, 0, 1024);
21-
    driver.setPWM(channel, on, off)
21+
    // driver.setPWM(0, getOn(.25), getOff(.25));
22
    delay(1);
23
    driver.setPWM(0, 0, 3075);
24
    // driver.setPWM(0, getOn(.25), getOff(.25));
25
    delay(1);
26
}