Skip to content

Commit 650d208

Browse files
author
Thomas Preston
committed
Added servo to core
1 parent a2e4f30 commit 650d208

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

codebug_tether/core.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
CHANNEL_INDEX_COLOURTAIL_CONTROL,
4343
CHANNEL_INDEX_PWM_CONF_0,
4444
CHANNEL_INDEX_PWM_CONF_1,
45-
CHANNEL_INDEX_PWM_CONF_2) = range(5, 30)
45+
CHANNEL_INDEX_PWM_CONF_2,
46+
CHANNEL_INDEX_SERVO_PULSE_LENGTH,
47+
CHANNEL_INDEX_SERVO_CONF) = range(5, 32)
4648

4749
EXTENSION_CONF_IO = 0x01
4850
EXTENSION_CONF_SPI = 0x02
@@ -216,6 +218,16 @@ def pwm_off(self):
216218
go_busy_off_mask = 0xff ^ (1 << 4)
217219
self.and_mask(CHANNEL_INDEX_PWM_CONF_2, go_busy_off_mask)
218220

221+
def servo_set(self, servo_index, pulse_length):
222+
pulse_length_msb = 0xff & (pulse_length >> 8)
223+
pulse_length_lsb = 0xff & pulse_length
224+
conf_msb = ((servo_index & 0xf) << 4) | 0x01
225+
conf_lsb = ((servo_index & 0xf) << 4) | 0x00
226+
self.set_bulk(CHANNEL_INDEX_SERVO_PULSE_LENGTH,
227+
[pulse_length_msb, conf_msb])
228+
self.set_bulk(CHANNEL_INDEX_SERVO_PULSE_LENGTH,
229+
[pulse_length_lsb, conf_lsb])
230+
219231
def clear(self):
220232
"""Clears the pixels on CodeBug.
221233

0 commit comments

Comments
 (0)