func main() { flag.Parse() if err := embd.InitI2C(); err != nil { panic(err) } defer embd.CloseI2C() bus := embd.NewI2CBus(1) baro := bmp180.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) } }
func initBMP180() error { myBMP180 = bmp180.New(i2cbus) //TODO: error checking. return nil }
func main() { glog.Info("main: starting up") flag.Parse() var car Car = NullCar if !*fakeCar { if err := embd.InitI2C(); err != nil { panic(err) } defer embd.CloseI2C() bus := embd.NewI2CBus(byte(*i2cBusNo)) var cam Camera = NullCamera if !*fakeCam { cam = NewCamera(*camWidth, *camHeight, *camTurnImage, *camFps) } defer cam.Close() cam.Run() var comp Compass = NullCompass if !*fakeCompass { comp = NewCompass(bus) } defer comp.Close() var rf RangeFinder = NullRangeFinder if !*fakeRangeFinder { thermometer := bmp180.New(bus) defer thermometer.Close() if err := embd.InitGPIO(); err != nil { panic(err) } defer embd.CloseGPIO() echoPin, err := embd.NewDigitalPin(*echoPinNumber) if err != nil { panic(err) } triggerPin, err := embd.NewDigitalPin(*triggerPinNumber) if err != nil { panic(err) } rf = NewRangeFinder(echoPin, triggerPin, thermometer) } defer rf.Close() var fw FrontWheel = NullFrontWheel if !*fakeFrontWheel { sb := servoblaster.New() defer sb.Close() pwm := sb.Channel(*sbChannel) servo := servo.New(pwm) fw = &frontWheel{servo} } defer fw.Turn(0) var engine Engine = NullEngine if !*fakeEngine { ctrl := pca9685.New(bus, 0x41) defer ctrl.Close() pwm := ctrl.AnalogChannel(15) engine = NewEngine(pwm) } defer engine.Stop() var gyro Gyroscope = NullGyroscope if !*fakeGyro { gyro = NewGyroscope(bus, l3gd20.R250DPS) } defer gyro.Close() car = NewCar(bus, cam, comp, rf, gyro, fw, engine) } defer car.Close() ws := NewWebServer(car) ws.Run() quit := make(chan os.Signal, 1) signal.Notify(quit, os.Interrupt, os.Kill) <-quit glog.Info("main: all done") }
func initBMP180() { bus = embd.NewI2CBus(1) i2csensor = bmp180.New(bus) }