def digit_led_ascii(self, display_string):
"""This command controls the four 7 segment displays using ASCII character codes.
Arguments:
display_string: A four character string to be displayed. This must be four
characters. Any blank characters should be represented with a space: ' '
Due to the limited display, there is no control over upper or lowercase
letters. create2api will automatically convert all chars to uppercase, but
some letters (Such as 'B' and 'D') will still display as lowercase on the
Create 2's display. C'est la vie.
"""
noError = True
display_string = display_string.upper()
if len(display_string) == 4:
display_list = []
else:
#Too many or too few characters!
noError = False
raise _ROIDataByteError("Invalid ASCII input (Must be EXACTLY four characters)")
if noError:
#Need to map ascii to numbers from the dict.
for i in range (0,4):
#Check that the character is in the list, if it is, add it.
if display_string[i] in self.config.data['ascii table']:
display_list.append(self.config.data['ascii table'][display_string[i]])
else:
# Char was not available. Just print a blank space
# Raise an error so the software knows that the input was bad
display_list.append(self.config.data['ascii table'][' '])
warnings.formatwarning = custom_format_warning
warnings.warn("Warning: Char '" + display_string[i] + "' was not found in ascii table")
self.SCI.send(self.config.data['opcodes']['digit_led_ascii'], tuple(display_list))
else:
raise _ROIFailedToSendError("Invalid data, failed to send")
#NOTE ABOUT SONGS: For some reason you cannot play a new song immediately
#after playing a different one, only the first song will play. You have to
#time.sleep() at least a fraction of a second for the speaker to process
评论列表
文章目录