Пример #1
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	controller, err := hd44780.NewI2C(
		bus,
		0x20,
		hd44780.PCF8574PinMap,
		hd44780.RowAddress20Col,
		hd44780.TwoLine,
		hd44780.BlinkOn,
	)
	if err != nil {
		panic(err)
	}

	display := characterdisplay.New(controller, 20, 4)
	defer display.Close()

	display.Clear()
	display.Message("Hello, world!\n@embd | characterdisplay")
	time.Sleep(10 * time.Second)
	display.BacklightOff()
}
Пример #2
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	hd, err := hd44780.NewI2C(
		bus,
		0x20,
		hd44780.PCF8574PinMap,
		hd44780.RowAddress20Col,
		hd44780.TwoLine,
		hd44780.BlinkOn,
	)
	if err != nil {
		panic(err)
	}
	defer hd.Close()

	hd.Clear()
	message := "Hello, world!"
	bytes := []byte(message)
	for _, b := range bytes {
		hd.WriteChar(b)
	}
	hd.SetCursor(0, 1)

	message = "@embd | hd44780"
	bytes = []byte(message)
	for _, b := range bytes {
		hd.WriteChar(b)
	}
	time.Sleep(10 * time.Second)
	hd.BacklightOff()
}
Пример #3
0
// NewLcd create and init new lcd output
func NewLcd() *Lcd {
	var l *Lcd
	defer func() {
		if e := recover(); e != nil {
			glog.Infof("NewLcd failed create - recover: %v", e)
		}
	}()

	l = &Lcd{
		Lines:     2,
		Width:     lcdWidth,
		lastLines: make([]string, 2, 2),
	}
	if configuration.DisplayConf.Display == "i2c" {
		l.addr = configuration.DisplayConf.I2CAddr
		glog.V(1).Infof("Starting hd44780 on i2c addr=%d", l.addr)

		if err := embd.InitI2C(); err != nil {
			glog.Error("Can't open lcd: ", err.Error())
			return nil
		}

		bus := embd.NewI2CBus(1)

		var err error
		l.hd, err = hd44780.NewI2C(
			bus,
			l.addr,
			hd44780.PCF8574PinMap,
			hd44780.RowAddress16Col,
			hd44780.TwoLine,
			//		hd44780.BlinkOff,
			hd44780.CursorOff,
			hd44780.EntryIncrement,
		)
		if err != nil {
			glog.Fatal("Can't open i2c lcd: ", err.Error())
			return nil
		}
	} else {
		glog.V(1).Infof("Starting hd44780 on GPIO")
		var err error
		l.hd, err = hd44780.NewGPIO(
			configuration.DisplayConf.GpioRs,
			configuration.DisplayConf.GpioEn,
			configuration.DisplayConf.GpioD4,
			configuration.DisplayConf.GpioD5,
			configuration.DisplayConf.GpioD6,
			configuration.DisplayConf.GpioD7,
			configuration.DisplayConf.GpioBl,
			hd44780.Positive,
			hd44780.RowAddress16Col,
			hd44780.TwoLine,
			//		hd44780.BlinkOff,
			hd44780.CursorOff,
			hd44780.EntryIncrement,
		)
		if err != nil {
			glog.Fatal("Can't open gpio lcd: ", err.Error())
			return nil
		}
	}

	l.hd.Clear()
	l.hd.BacklightOn()
	l.backlight = true

	l.active = true

	// Custom characters
	// play
	l.setChar(0, []byte{0x0, 0x8, 0xc, 0xe, 0xc, 0x8, 0x0, 0x0})
	// pause
	l.setChar(1, []byte{0x0, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x0, 0x0})
	// stop
	l.setChar(2, []byte{0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0, 0x0})

	return l
}