func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") board_led := gpio.NewLedDriver(e, "led", "13") red_led := gpio.NewLedDriver(e, "led", "3") green_led := gpio.NewLedDriver(e, "led", "2") buzzer := gpio.NewBuzzerDriver(e, "buzzer", "4") // Blink the Board LED board_blink_work := func() { gobot.Every(10*time.Second, func() { board_led.Toggle() }) } // Ring the buzzer buzzer_work := func() { gobot.Every(4*time.Second, func() { buzzer.Tone(gpio.G5, gpio.Eighth) }) } board_blink_bot := gobot.NewRobot("Board LED", []gobot.Connection{e}, []gobot.Device{board_led}, board_blink_work, ) buzz_bot := gobot.NewRobot("buzzBot", []gobot.Connection{e}, []gobot.Device{buzzer}, buzzer_work, ) red_blink_bot := gobot.NewRobot("Red LED", []gobot.Connection{e}, []gobot.Device{red_led}, ) green_blink_bot := gobot.NewRobot("Green LED", []gobot.Connection{e}, []gobot.Device{green_led}, ) gbot.AddRobot(board_blink_bot) gbot.AddRobot(green_blink_bot) gbot.AddRobot(red_blink_bot) gbot.AddRobot(buzz_bot) a := api.NewAPI(gbot) a.Debug() a.Start() gbot.Start() }
func main() { gbot := gobot.NewGobot() board := edison.NewEdisonAdaptor("edison") buzzer := gpio.NewBuzzerDriver(board, "buzzer", "3") work := func() { type note struct { tone float64 duration float64 } song := []note{ {gpio.C4, gpio.Quarter}, {gpio.C4, gpio.Quarter}, {gpio.G4, gpio.Quarter}, {gpio.G4, gpio.Quarter}, {gpio.A4, gpio.Quarter}, {gpio.A4, gpio.Quarter}, {gpio.G4, gpio.Half}, {gpio.F4, gpio.Quarter}, {gpio.F4, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.D4, gpio.Quarter}, {gpio.D4, gpio.Quarter}, {gpio.C4, gpio.Half}, } for _, val := range song { buzzer.Tone(val.tone, val.duration) <-time.After(10 * time.Millisecond) } } robot := gobot.NewRobot("bot", []gobot.Connection{board}, []gobot.Device{buzzer}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0") buzzer := gpio.NewBuzzerDriver(firmataAdaptor, "buzzer", "3") work := func() { type note struct { tone float64 duration float64 } song := []note{ {gpio.C4, gpio.Quarter}, {gpio.C4, gpio.Quarter}, {gpio.G4, gpio.Quarter}, {gpio.G4, gpio.Quarter}, {gpio.A4, gpio.Quarter}, {gpio.A4, gpio.Quarter}, {gpio.G4, gpio.Half}, {gpio.F4, gpio.Quarter}, {gpio.F4, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.D4, gpio.Quarter}, {gpio.D4, gpio.Quarter}, {gpio.C4, gpio.Half}, } for _, val := range song { buzzer.Tone(val.tone, val.duration) <-time.After(10 * time.Millisecond) } } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{buzzer}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() board := edison.NewEdisonAdaptor("board") screen := i2c.NewGroveLcdDriver(board, "screen") buzzer := gpio.NewBuzzerDriver(board, "buzzer", "3") sensor := gpio.NewGroveTemperatureSensorDriver(board, "sensor", "1") //the hot song is work := func() { //initial calibration in fahrenheit min = 60.0 max = 80.0 diff = max - min type note struct { tone float64 duration float64 } //the cold song is "do you want to build a snowman" coldSong := []note{ {gpio.C3, gpio.Quarter}, {gpio.C3, gpio.Quarter}, {gpio.C3, gpio.Quarter}, {gpio.G3, gpio.Quarter}, {gpio.C3, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.D4, gpio.Half}, {gpio.E4, gpio.Half}, } //the hot song is "let's get it started in here" hotSong := []note{ {gpio.E4, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.E4, gpio.Quarter}, {gpio.C3, gpio.Quarter}, {gpio.A3, gpio.Quarter}, {gpio.C3, gpio.Quarter}, } gobot.Every(time.Second, func() { screen.Clear() time.Sleep(5 * time.Millisecond) screen.Home() time.Sleep(5 * time.Millisecond) //get temps celsius := sensor.Temperature() fahrenheit := (celsius * 1.8) + 32 //recalibrate min = math.Min(fahrenheit, min) max = math.Max(fahrenheit, max) diff = max - min //check if fahrenheit > 80 { for _, val := range hotSong { buzzer.Tone(val.tone, val.duration) <-time.After(10 * time.Millisecond) } screen.Write(fmt.Sprintf("TOO HOT (%.2gF)", fahrenheit)) } else if fahrenheit < 60 { for _, val := range coldSong { buzzer.Tone(val.tone, val.duration) <-time.After(10 * time.Millisecond) } screen.Write(fmt.Sprintf("TOO COLD (%.2gF)", fahrenheit)) } else { screen.Write(fmt.Sprintf("%.2gF, %.2gC", fahrenheit, celsius)) } time.Sleep(5 * time.Millisecond) fmt.Printf("%.2gF, %.2gC\n", fahrenheit, celsius) //set to params screen.SetRGB(getRed(fahrenheit), 0, getBlue(fahrenheit)) }) } robot := gobot.NewRobot("sensorBot", []gobot.Connection{board}, []gobot.Device{screen, buzzer, sensor}, work, ) gbot.AddRobot(robot) gbot.Start() }