当前位置: 首页>>代码示例>>Golang>>正文


Golang embd.NewI2CBus函数代码示例

本文整理汇总了Golang中github.com/kidoman/embd.NewI2CBus函数的典型用法代码示例。如果您正苦于以下问题:Golang NewI2CBus函数的具体用法?Golang NewI2CBus怎么用?Golang NewI2CBus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewI2CBus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

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

	bus := embd.NewI2CBus(1)

	sensor := tmp006.New(bus, 0x40)
	if status, err := sensor.Present(); err != nil || !status {
		fmt.Println("tmp006: not found")
		fmt.Println(err)
		return
	}
	defer sensor.Close()

	sensor.Start()

	stop := make(chan os.Signal, 1)
	signal.Notify(stop, os.Interrupt, os.Kill)

	for {
		select {
		case temp := <-sensor.ObjTemps():
			fmt.Printf("tmp006: got obj temp %.2f\n", temp)
		case temp := <-sensor.RawDieTemps():
			fmt.Printf("tmp006: got die temp %.2f\n", temp)
		case <-stop:
			return
		}
	}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:32,代码来源:tmp006.go

示例2: main

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!\[email protected] | characterdisplay")
	time.Sleep(10 * time.Second)
	display.BacklightOff()
}
开发者ID:npotts,项目名称:embd,代码行数:30,代码来源:characterdisplay.go

示例3: main

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)
	}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:33,代码来源:bmp180.go

示例4: main

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

	bus := embd.NewI2CBus(1)

	gyro := l3gd20.New(bus, l3gd20.R250DPS)
	defer gyro.Close()

	gyro.Start()

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, os.Interrupt, os.Kill)

	orientations, err := gyro.Orientations()
	if err != nil {
		panic(err)
	}

	timer := time.Tick(250 * time.Millisecond)

	for {
		select {
		case <-timer:
			orientation := <-orientations
			fmt.Printf("x: %v, y: %v, z: %v\n", orientation.X, orientation.Y, orientation.Z)
		case <-quit:
			return
		}
	}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:33,代码来源:l3gd20.go

示例5: main

func main() {
	flag.Parse()

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

	bus := embd.NewI2CBus(1)

	dac := mcp4725.New(bus, 0x62)
	defer dac.Close()

	stop := make(chan os.Signal, 1)
	signal.Notify(stop, os.Interrupt, os.Kill)

	for {
		select {
		case <-stop:
			return
		default:
			voltage := rand.Intn(4096)
			if err := dac.SetVoltage(voltage); err != nil {
				fmt.Printf("mcp4725: %v\n", err)
			}
		}
	}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:28,代码来源:mcp4725.go

示例6: main

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)
	}
}
开发者ID:JokerQyou,项目名称:nlcd,代码行数:52,代码来源:digital_clock.go

示例7: Init

func (pd *PiioDigital) Init(address byte, numGpios int) {
	// initialize the Error!
	Error = log.New(os.Stderr,
		"ERROR: ",
		log.Ldate|log.Ltime|log.Lshortfile)
	var err error

	if numGpios < 0 || numGpios > 16 {
		Error.Fatal("Number of Gpios must be between 0 and 16.")
	}

	pd.i2c = embd.NewI2CBus(address)
	pd.address = address
	pd.numGpios = uint(numGpios)

	// set defaults
	if numGpios <= 8 {
		if err := pd.i2c.WriteByte(Mcp23017IoDirA, 0xFF); err != nil { // all inputs on port A
			Error.Fatal("Unable to write byte.")
		}
		if pd.direction, err = pd.i2c.ReadByte(Mcp23017IoDirA); err != nil {
			Error.Fatal("Unable to write byte.")
		}
		if err := pd.i2c.WriteByte(Mcp23008GppuA, 0x00); err != nil {
			Error.Fatal("Unable to write byte.")
		}
	} else if numGpios > 8 {
		if err := pd.i2c.WriteByte(Mcp23017IoDirA, 0XFF); err != nil { // all inputs on port A
			Error.Print(err)
			Error.Fatal("Unable to write byte.")
		}
		if err := pd.i2c.WriteByte(Mcp23017IoDirB, 0XFF); err != nil { // all inpots on port B
			Error.Fatal("Unable to write byte.")
		}
		var t1, t2 byte
		if t1, err = pd.i2c.ReadByte(Mcp23017IoDirA); err != nil {
			Error.Fatal("Unable to read byte.")
		}
		if t2, err = pd.i2c.ReadByte(Mcp23017IoDirB); err != nil {
			Error.Fatal("Unable to read byte.")
		}
		pd.direction = t1 | (t2 << 8)
		if err := pd.i2c.WriteByte(Mcp23017GppuA, 0x00); err != nil {
			Error.Fatal("Unable to write byte.")
		}
		if err := pd.i2c.WriteByte(Mcp23017GppuB, 0x00); err != nil {
			Error.Fatal("Unable to write byte.")
		}
	}
}
开发者ID:bjschafer,项目名称:piio-go,代码行数:50,代码来源:digital.go

