Esempio n. 1
0
func init() {
	rpi.WiringPiSetup()
	pcd8544.LCDInit(SCLK, DIN, DC, CS, RST, CONTRAST)
	pcd8544.LCDclear()
	pcd8544.LCDdisplay()

}
Esempio n. 2
0
func gpio_cleanup() {
	pcd8544.LCDclear()
	pcd8544.LCDdisplay()

	rpi.PinMode(SCLK, rpi.INPUT)
	rpi.PinMode(DIN, rpi.INPUT)
	rpi.PinMode(DC, rpi.INPUT)
	rpi.PinMode(CS, rpi.INPUT)
	rpi.PinMode(RST, rpi.INPUT)
}
Esempio n. 3
0
func main() {
	sig := make(chan os.Signal, 1)
	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)
	baro := bmp085.New(bus)
	defer baro.Close()

	// Draw the outline
	pcd8544.LCDdrawrect(6-1, 6-1, pcd8544.LCDWIDTH-6, pcd8544.LCDHEIGHT-6, pcd8544.BLACK)
	// date string changes slowly
	var (
		date_str string
		temp_str string
	)

	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		s := <-sig
		fmt.Println(s)
		gpio_cleanup()
		os.Exit(0)
	}()

	keep_running := true
	for keep_running {
		// Get temperature
		temp, err := baro.Temperature()
		if err != nil {
			gpio_cleanup()
			panic(err)
		}
		_temp_str := fmt.Sprint(strconv.FormatFloat(temp, 'f', 2, 64), " C")

		time_str, _date_str := get_time()
		pcd8544.LCDdrawstring(20, 12, time_str)
		if date_str != _date_str {
			date_str = _date_str
			pcd8544.LCDdrawstring(18, 24, date_str)
		}
		if temp_str != _temp_str {
			temp_str = _temp_str
			pcd8544.LCDdrawstring(20, 36, temp_str)
		}
		pcd8544.LCDdisplay()
		// wait for 1 sec
		time.Sleep(time.Second)
	}
}