Skip to content

Commit f5c4929

Browse files
committed
📝 (Examples): update to compile under AVR
1 parent ac67bc6 commit f5c4929

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

examples/PCA9685/Servo/Servo.ino

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,17 @@ void setup() {
2323
Serial.begin(115200);
2424
Serial.println("I2CDevLib Example - PCA9685 Test");
2525

26-
if (!Wire.begin()) {
27-
Serial.println("[E] Failed to init Wire!");
28-
while(true) {};
29-
}
26+
Wire.begin();
3027

3128
// auto result = pca9685.setPrescale(100);
3229
result = pca9685.setFrequency(SERVO_FREQ);
3330
if (result != I2CDEV_RESULT_OK) {
34-
Serial.printf("[E] Failed to set PCA9685 prescale: %i\n", result);
31+
Serial.println("[E] Failed to set PCA9685 prescale");
3532
while(true) {};
3633
}
3734
result = pca9685.wakeup();
3835
if (result != I2CDEV_RESULT_OK) {
39-
Serial.printf("[E] Failed wakeup PCA9685: %i\n", result);
36+
Serial.println("[E] Failed to wake up PCA9685");
4037
while(true) {};
4138
}
4239

@@ -46,16 +43,14 @@ void setup() {
4643
uint8_t currentServo = 0;
4744

4845
void loop() {
49-
Serial.printf("Current servo: %i\n", currentServo);
46+
Serial.print("Current servo: "); Serial.println(currentServo);
5047

5148
Serial.println("\t > SERVO_PULSE_LEN_MIN => SERVO_PULSE_LEN_MAX");
5249
for (uint16_t pulseLen = SERVO_PULSE_LEN_MIN; pulseLen < SERVO_PULSE_LEN_MAX; pulseLen++) {
5350
result = pca9685.setChannel(currentServo, pulseLen);
5451
if (result != I2CDEV_RESULT_OK) {
55-
Serial.printf("[E] Failed to set PCA9685 pin: %i\n", result);
52+
Serial.println("[E] Failed to set PCA9685 pin");
5653
}
57-
// delay(5);
58-
// Serial.printf("\t > SERVO_PULSE_LEN_MIN => SERVO_PULSE_LEN_MAX: %i\n", pulseLen);
5954
}
6055

6156
delay(500);
@@ -64,10 +59,8 @@ void loop() {
6459
for (uint16_t pulseLen = SERVO_PULSE_LEN_MAX; pulseLen > SERVO_PULSE_LEN_MIN; pulseLen--) {
6560
result = pca9685.setChannel(currentServo, pulseLen);
6661
if (result != I2CDEV_RESULT_OK) {
67-
Serial.printf("[E] Failed to set PCA9685 pin: %i\n", result);
62+
Serial.println("[E] Failed to set PCA9685 pin");
6863
}
69-
// delay(5);
70-
// Serial.printf("\t > SERVO_PULSE_LEN_MAX => SERVO_PULSE_LEN_MIN: %i\n", pulseLen);
7164
}
7265

7366
delay(500);
@@ -76,10 +69,8 @@ void loop() {
7669
for (uint16_t uSec = SERVO_US_MIN; uSec < SERVO_US_MAX; uSec++) {
7770
result = pca9685.writeMicroseconds(currentServo, uSec);
7871
if (result != I2CDEV_RESULT_OK) {
79-
Serial.printf("[E] Failed to set PCA9685 microseconds: %i\n", result);
72+
Serial.println("[E] Failed to set PCA9685 microseconds");
8073
}
81-
// delay(5);
82-
// Serial.printf("\t > SERVO_US_MIN => SERVO_US_MAX: %i\n", uSec);
8374
}
8475

8576
delay(500);
@@ -88,10 +79,8 @@ void loop() {
8879
for (uint16_t uSec = SERVO_US_MAX; uSec > SERVO_US_MIN; uSec--) {
8980
result = pca9685.writeMicroseconds(currentServo, uSec);
9081
if (result != I2CDEV_RESULT_OK) {
91-
Serial.printf("[E] Failed to set PCA9685 microseconds: %i\n", result);
82+
Serial.println("[E] Failed to set PCA9685 microseconds");
9283
}
93-
// delay(5);
94-
// Serial.printf("\t > SERVO_US_MAX => SERVO_US_MIN: %i\n", uSec);
9584
}
9685

9786
delay(500);

examples/PCA9685/VibroPulse/VibroPulse.ino

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,17 @@ void setup() {
1717
Serial.begin(115200);
1818
Serial.println("I2CDevLib Example - PCA9685 Test");
1919

20-
if (!Wire.begin()) {
21-
Serial.println("[E] Failed to init Wire!");
22-
while(true) {};
23-
}
20+
Wire.begin();
2421

2522
// auto result = pca9685.setPrescale(100);
2623
result = pca9685.setFrequency(PWM_FREQ);
2724
if (result != I2CDEV_RESULT_OK) {
28-
Serial.printf("[E] Failed to set PCA9685 prescale: %i\n", result);
25+
Serial.println("[E] Failed to set PCA9685 prescale");
2926
while(true) {};
3027
}
3128
result = pca9685.wakeup();
3229
if (result != I2CDEV_RESULT_OK) {
33-
Serial.printf("[E] Failed wakeup PCA9685: %i\n", result);
30+
Serial.println("[E] Failed wakeup PCA9685");
3431
while(true) {};
3532
}
3633

@@ -46,7 +43,7 @@ void pulse(uint8_t pin) {
4643
uint8_t currentVibro = 0;
4744

4845
void loop() {
49-
Serial.printf("Current vibro: %i\n", currentVibro);
46+
Serial.print("Current vibro: "); Serial.println(currentVibro);
5047

5148
pulse(currentVibro);
5249
delay(100);

0 commit comments

Comments
 (0)