Skip to content

Commit edc313f

Browse files
committed
including error reporting
1 parent 09db66d commit edc313f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

examples/servo/main.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ int main(void) {
1111
return -1;
1212
}
1313

14-
uint16_t angle;
14+
uint16_t angle = 0;
1515

1616
// Changes the angle of the servomotor from 0 to 180 degrees (waiting 0.1 ms between every change).
1717
for (int i = 0; i <= 180; i++) {
18-
libtock_servo_angle(i);
19-
libtocksync_alarm_delay_ms(100);
20-
// Verifies if the function successfully returned the current angle.
21-
if (libtock_current_servo_angle(&angle) == RETURNCODE_SUCCESS) {
22-
printf("the current angle is: %d", angle);
18+
if (libtock_servo_angle(i) == RETURNCODE_SUCCESS) {
19+
libtocksync_alarm_delay_ms(100);
20+
// Verifies if the function successfully returned the current angle.
21+
if (libtock_current_servo_angle(&angle) == RETURNCODE_SUCCESS) {
22+
printf("The current angle is: %d\n", angle);
23+
} else {
24+
printf("\nThe servomotor is OFF\n");
25+
}
26+
} else {
27+
printf("\nThe angle could not be changed\n");
28+
return -1;
2329
}
2430
}
2531
}

0 commit comments

Comments
 (0)