コード例 #1
0
ファイル: test2.go プロジェクト: d2r2/go-hd44780
func main() {
	i2c, err := device.NewI2C(0x27, 2)
	checkError(err)
	defer i2c.Close()
	lcd, err := device.NewLcd(i2c, device.LCD_16x2)
	checkError(err)
	err = lcd.BacklightOn()
	checkError(err)
	m := &sync.Mutex{}
	blink := false
	go func() {
		//writeTime(lcd, time.Now(), blink, m)
		c := time.Tick(1 * time.Second)
		for t := range c {
			writeTime(lcd, t, blink, m)
			blink = !blink
		}
	}()

	for {
		temp, hum, _, err := sensor.ReadDHTxxWithRetry(sensor.DHT11, 4, 5, true)
		if err == nil {
			m.Lock()
			lcd.ShowMessage(fmt.Sprintf("T: %v*C Hum: %v%%", temp, hum),
				device.SHOW_LINE_2|device.SHOW_ELIPSE_IF_NOT_FIT)
			m.Unlock()
		} else {
			m.Lock()
			lcd.ShowMessage("DHTxx read error",
				device.SHOW_LINE_2|device.SHOW_ELIPSE_IF_NOT_FIT)
			m.Unlock()
		}
		time.Sleep(10 * time.Second)
	}
}
コード例 #2
0
ファイル: test1.go プロジェクト: d2r2/go-hd44780
func main() {
	i2c, err := device.NewI2C(0x27, 2)
	checkError(err)
	defer i2c.Close()
	lcd, err := device.NewLcd(i2c, device.LCD_20x4)
	checkError(err)
	err = lcd.BacklightOn()
	checkError(err)
	err = lcd.ShowMessage("--=! Let's rock !=--", device.SHOW_LINE_1)
	checkError(err)
	err = lcd.ShowMessage("Welcome to RPi dude!", device.SHOW_LINE_2)
	checkError(err)
	err = lcd.ShowMessage("I'm lazy to be lazy.", device.SHOW_LINE_3)
	checkError(err)
	err = lcd.ShowMessage("R2D2, where are you?", device.SHOW_LINE_4)
	checkError(err)
	time.Sleep(5 * time.Second)
	for i := 0; i <= 12; i++ {
		var buf bytes.Buffer
		for j := 0; j <= 19; j++ {
			buf.Write([]byte{byte(i*20 + j)})
		}
		err = lcd.ShowMessage(buf.String(), device.SHOW_LINE_1)
		checkError(err)
		time.Sleep(1 * time.Second)
	}
	time.Sleep(5 * time.Second)
	err = lcd.TestWriteCGRam()
	checkError(err)
	for i := 0; i <= 12; i++ {
		var buf bytes.Buffer
		for j := 0; j <= 19; j++ {
			buf.Write([]byte{byte(i*20 + j)})
		}
		err = lcd.ShowMessage(buf.String(), device.SHOW_LINE_1)
		checkError(err)
		time.Sleep(1 * time.Second)
	}
	lcd.Clear()
	for {
		lcd.Home()
		t := time.Now()
		lcd.SetPosition(1, 0)
		fmt.Fprint(lcd, t.Format("Monday Jan 2"))
		lcd.SetPosition(2, 1)
		fmt.Fprint(lcd, t.Format("15:04:05 2006"))
		//		lcd.SetPosition(4, 0)
		//		fmt.Fprint(lcd, "i2c, VGA, and Go")
		time.Sleep(666 * time.Millisecond)
	}

}
コード例 #3
0
ファイル: main.go プロジェクト: d2r2/go-hd44780
func main() {
	i2c, err := device.NewI2C(0x27, 2)
	check(err)
	defer i2c.Close()
	lcd, err := device.NewLcd(i2c, device.LCD_16x2)
	check(err)
	lcd.BacklightOn()
	lcd.Clear()
	for {
		lcd.Home()
		t := time.Now()
		lcd.SetPosition(0, 0)
		fmt.Fprint(lcd, t.Format("Monday Jan 2"))
		lcd.SetPosition(1, 0)
		fmt.Fprint(lcd, t.Format("15:04:05 2006"))
		//		lcd.SetPosition(4, 0)
		//		fmt.Fprint(lcd, "i2c, VGA, and Go")
		time.Sleep(333 * time.Millisecond)
	}
}
コード例 #4
0
ファイル: test3.go プロジェクト: d2r2/go-hd44780
func main() {
	i2c, err := device.NewI2C(0x27, 2)
	checkError(err)
	defer i2c.Close()
	lcd, err := device.NewLcd(i2c, device.LCD_20x4)
	checkError(err)
	err = lcd.BacklightOn()
	checkError(err)
	var msg = []string{
		"--=! Let's rock !=--",
		"Welcome to RPi dude!",
		"I'm lazy to be lazy.",
		"R2D2, where are you?",
	}
	lines := []device.ShowOptions{device.SHOW_LINE_1, device.SHOW_LINE_2,
		device.SHOW_LINE_3, device.SHOW_LINE_4}
	i := 0
	for {
		var j byte
		for j = 0; j < 4; j++ {
			k := (i + int(j)) % 4
			err = lcd.ShowMessage(msg[k], lines[j])
			checkError(err)
		}
		time.Sleep(2 * time.Second)
		for j = 0; j < 4; j++ {
			err = lcd.ShowMessage(strings.Repeat(" ", 20), lines[j])
			checkError(err)
		}
		err = lcd.BacklightOff()
		checkError(err)
		time.Sleep(2 * time.Second)
		err = lcd.BacklightOn()
		checkError(err)
		i++
	}
}
コード例 #5
0
ファイル: test4.go プロジェクト: d2r2/go-hd44780
func main() {
	i2c, err := device.NewI2C(0x27, 2)
	checkError(err)
	defer i2c.Close()
	lcd, err := device.NewLcd(i2c, device.LCD_16x2)
	checkError(err)
	err = lcd.BacklightOn()
	checkError(err)
	/*	var msg = []string{
		"--=! Let's rock !=--",
		"Welcome to RPi dude!",
		"I'm lazy to be lazy.",
		"R2D2, where are you?",
	}*/
	err = lcd.ShowMessage("Hello world !!! How are you? How are you",
		device.SHOW_LINE_1|device.SHOW_LINE_2|
			device.SHOW_ELIPSE_IF_NOT_FIT|device.SHOW_BLANK_PADDING)
	checkError(err)
	time.Sleep(3 * time.Second)
	err = lcd.ShowMessage("Welcome to RPi!!!",
		device.SHOW_LINE_1|device.SHOW_LINE_2|
			device.SHOW_ELIPSE_IF_NOT_FIT|device.SHOW_BLANK_PADDING)
	checkError(err)
}