示例8: main

func main() {
	flag.Parse()

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

	bus := embd.NewI2CBus(1)

	d := pca9685.New(bus, 0x41)
	d.Freq = 50
	defer d.Close()

	pwm := d.ServoChannel(0)

	servo := servo.New(pwm)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	turnTimer := time.Tick(500 * time.Millisecond)
	left := true

	servo.SetAngle(90)
	defer func() {
		servo.SetAngle(90)
	}()

	for {
		select {
		case <-turnTimer:
			left = !left
			switch left {
			case true:
				servo.SetAngle(70)
			case false:
				servo.SetAngle(110)
			}
		case <-c:
			return
		}
	}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:44,代码来源:servo.go

示例9: main

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

	bus := embd.NewI2CBus(1)

	mems := lsm303.New(bus)
	defer mems.Close()

	for {
		heading, err := mems.Heading()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Heading is %v\n", heading)

		time.Sleep(500 * time.Millisecond)
	}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:21,代码来源:lsm303.go

示例10: main

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

	bus := embd.NewI2CBus(1)

	sensor := bh1750fvi.New(bh1750fvi.High, bus)
	defer sensor.Close()

	for {
		lighting, err := sensor.Lighting()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Lighting is %v lx\n", lighting)

		time.Sleep(500 * time.Millisecond)
	}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:21,代码来源:bh1750fvi.go

示例11: main

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()
}
开发者ID:npotts,项目名称:embd,代码行数:39,代码来源:hd44780.go

示例12: main

func main() {
	flag.Parse()

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

	bus := embd.NewI2CBus(1)

	pca9685 := pca9685.New(bus, 0x41)
	pca9685.Freq = 1000
	defer pca9685.Close()

	if err := pca9685.SetPwm(15, 0, 2000); err != nil {
		panic(err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	timer := time.Tick(2 * time.Second)
	sleeping := false

	for {
		select {
		case <-timer:
			sleeping = !sleeping
			if sleeping {
				pca9685.Sleep()
			} else {
				pca9685.Wake()
			}
		case <-c:
			return
		}
	}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:38,代码来源:pca9685.go

示例13: main

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")
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:92,代码来源:main.go

示例14: main

func main() {
	var zoneFlag zoneslice
	var timeout time.Duration
	var verbose bool
	var repeat uint64

	flag.DurationVar(&timeout, "timeout", 10*time.Second, "amount of time to run each zone")
	flag.Uint64Var(&repeat, "repeat", 1, "how many times to repeat the zone list")
	flag.BoolVar(&verbose, "verbose", false, "whether or not to be verbose")
	flag.Var(&zoneFlag, "zone", "comma-separated list of zones to use")
	flag.Parse()

	if len(zoneFlag) == 0 {
		fmt.Fprintf(os.Stderr, "No zone specified\n")
		flag.PrintDefaults()
		os.Exit(1)
	}

	if timeout == 0 && len(zoneFlag) > 1 {
		fmt.Fprintf(os.Stderr, "No timeout with multiple zones\n")
		os.Exit(1)
	}

	if repeat == 0 {
		fmt.Fprintf(os.Stderr, "Nothing to do!\n")
		os.Exit(1)
	}

	if repeat > 1 && len(zoneFlag) == 1 {
		fmt.Fprintf(os.Stderr, "Repeating only one zone\n")
		os.Exit(1)
	}

	if timeout > 0 && timeout < 5*time.Second {
		fmt.Fprintf(os.Stderr, "Increasing timeout to 5s\n")
		timeout = 5 * time.Second
	}

	if verbose {
		fmt.Printf("Zones: %v\n", zoneFlag)
		fmt.Printf("Repeating: %d\n", repeat)
		fmt.Printf("Timeout: %v\n", timeout)
	}

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

	bus := embd.NewI2CBus(1)
	defer bus.Close()

	pcf8574 := pcf8574.New(bus, 0x20)
	defer pcf8574.SetByte(^byte(0))

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	timer := time.Tick(timeout)

	for i := uint64(0); i < repeat; i++ {
		for _, zone := range zoneFlag {
			input := ^(byte(1) << (zone - 1))
			pcf8574.SetByte(input)
			if verbose {
				fmt.Printf("Zone: %d Input: %08b\n", zone, input)
			}
			select {
			case <-timer:
				continue
			case <-c:
				return
			}
		}
	}
}
开发者ID:PSUdaemon,项目名称:sprinkler,代码行数:76,代码来源:sprinkler.go

示例15: initMPU6050

func initMPU6050() {
	bus = embd.NewI2CBus(1)
	attSensor = mpu6050.New(bus)
}
开发者ID:rahlfors,项目名称:stratux,代码行数:4,代码来源:sensortest.go


注:本文中的github.com/kidoman/embd.NewI2CBus函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。