def LCD_Reset(self): GPIO.output(LCD_Config.LCD_RST_PIN, GPIO.HIGH) LCD_Config.Driver_Delay_ms(100) GPIO.output(LCD_Config.LCD_RST_PIN, GPIO.LOW) LCD_Config.Driver_Delay_ms(100) GPIO.output(LCD_Config.LCD_RST_PIN, GPIO.HIGH) LCD_Config.Driver_Delay_ms(100)
def LCD_Init(self, Lcd_ScanDir): if (LCD_Config.GPIO_Init() != 0): return -1 #Turn on the backlight GPIO.output(LCD_Config.LCD_BL_PIN, GPIO.HIGH) #Hardware reset self.LCD_Reset() #Set the initialization register self.LCD_InitReg() #Set the display scan and color transfer modes self.LCD_SetGramScanWay(Lcd_ScanDir) LCD_Config.Driver_Delay_ms(200) #sleep out self.LCD_WriteReg(0x11) LCD_Config.Driver_Delay_ms(120) #Turn on the LCD display self.LCD_WriteReg(0x29) self.LCD_Clear(0xffff)
def main(): LCD = LCD_1in8.LCD() print ("**********Init LCD**********") Lcd_ScanDir = LCD_1in8.SCAN_DIR_DFT #SCAN_DIR_DFT = D2U_L2R LCD.LCD_Init(Lcd_ScanDir) LCD.LCD_Clear(0xffff) image = Image.new("RGB", (LCD.LCD_Dis_Column, LCD.LCD_Dis_Page), "WHITE") draw = ImageDraw.Draw(image) font18 = ImageFont.truetype(picdir+'/Font.ttc', 18) if (Lcd_ScanDir == LCD_1in8.L2R_U2D) or (Lcd_ScanDir == LCD_1in8.L2R_D2U) or (Lcd_ScanDir == LCD_1in8.R2L_U2D) or (Lcd_ScanDir == LCD_1in8.R2L_D2U) : print ("***draw") draw.line([(0,0),(127,0)], fill = "BLUE",width = 5) draw.line([(127,0),(127,159)], fill = "BLUE",width = 5) draw.line([(127,159),(0,159)], fill = "BLUE",width = 5) draw.line([(0,159),(0,0)], fill = "BLUE",width = 5) draw.rectangle([(18,10),(110,20)],fill = "RED") draw.rectangle((50, 85, 85, 120), outline = "Pink") draw.arc((55, 90, 80, 115), 0, 360, fill = 0) draw.line([(50,85),(85,120)], fill = "BLUE",width = 2) draw.line([(50,120),(85,85)], fill = "BLUE",width = 2) print ("***draw text") draw.text((33, 22), 'WaveShare ', fill = "purple") draw.text((33, 36), 'Electronic ', fill = "Orange") draw.text((33, 48), '1234567890', fill = "BLUE") draw.text((33, 62), u'微雪电子', font = font18, fill = "red") LCD.LCD_ShowImage(image) LCD_Config.Driver_Delay_ms(3000) draw = ImageDraw.Draw(image) image = Image.open(picdir+'/Himage.bmp') LCD.LCD_ShowImage(image) # LCD_Config.Driver_Delay_ms(3000) else: print ("***draw") draw.line([(0,0),(159,0)], fill = "BLUE",width = 5) draw.line([(159,0),(159,127)], fill = "BLUE",width = 5) draw.line([(159,127),(0,127)], fill = "BLUE",width = 5) draw.line([(0,127),(0,0)], fill = "BLUE",width = 5) draw.rectangle([(18,10),(142,20)],fill = "RED") draw.rectangle((50, 85, 85, 120), outline = "Pink") draw.arc((55, 90, 80, 115), 0, 360, fill = 0) draw.line([(50,85),(85,120)], fill = "BLUE",width = 2) draw.line([(50,120),(85,85)], fill = "BLUE",width = 2) print ("***draw text") draw.text((33, 22), 'WaveShare ', fill = "purple") draw.text((33, 36), 'Electronic ', fill = "Orange") draw.text((33, 48), '1234567890', fill = "BLUE") draw.text((33, 62), u'微雪电子', font = font18, fill = "red") LCD.LCD_ShowImage(image) LCD_Config.Driver_Delay_ms(3000) draw = ImageDraw.Draw(image) image = Image.open(picdir+'/welcome.bmp') LCD.LCD_ShowImage(image)
def LCD_Clear(self, color): _buffer = [color] * (self.LCD_Dis_Column * self.LCD_Dis_Page * 2) if (self.LCD_Scan_Dir == L2R_U2D) or (self.LCD_Scan_Dir == L2R_D2U) or ( self.LCD_Scan_Dir == R2L_U2D) or (self.LCD_Scan_Dir == R2L_D2U): # self.LCD_SetArealColor(0,0, LCD_X_MAXPIXEL , LCD_Y_MAXPIXEL , Color = color)#white self.LCD_SetWindows(0, 0, LCD_X_MAXPIXEL, LCD_Y_MAXPIXEL) GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) for i in range(0, len(_buffer), 4096): LCD_Config.SPI_Write_Byte(_buffer[i:i + 4096]) else: # self.LCD_SetArealColor(0,0, LCD_Y_MAXPIXEL , LCD_X_MAXPIXEL , Color = color)#white self.LCD_SetWindows(0, 0, LCD_Y_MAXPIXEL, LCD_X_MAXPIXEL) GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) for i in range(0, len(_buffer), 4096): LCD_Config.SPI_Write_Byte(_buffer[i:i + 4096])
def LCD_ShowImage(self, Image): if (Image == None): return self.LCD_SetWindows(0, 0, self.LCD_Dis_Column, self.LCD_Dis_Page) GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) # Pixels = Image.load() img = np.asarray(Image) pix = np.zeros((Image.height, Image.width, 2), dtype=np.uint8) pix[..., [0]] = np.add(np.bitwise_and(img[..., [0]], 0xF8), np.right_shift(img[..., [1]], 5)) pix[..., [1]] = np.add( np.bitwise_and(np.left_shift(img[..., [1]], 3), 0xE0), np.right_shift(img[..., [2]], 3)) pix = pix.flatten().tolist() for i in range(0, len(pix), 4096): LCD_Config.SPI_Write_Byte(pix[i:i + 4096])
def LCD_WriteData_NLen16Bit(self, Data, DataLen): GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) for i in range(0, DataLen): LCD_Config.SPI_Write_Byte([Data >> 8]) LCD_Config.SPI_Write_Byte([Data & 0xff])
def LCD_WriteData_8bit(self, Data): GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) LCD_Config.SPI_Write_Byte([Data])
def LCD_WriteReg(self, Reg): GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.LOW) LCD_Config.SPI_Write_Byte([Reg])