• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang beaglebone.NewBeagleboneAdaptor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: blinkLedOverAndOver

// Demos the Gobot Every function, which provides a way
// to trigger recurring functionality.
func blinkLedOverAndOver(gbot *gobot.Gobot) {

	// Create an instance of our chosen adapter type
	// and pass it to the LED driver. The names given here
	// are used in the management functionality.
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_15")

	// Robots in the Gobot colletion run a "work" function
	// when they fire
	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	// A Robot is a board or device, and is one of the things managed by a Gobot.
	// Here we make one with the adaptor and led objects we made above.
	// The constructor creates a new named robot, provided a connection and a device
	// which will map to something like a GPIO pin.

	// A Robot can be composed of as many Connections and Devices as you like,
	// meaning that you can create something out of a group of supported hardware pieces
	// and treat it in code as a single logical unit.
	robot := gobot.NewRobot("blinkBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
开发者ID:trevrosen,项目名称:gobot-demo,代码行数:36,代码来源:main.go


示例2: main

func main() {
	gbot := gobot.NewGobot()
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")

	work := func() {
		brightness := uint8(0)
		fadeAmount := uint8(5)

		gobot.Every(100*time.Millisecond, func() {
			led.Brightness(brightness)
			brightness = brightness + fadeAmount
			if brightness == 0 || brightness == 255 {
				fadeAmount = -fadeAmount
			}
		})
	}

	robot := gobot.NewRobot("pwmBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
开发者ID:aryanugroho,项目名称:gobot,代码行数:28,代码来源:beaglebone_led_brightness.go


示例3: main

func main() {
	gbot := gobot.NewGobot()
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	blinkm := i2c.NewBlinkMDriver(beagleboneAdaptor, "blinkm")

	work := func() {
		gobot.Every(3*time.Second, func() {
			r := byte(gobot.Rand(255))
			g := byte(gobot.Rand(255))
			b := byte(gobot.Rand(255))
			blinkm.Rgb(r, g, b)
			color, _ := blinkm.Color()
			fmt.Println("color", color)
		})
	}

	robot := gobot.NewRobot("blinkmBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{blinkm},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
开发者ID:aryanugroho,项目名称:gobot,代码行数:26,代码来源:beaglebone_blinkm.go


示例4: main

func main() {
	gbot := gobot.NewGobot()

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewDirectPinDriver(beagleboneAdaptor, "led", "P8_10")
	button := gpio.NewDirectPinDriver(beagleboneAdaptor, "button", "P8_9")

	work := func() {
		gobot.Every(500*time.Millisecond, func() {
			if button.DigitalRead() == 1 {
				led.DigitalWrite(1)
			} else {
				led.DigitalWrite(0)
			}
		})
	}

	robot := gobot.NewRobot("pinBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
开发者ID:heupel,项目名称:gobot,代码行数:27,代码来源:beaglebone_direct_pin.go


示例5: main

func main() {
	gbot := gobot.NewGobot()

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "button", "P8_9")

	work := func() {
		button.On(gpio.ButtonPush, func(data interface{}) {
			fmt.Println("button pressed")
		})

		button.On(gpio.ButtonRelease, func(data interface{}) {
			fmt.Println("button released")
		})
	}

	robot := gobot.NewRobot("makeyBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{button},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
开发者ID:ympons,项目名称:gobot,代码行数:26,代码来源:beaglebone_makey_button.go


示例6: main

func main() {
	gbot := gobot.NewGobot()

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "sensor", "P9_33")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")

	work := func() {
		sensor.On(sensor.Event("data"), func(data interface{}) {
			brightness := uint8(
				gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255),
			)
			fmt.Println("sensor", data)
			fmt.Println("brightness", brightness)
			led.Brightness(brightness)
		})
	}

	robot := gobot.NewRobot("sensorBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{sensor, led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
开发者ID:ympons,项目名称:gobot,代码行数:28,代码来源:beaglebone_led_brightness_with_analog_input.go


示例7: setDirectPin

// Run some simple GPIO interactions
// by taking control of the Direct Pin abstraction
func setDirectPin(state int) {
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "myDevice", "P9_12")

	// Initialize the internal representation of the pinout
	beagleboneAdaptor.Connect()

	// Cast to byte because we are returning an int from a function
	// and not passing in an int literal.
	gpioPin.DigitalWrite(byte(state))
}
开发者ID:trevrosen,项目名称:gobot-demo,代码行数:13,代码来源:main.go


示例8: main

func main() {

	// Use Gobot to control BeagleBone's digital pins directly

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "myDevice", "P9_12")

	// Initialize the internal representation of the pinout
	beagleboneAdaptor.Connect()

	// Cast to byte because we are returning an int from a function
	// and not passing in an int literal.
	gpioPin.DigitalWrite(byte(myStateFunction()))
}
开发者ID:aryanugroho,项目名称:gobot,代码行数:14,代码来源:beaglebone_basic_direct_pin.go


示例9: main

func main() {
	gbot := gobot.NewGobot()

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_12")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("blinkBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{led}, work))
	gbot.Start()
}
开发者ID:ninetwentyfour,项目名称:gobot,代码行数:16,代码来源:beaglebone_blink.go


示例10: main

func main() {
	gbot := gobot.NewGobot()
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	servo := gpio.NewServoDriver(beagleboneAdaptor, "servo", "P9_14")

	work := func() {
		gobot.Every(1*time.Second, func() {
			i := uint8(gobot.Rand(180))
			fmt.Println("Turning", i)
			servo.Move(i)
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("servoBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{servo}, work))
	gbot.Start()
}
开发者ID:ninetwentyfour,项目名称:gobot,代码行数:17,代码来源:beaglebone_servo.go


示例11: main

func main() {
	gbot := gobot.NewGobot()
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")

	sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "sensor", "P9_33")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")

	work := func() {
		gobot.Every(100*time.Millisecond, func() {
			val := sensor.Read()
			brightness := uint8(gobot.ToScale(gobot.FromScale(float64(val), 0, 1024), 0, 255))
			fmt.Println("sensor", val)
			fmt.Println("brightness", brightness)
			led.Brightness(brightness)
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("sensorBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{sensor, led}, work))
	gbot.Start()
}
开发者ID:ninetwentyfour,项目名称:gobot,代码行数:21,代码来源:beaglebone_led_brightness_with_analog_input.go


示例12: main

func main() {
	gbot := gobot.NewGobot()

	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "usr0")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("blinkBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
开发者ID:aryanugroho,项目名称:gobot,代码行数:22,代码来源:beaglebone_blink_usr_led.go


示例13: main

func main() {
	var code string
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	//NewDirectPinDriver returns a pointer - this wasn't immediately obvious to me
	splate := gpio.NewDirectPinDriver(beagleboneAdaptor, "splate", "P9_11")
	c := &serial.Config{Name: "/dev/ttyUSB0", Baud: 9600}
	u, err := serial.OpenPort(c)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	//Configure ZMQ publisher
	publisher, err := zmq.NewSocket(zmq.PUB)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	publisher.Bind("tcp://*:5556")
	//Configure ZMQ publisher
	go http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Code: "))
		w.Write([]byte(code))
	})
	// the anonymous function here allows us to call openDoor with splate remaining in scope
	go http.HandleFunc("/open", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Okay"))
		openDoor(*splate, publisher)
	})
	go http.ListenAndServe(":8080", nil)
	buf := make([]byte, 16)
	for {
		n, err := io.ReadFull(u, buf)
		if err != nil {
			fmt.Print(err)
			os.Exit(1)
		}
		// We need to strip the stop and start bytes from the tag, so we only assign a certain range of the slice
		code = string(buf[1 : n-3])
		var request bytes.Buffer
		request.WriteString("https://members.pumpingstationone.org/rfid/check/FrontDoor/")
		request.WriteString(code)
		resp, err := http.Get(request.String())
		if err != nil {
			fmt.Printf("Whoops!")
			publisher.SendMessage("door.rfid.error", fmt.Sprintf("Auth Server Error: %s", err))
			os.Exit(1)
		}
		if resp.StatusCode == 200 {
			fmt.Println("Success!")
			publisher.SendMessage("door.rfid.accept", "RFID Accepted")
			code = ""
			openDoor(*splate, publisher)
		} else if resp.StatusCode == 403 {
			fmt.Println("Membership status: Expired")
			publisher.SendMessage("door.rfid.deny", "RFID Denied")
		} else {
			fmt.Println("Code not found")
			publisher.SendMessage("door.rfid.deny", "RFID not found")
		}
	}

}
开发者ID:iiie,项目名称:ps1rfid,代码行数:62,代码来源:main.go


示例14: main

func main() {
	var code string
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	//NewDirectPinDriver returns a pointer - this wasn't immediately obvious to me
	splate := gpio.NewDirectPinDriver(beagleboneAdaptor, "splate", "P9_11")
	c := &serial.Config{Name: "/dev/ttyUSB0", Baud: 9600}
	u, err := serial.OpenPort(c)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	//Configure ZMQ publisher
	publisher, err := zmq.NewSocket(zmq.PUB)
	if err != nil {
		fmt.Print(err)
		os.Exit(1)
	}
	publisher.Bind("tcp://*:5556")
	//Configure ZMQ publisher
	go http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Code: "))
		w.Write([]byte(code))
	})
	// the anonymous function here allows us to call openDoor with splate remaining in scope
	go http.HandleFunc("/open", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Okay"))
		openDoor(*splate, publisher)
	})
	go http.ListenAndServe(":8080", nil)
	buf := make([]byte, 16)
	for {
		n, err := io.ReadFull(u, buf)
		if err != nil {
			fmt.Print(err)
			os.Exit(1)
		}
		// We need to strip the stop and start bytes from the tag, so we only assign a certain range of the slice
		code = string(buf[1 : n-3])

		// Now open the cache db to check if it's already here
		cacheDB, err = bolt.Open("rfid-tags.db", 0600, nil)
		if err != nil {
			fmt.Println(err)
		}

		cacheDB.Update(func(tx *bolt.Tx) error {
			_, err := tx.CreateBucketIfNotExists([]byte("RFIDBucket"))
			if err != nil {
				return fmt.Errorf("create bucket: %s", err)
			}
			return nil
		})

		// Before checking the site for the code, let's check our cache
		if checkCacheDBForTag(code) == false {
			var request bytes.Buffer
			request.WriteString("https://members.pumpingstationone.org/rfid/check/FrontDoor/")
			request.WriteString(code)
			resp, err := http.Get(request.String())
			if err != nil {
				fmt.Printf("Whoops!")
				publisher.SendMessage("door.rfid.error", fmt.Sprintf("Auth Server Error: %s", err))
				os.Exit(1)
			}
			if resp.StatusCode == 200 {

				// We got 200 back, so we're good to add this
				// tag to the cache
				addTagToCacheDB(code)

				fmt.Println("Success!")
				publisher.SendMessage("door.rfid.accept", "RFID Accepted")
				code = ""
				openDoor(*splate, publisher)
			} else if resp.StatusCode == 403 {
				fmt.Println("Membership status: Expired")
				publisher.SendMessage("door.rfid.deny", "RFID Denied")
			} else {
				fmt.Println("Code not found")
				publisher.SendMessage("door.rfid.deny", "RFID not found")
			}
		} else {
			// If we're here, we found the tag in the cache, so
			// let's just go and open the door for 'em
			fmt.Println("Success!")
			publisher.SendMessage("door.rfid.accept", "RFID Accepted")
			code = ""
			openDoor(*splate, publisher)
		}

		cacheDB.Close()
	}
}
开发者ID:tachoknight,项目名称:ps1rfid,代码行数:93,代码来源:main.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang firmata.NewFirmataAdaptor函数代码示例发布时间:2022-05-28
下一篇:
Golang gobottest.Refute函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap