From b48bc5ac5d795bcbd6fafd5592cc992008698ae9 Mon Sep 17 00:00:00 2001 From: Alan Wang <44191076+alankrantas@users.noreply.github.com> Date: Fri, 24 Dec 2021 17:19:29 +0800 Subject: [PATCH] Update hd44780i2c.go --- hd44780i2c/hd44780i2c.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hd44780i2c/hd44780i2c.go b/hd44780i2c/hd44780i2c.go index d81af60..3005f4f 100644 --- a/hd44780i2c/hd44780i2c.go +++ b/hd44780i2c/hd44780i2c.go @@ -101,7 +101,7 @@ func (d *Device) Configure(cfg Config) error { return nil } -// ClearDisplay clears all texts on the display. +// ClearDisplay clears all texts on the display and sets the cursor back to position (0, 0). func (d *Device) ClearDisplay() { d.sendCommand(DISPLAY_CLEAR) d.cursor.x = 0 @@ -117,9 +117,10 @@ func (d *Device) Home() { delayus(2000) } -// SetCursor sets the cursor to a specific position (x, y). +// SetCursor sets the cursor to a specific position (x, y). // -// if y (row) is set larger than actual rows, it would be set to 0. +// For example, on 16x2 LCDs the range of x (column) is 0~15 and y (row) is 0~1. +// if y is larger than actual rows, it would be set to 0 (restart from first row). func (d *Device) SetCursor(x, y uint8) { rowOffset := []uint8{0x0, 0x40, 0x14, 0x54} if y > (d.height - 1) { @@ -139,11 +140,11 @@ func (d *Device) Print(data []byte) { if chr == '\n' { d.newLine() } else { - d.cursor.x++ if d.cursor.x >= d.width { d.newLine() } d.sendData(uint8(rune(chr))) + d.cursor.x++ } } }