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

	r := raspi.NewRaspiAdaptor("raspi")
	led := gpio.NewLedDriver(r, "led", "12")

	work := func() {
		current := uint8(0)
		change := uint8(5)

		gobot.Every(30*time.Millisecond, func() {
			led.Brightness(current)
			current += change
			if current == 0 || current == 255 {
				change = -change
			}
		})
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
예제 #2
0
func main() {
	gbot := gobot.NewGobot()
	r := raspi.NewRaspiAdaptor("raspi")
	blinkm := i2c.NewBlinkMDriver(r, "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{r},
		[]gobot.Device{blinkm},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
예제 #3
0
func main() {
	gbot := gobot.NewGobot()

	r := raspi.NewRaspiAdaptor("raspi")
	button := gpio.NewButtonDriver(r, "button", "11")
	led := gpio.NewLedDriver(r, "led", "7")

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

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

	robot := gobot.NewRobot("buttonBot",
		[]gobot.Connection{r},
		[]gobot.Device{button, led},
		work,
	)
	gbot.AddRobot(robot)
	gbot.Start()
}
예제 #4
0
func run(cmd *cobra.Command, args []string) {
	if pin == 0 {
		log.Fatalln("Pin number is required")
	}
	a = raspi.NewRaspiAdaptor("raspi")
	err := a.DigitalWrite(strconv.Itoa(pin), 0)
	if err != nil {
		panic(err)
	}
	if len(flircMap) > 0 {
		go OpenFLIRC(true)
	}
	log.Fatalln(http.ListenAndServe(bindAddr, http.HandlerFunc(ServeHTTP)))
}
예제 #5
0
파일: jenpi.go 프로젝트: laibulle/jenpi
func main() {
	app := cli.NewApp()
	app.Name = "jenpi"
	app.Usage = "Jenpi CLI"
	app.Version = version

	app.Commands = []cli.Command{
		{
			Name:  "start",
			Usage: "start crawling Jenkins",
			Action: func(c *cli.Context) {
				urls = c.Args()

				gbot := gobot.NewGobot()

				r := raspi.NewRaspiAdaptor("raspi")

				ledProcessing = gpio.NewLedDriver(r, "led", "7") // BCM 4
				ledFail = gpio.NewLedDriver(r, "led", "13")      // BCM 17
				ledSuccess = gpio.NewLedDriver(r, "led", "11")   // BCM 27

				gbot.AddRobot(gobot.NewRobot("jenpi",
					[]gobot.Connection{r},
					[]gobot.Device{ledSuccess, ledProcessing, ledFail},
					func() {
						checkError(ledProcessing.On())
						checkError(ledFail.On())
						checkError(ledSuccess.On())

						fmt.Print("Starting in 1 seconds")

						time.Sleep(1 * time.Second)
						gobot.Every(2*time.Second, func() {
							update()
						})
					},
				))

				gbot.Start()
			},
		},
	}

	app.Run(os.Args)
}
예제 #6
0
func main() {
	host := raspi.NewRaspiAdaptor("host")

	dev := i2c.NewLIDARLiteDriver(host, "dev")

	dev.Start()

	go func() {
		if dist, err := dev.Distance(); err != nil {
			log.Error(err)
		} else {
			log.Info(dist)
		}
		time.Sleep(time.Second * 1)
	}()

	select {}
}
예제 #7
0
파일: main.go 프로젝트: TheInsideMan/aambr
func main() {
	if SetViper() {
		gbot := gobot.NewGobot()
		board := raspi.NewRaspiAdaptor("raspi")
		screen := i2c.NewGroveLcdDriver(board, "screen")
		// rgb_tmp := ""
		for {
			work := func() {

				if lcd_message == "" {
					fmt.Println("Loading...")
					screen.Write("Loading...")
				} else if lcd_message != "" {
					s := lcd_message[0:16] + "\n" + lcd_message[16:len(lcd_message)]
					fmt.Println(s)
					screen.Write(s)
				}
				// if rgb_tmp != rgb {
				if rgb == "green" {
					screen.SetRGB(0, 255, 0)
				}
				if rgb == "amber" {
					screen.SetRGB(255, 102, 0)
				}
				if rgb == "red" {
					screen.SetRGB(255, 0, 0)
				}
				// rgb_tmp = rgb
				// }

			}
			robot := gobot.NewRobot("screenBot",
				[]gobot.Connection{board},
				[]gobot.Device{screen},
				work,
			)
			gbot.AddRobot(robot)
			robot.Start()
			Looper()
			time.Sleep(30 * time.Second)
		}
	}
}
예제 #8
0
func main() {
	gbot := gobot.NewGobot()

	r := raspi.NewRaspiAdaptor("raspi")
	led := gpio.NewLedDriver(r, "led", "4")

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

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

	gbot.AddRobot(robot)

	gbot.Start()
}
예제 #9
0
func main() {
	gbot := gobot.NewGobot()
	r := raspi.NewRaspiAdaptor("raspi")
	adaFruit := i2c.NewAdafruitMotorHatDriver(r, "adafruit")

	work := func() {
		gobot.Every(5*time.Second, func() {

			adafruitServoMotorRunner(adaFruit)
		})
	}

	robot := gobot.NewRobot("adaFruitBot",
		[]gobot.Connection{r},
		[]gobot.Device{adaFruit},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
예제 #10
0
파일: main.go 프로젝트: strackr/quasiped
func main() {
	gbot := gobot.NewGobot()
	r := raspi.NewRaspiAdaptor("raspi")
	gbot.AddRobot(quasiped.New(r, r).Robot())
	gbot.Start()
}
예제 #11
0
var furbyBotCmd = &cobra.Command{
	Use:   "furbyBot",
	Short: "Primary command for project - set up gobot Furby interaction",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("furbyBot called")

		gbot := gobot.NewGobot()
		api.NewAPI(gbot).Start()

		r := raspi.NewRaspiAdaptor("raspi")
		audioAdaptor := audio.NewAudioAdaptor("sound")
		jenkinsAdaptor := jenkinsconnect.NewJenkinsconnectAdaptor("jenkins")

		// Set up asynchronous channel - if we get more than 3 sounds being played in a row, something's up
		csoundFiles := make(chan string, 3)
		furby := furby.NewFurbyDriver(r, "furby", "16", csoundFiles)
		audioDriver := audio.NewAudioDriver(audioAdaptor, "sounds", csoundFiles)
		jenkinsDriver := jenkinsconnect.NewJenkinsconnectDriver(jenkinsAdaptor, "jenkins-command")

		screen := i2c.NewGroveLcdDriver(r, "screen")
		work := func() {

			screen.Clear()
			screen.Home()
			furby.On()
예제 #12
0
파일: main.go 프로젝트: ossianpe/7segdocker
func main() {
	raspiAdaptor := raspi.NewRaspiAdaptor("raspi")
	a := gpio.NewLedDriver(raspiAdaptor, "a", "16")
	b := gpio.NewLedDriver(raspiAdaptor, "b", "12")
	c := gpio.NewLedDriver(raspiAdaptor, "c", "16") // changed from 5 to 16
	d := gpio.NewLedDriver(raspiAdaptor, "d", "6")
	e := gpio.NewLedDriver(raspiAdaptor, "e", "0")
	f := gpio.NewLedDriver(raspiAdaptor, "f", "1")
	g := gpio.NewLedDriver(raspiAdaptor, "g", "24")
	dp := gpio.NewLedDriver(raspiAdaptor, "dp", "26")

	work := func() {
		containerCount := runningContainers()
		//        fmt.Println(containerCount)
		switch containerCount {
		case 0:
			a.On()
			b.On()
			c.On()
			d.On()
			e.On()
			f.On()
			g.Off()
			dp.On()
			return
		case 1:
			a.Off()
			b.On()
			c.On()
			d.Off()
			e.Off()
			f.Off()
			g.Off()
			dp.On()
			return
		case '2':
			a.On()
			b.On()
			c.Off()
			d.On()
			e.On()
			f.Off()
			g.On()
			dp.On()
			return
		case '3':
			a.On()
			b.On()
			c.On()
			d.On()
			e.Off()
			f.Off()
			g.On()
			dp.On()
			return
		case '4':
			a.Off()
			b.On()
			c.On()
			d.Off()
			e.Off()
			f.Off()
			g.Off()
			dp.On()
			return
		case '5':
			a.Off()
			b.On()
			c.On()
			d.Off()
			e.Off()
			f.Off()
			g.Off()
			dp.On()
			return
		case '6':
			a.Off()
			b.On()
			c.On()
			d.Off()
			e.Off()
			f.Off()
			g.Off()
			dp.On()
			return
		case '7':
			a.Off()
			b.On()
			c.On()
			d.Off()
			e.Off()
			f.Off()
			g.Off()
			dp.On()
			return
		case '8':
			a.Off()
			b.On()
			c.On()
			d.Off()
			e.Off()
			f.Off()
			g.Off()
			dp.On()
			return
		case '9':
			a.Off()
			b.On()
			c.On()
			d.Off()
			e.Off()
			f.Off()
			g.Off()
			dp.On()
			return
		default:
			a.On()
			b.On()
			c.On()
			d.On()
			e.On()
			f.On()
			g.On()
			dp.On()
		}
	}

	robot := gobot.NewRobot("bot",
		[]gobot.Connection{raspiAdaptor},
		[]gobot.Device{a},
		[]gobot.Device{b},
		[]gobot.Device{c},
		[]gobot.Device{d},
		[]gobot.Device{e},
		[]gobot.Device{f},
		[]gobot.Device{g},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
예제 #13
0
func main() {
	var (
		gbot = gobot.NewGobot()
		r    = raspi.NewRaspiAdaptor("raspi")
		keys = keyboard.NewKeyboardDriver("keyboard")
	)

	conf, err := NewMatrixConfig("config.json")
	if err != nil {
		log.Fatalf("Error loading config: %s", err)
	}
	cube, err := NewMatrixCube(r, conf)
	if err != nil {
		log.Fatalf("Error init cube: %s", err)
	}

	work := func() {
		var x, y, z int

		cube.Clear()
		cube.Toggle(x, y, z)

		ticker := time.NewTicker(10 * time.Millisecond)
		gobot.On(keys.Event("key"), func(data interface{}) {
			<-ticker.C
			key := data.(keyboard.KeyEvent)

			lastX, lastY, lastZ := x, y, z
			if key.Key == keyboard.R {
				cube.Clear()
				x, y, z = 0, 0, 0
				cube.Toggle(x, y, z)
				return
			}
			x, y, z = handle(key.Key, x, y, z)
			if lastX != x || lastY != y || lastZ != z {
				cube.Toggle(lastX, lastY, lastZ)
				cube.Toggle(x, y, z)
			}
			println(x, y, z)
		})

	}

	devices := []gobot.Device{}
	for _, elem := range cube.rows {
		devices = append(devices, elem)
	}
	for _, elem := range cube.cols {
		devices = append(devices, elem)
	}
	devices = append(devices, keys)

	robot := gobot.NewRobot("blinkBot",
		[]gobot.Connection{r},
		devices,
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
예제 #14
0
파일: main.go 프로젝트: tikiatua/buzz-wire
func main() {

	// initialize our base configuration for the system
	initConfiguration()

	// initialize a new gobot
	gbot := gobot.NewGobot()

	// initialize a raspberry pi adaptor
	raspberry := raspi.NewRaspiAdaptor("raspi")

	// start/stop button for a woman
	buttonWoman := gpio.NewButtonDriver(raspberry, "buttonWoman", "11") // GPIO #17 (Low)
	ledWoman := gpio.NewLedDriver(raspberry, "ledWoman", "36")          // GPIO #16 (Low)

	// start/stop buttom for a man
	buttonMan := gpio.NewButtonDriver(raspberry, "buttonMan", "12") // GPIO #18 (Low)
	ledMan := gpio.NewLedDriver(raspberry, "ledMan", "40")          // GPIO #21 (Low)

	// contact with the wire (start- and finish-area)
	contactStart := gpio.NewButtonDriver(raspberry, "contactStart", "13")   // GPIO #27 (Low)
	contactFinish := gpio.NewButtonDriver(raspberry, "contactFinish", "22") // GPIO #25 (Low)

	// user made contact with the wire (use buzzer to indicate audible)
	contactWire := gpio.NewButtonDriver(raspberry, "contactWire", "16") // GPIO #23 (Low)
	buzzer := gpio.NewLedDriver(raspberry, "buzzer", "32")              // GPIO #12 (Low)

	// create a channel for game events
	GameEvents = make(chan string)

	// simulate events with keyboard interaction
	go simulate(GameEvents)

	// define the work to be done by the robot (i.e. react to events)
	work := func() {

		// user pushed the start/stop button
		gobot.On(buttonWoman.Event("push"), func(data interface{}) {
			handleButtonPress(FEMALE)
		})

		gobot.On(buttonMan.Event("push"), func(data interface{}) {
			handleButtonPress(MALE)
		})

		// user made contact with wire
		gobot.On(contactWire.Event("push"), handleWireContact)

		// user is starting the game (must touch the starting area)
		gobot.On(contactStart.Event("push"), handleStartContact)

		// user finished the game (touched finish area)
		gobot.On(contactFinish.Event("push"), handleFinishContact)

		go func() {

			for event := range GameEvents {

				switch event {
				// sound the buzzer
				case "soundBuzzer":
					go func() {
						buzzer.On()
						<-time.After(300 * time.Millisecond)
						buzzer.Off()
					}()

				// enable/disable the led for the woman button
				case "enableLedWoman":
					ledWoman.On()
				case "disableLedWoman":
					ledWoman.Off()

				// enable/disable the lef for the man button
				case "enableLedMan":
					ledMan.On()
				case "disableLedMan":
					ledMan.Off()

				// disable all leds
				case "ledOff":
					ledWoman.Off()
					ledMan.Off()

				// simulated events
				case "button":
					handleButtonPress(FEMALE)
				case "contact":
					handleWireContact(nil)
				case "start":
					handleStartContact(nil)
				case "finish":
					handleFinishContact(nil)

				case "off":
					ledMan.Off()
					ledWoman.Off()
					buzzer.Off()
				}
			}
		}()

	}

	// we need to define a robot to be used with gobot
	var robot *gobot.Robot

	// switch cases depending on the mode
	if Mode == MODE_DEBUG {
		// debug mode is run on the mac without physical connections
		fmt.Println("RUNNING IN DEBUG-MODE")

		robot = gobot.NewRobot("buzzwire",
			[]gobot.Connection{},
			[]gobot.Device{},
			work)
	} else {
		// all other modes are run on the pi with physical connections
		robot = gobot.NewRobot("buzzwire",
			[]gobot.Connection{raspberry},
			[]gobot.Device{buttonWoman, ledWoman, buttonMan, ledMan, contactStart, contactWire, buzzer, contactFinish},
			work)
	}

	// add the robot to the fleet
	gbot.AddRobot(robot)

	// start the webserver in a separate go routine
	go startServer("localhost:8484")

	// open the default webseite
	go openInDefaultBrowser("localhost:8484")

	// start the robot (blocking)
	gbot.Start()
}