@@ -172,19 +172,19 @@ def set_leg_io(self, leg_index, direction):
172172 def pwm_on (self , t2_prescale , full_period , on_period ):
173173 """Turns on the PWM generator with the given settings.
174174
175- :param t2_prescale: One of T2_PS_1_1, T2_PS_1_4, T2_PS_1_16
176- Scales down the 12MHz instruction clock by
177- 1, 4 or 16.
178- :param full_period: 8-bit value - which is scaled up to 10-bits
179- (<< 2) - to which timer 2 will count up to
180- before resetting PWM output to 1.
181- :param on_period: 10-bit value to which timer 2 will count up to
182- before setting PWM output to 0. Use this with
183- full_period to control duty cycle. For
184- example:
185-
186- # 12MHz / 16 with 50% duty cycle
187- codebug.pwm_on(T2_PS_1_16, 0xff, 0x200)
175+ Args:
176+ t2_prescale: One of T2_PS_1_1, T2_PS_1_4, T2_PS_1_16
177+ Scales down the 12MHz instruction clock by
178+ 1, 4 or 16.
179+ full_period: 8-bit value - which is scaled up to 10-bits
180+ (<< 2) - to which timer 2 will count up to
181+ before resetting PWM output to 1.
182+ on_period: 10-bit value to which timer 2 will count up to
183+ before setting PWM output to 0. Use this with
184+ full_period to control duty cycle. For example:
185+
186+ # 12MHz / 16 with 50% duty cycle
187+ codebug.pwm_on(T2_PS_1_16, 0xff, 0x200)
188188
189189 """
190190 # full period
@@ -335,6 +335,34 @@ def draw_sprite(self, x, y, sprite, clear_first=True):
335335 for i , row in enumerate (cb_rows ):
336336 self .or_mask (i , bytes (row ))
337337
338+ def scroll_sprite (self , sprite , interval = 0.1 , direction = 'L' ):
339+ """Scrolls a sprite.
340+
341+ Args:
342+ sprite: The sprite to scroll.
343+ interval: The time delay between each movement in seconds.
344+ (optional)
345+ direction: The direction of the scroll ('L', 'R', 'U', 'D').
346+
347+ """
348+ direction = direction .upper ()[0 ] # only take the first char
349+ if direction == 'L' :
350+ for i in range (sprite .width + 5 ):
351+ self .draw_sprite (5 - i , 0 , sprite )
352+ time .sleep (interval )
353+ elif direction == 'D' :
354+ for i in range (sprite .height + 5 ):
355+ self .draw_sprite (0 , 5 - i , sprite )
356+ time .sleep (interval )
357+ elif direction == 'R' :
358+ for i in reversed (range (sprite .width + 5 )):
359+ self .draw_sprite (5 - i , 0 , sprite )
360+ time .sleep (interval )
361+ elif direction == 'U' :
362+ for i in reversed (range (sprite .height + 5 )):
363+ self .draw_sprite (0 , 5 - i , sprite )
364+ time .sleep (interval )
365+
338366 def config_extension_io (self ):
339367 self .set (CHANNEL_INDEX_EXT_CONF , EXTENSION_CONF_IO )
340368
@@ -390,10 +418,12 @@ def i2c_transaction(self,
390418 """Run an I2C transaction using the extensions pins. Be sure to
391419 configure the extension pins first.
392420
393- :param add_stop_last_message: Adds stop flag to the last I2CMessage.
394- :type add_stop_last_message: boolean
395- :param interval: Adds delay of `interval` seconds between I2C messages.
396- :type interval: interger
421+ Args:
422+ messages: The I2C messages.
423+ add_stop_last_message: Adds stop flag to the last
424+ I2CMessage.
425+ interval: Adds delay of `interval` seconds between I2C
426+ messages.
397427
398428 Example:
399429
0 commit comments