File tree Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Original file line number Diff line number Diff line change 17
17
18
18
#include < Adafruit_PWMServoDriver.h>
19
19
#include < Wire.h>
20
- #if defined(__AVR__)
21
- #define WIRE Wire
22
- #elif defined(CORE_TEENSY) // Teensy boards
23
- #define WIRE Wire
24
- #else // Arduino Due
20
+ #if defined(ARDUINO_SAM_DUE)
25
21
#define WIRE Wire1
22
+ #else
23
+ #define WIRE Wire
26
24
#endif
27
25
26
+
28
27
// Set to true to print some debug messages, or false to disable them.
29
28
#define ENABLE_DEBUG_OUTPUT false
30
29
Original file line number Diff line number Diff line change @@ -24,22 +24,31 @@ Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
24
24
// you can also call it with a different address you want
25
25
// Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
26
26
27
+ #if defined(ARDUINO_ARCH_SAMD )
28
+ // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
29
+ #define Serial SerialUSB
30
+ #endif
31
+
27
32
void setup () {
33
+ #ifdef ESP8266
34
+ Wire . pins(2 , 14 ); // ESP8266 can use any two pins, such as SDA to #2 and SCL to #14
35
+ #endif
36
+
28
37
Serial . begin(9600 );
29
38
Serial . println(" 16 channel PWM test!" );
30
39
40
+ pwm. begin();
41
+ pwm. setPWMFreq(1600 ); // This is the maximum PWM frequency
42
+
31
43
// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
32
44
// some i2c devices dont like this so much so if you're sharing the bus, watch
33
45
// out for this!
34
-
35
- pwm. begin();
36
- pwm. setPWMFreq(1600 ); // This is the maximum PWM frequency
37
-
46
+ #ifdef TWBR
38
47
// save I2C bitrate
39
48
uint8_t twbrbackup = TWBR ;
40
49
// must be changed after calling Wire.begin() (inside pwm.begin())
41
50
TWBR = 12 ; // upgrade to 400KHz!
42
-
51
+ #endif
43
52
}
44
53
45
54
void loop () {
@@ -49,4 +58,4 @@ void loop() {
49
58
pwm. setPWM(pwmnum, 0 , (i + (4096 / 16 )* pwmnum) % 4096 );
50
59
}
51
60
}
52
- }
61
+ }
Original file line number Diff line number Diff line change @@ -38,9 +38,15 @@ void setup() {
38
38
Serial . begin(9600 );
39
39
Serial . println(" 16 channel Servo test!" );
40
40
41
+ #ifdef ESP8266
42
+ Wire . pins(2 , 14 ); // ESP8266 can use any two pins, such as SDA to #2 and SCL to #14
43
+ #endif
44
+
41
45
pwm. begin();
42
46
43
47
pwm. setPWMFreq(60 ); // Analog servos run at ~60 Hz updates
48
+
49
+ yield();
44
50
}
45
51
46
52
// you can use this function if you'd like to set the pulse length in seconds
@@ -65,12 +71,14 @@ void loop() {
65
71
for (uint16_t pulselen = SERVOMIN ; pulselen < SERVOMAX ; pulselen++ ) {
66
72
pwm. setPWM(servonum, 0 , pulselen);
67
73
}
74
+
68
75
delay (500 );
69
76
for (uint16_t pulselen = SERVOMAX ; pulselen > SERVOMIN ; pulselen-- ) {
70
77
pwm. setPWM(servonum, 0 , pulselen);
71
78
}
79
+
72
80
delay (500 );
73
81
74
82
servonum ++ ;
75
- if (servonum > 15 ) servonum = 0 ;
83
+ if (servonum > 7 ) servonum = 0 ;
76
84
}
You can’t perform that action at this time.
0 commit comments