Ejemplo n.º 1
0
func main() {
	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	baro := bmp085.New(bus)
	defer baro.Close()

	for {
		temp, err := baro.Temperature()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Temp is %v\n", temp)
		pressure, err := baro.Pressure()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Pressure is %v\n", pressure)
		altitude, err := baro.Altitude()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Altitude is %v\n", altitude)

		time.Sleep(500 * time.Millisecond)
	}
}
Ejemplo n.º 2
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)
	}
}