#NEWLINE# def begin( self , cols , rows ) : #NEWLINE# #INDENT# ' Initializes the LCD driver and sets it to the given number of rows\n        and columns. ' #NEWLINE# assert ( ( cols == 8 ) or ( cols == 16 ) or ( cols == 20 ) ) , 'LiquidCrystal only supports 8, 16 and 20 row displays' #NEWLINE# assert ( ( rows == 1 ) or ( rows == 2 ) or ( rows == 4 ) ) , 'LiquidCrystal only supports 1, 2 and 4 column displays' #NEWLINE# self . cols = cols #NEWLINE# self . rows = rows #NEWLINE# for pin in ( ( self . rs , self . enable ) + self . data_pins ) : #NEWLINE# #INDENT# bbio . pinMode ( pin , bbio . OUTPUT ) #NEWLINE# #UNINDENT# if self . rw : #NEWLINE# #INDENT# bbio . pinMode ( self . rw , bbio . OUTPUT ) #NEWLINE# #UNINDENT# bbio . digitalWrite ( self . enable , bbio . LOW ) #NEWLINE# if ( self . mode_bits == 8 ) : #NEWLINE# #INDENT# self . writeCommand ( ( self . COMMAND_FUNCTIONSET | self . FUNCTIONSET_8BIT ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _write4bits ( ( ( self . COMMAND_FUNCTIONSET | self . FUNCTIONSET_8BIT ) >> 4 ) ) #NEWLINE# #UNINDENT# bbio . delay ( 5 ) #NEWLINE# if ( self . mode_bits == 8 ) : #NEWLINE# #INDENT# self . writeCommand ( ( self . COMMAND_FUNCTIONSET | self . FUNCTIONSET_8BIT ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _write4bits ( ( ( self . COMMAND_FUNCTIONSET | self . FUNCTIONSET_8BIT ) >> 4 ) ) #NEWLINE# #UNINDENT# bbio . delay ( 5 ) #NEWLINE# if ( self . mode_bits == 8 ) : #NEWLINE# #INDENT# self . writeCommand ( ( self . COMMAND_FUNCTIONSET | self . FUNCTIONSET_8BIT ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _write4bits ( ( ( self . COMMAND_FUNCTIONSET | self . FUNCTIONSET_8BIT ) >> 4 ) ) #NEWLINE# #UNINDENT# function_set = 0 #NEWLINE# if ( self . mode_bits == 8 ) : #NEWLINE# #INDENT# function_set = self . FUNCTIONSET_8BIT #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _write4bits ( ( self . COMMAND_FUNCTIONSET >> 4 ) ) #NEWLINE# #UNINDENT# if ( self . rows > 1 ) : #NEWLINE# #INDENT# function_set |= self . FUNCTIONSET_2LINE #NEWLINE# #UNINDENT# self . writeCommand ( ( self . COMMAND_FUNCTIONSET | function_set ) ) #NEWLINE# self . setDisplay ( self . OFF ) #NEWLINE# self . clear ( ) #NEWLINE# self . _entry_mode = self . ENTRYMODE_SHIFTRIGHT #NEWLINE# self . writeCommand ( ( self . COMMAND_ENTRYMODE | self . _entry_mode ) ) #NEWLINE# self . setDisplay ( self . ON )