Beispiel #1
0
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	screen := i2c.NewGroveLcdDriver(board, "screen")

	work := func() {
		screen.Write("hello")

		screen.SetRGB(255, 0, 0)

		gobot.After(5*time.Second, func() {
			screen.Clear()
			screen.Home()
			screen.SetRGB(0, 255, 0)
			screen.Write("goodbye")
		})

		screen.Home()
		<-time.After(1 * time.Second)
		screen.SetRGB(0, 0, 255)
	}

	robot := gobot.NewRobot("screenBot",
		[]gobot.Connection{board},
		[]gobot.Device{screen},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Beispiel #2
0
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)
		}
	}
}
Beispiel #3
0
/*
This function is used if only the rotary port is in play.
func mapValueToColor(i int) (int, int, int) {
	// Masking to account for very sensitive rotary
	red := ((i & (1 << 1)) << 2) | ((i & (1 << 4)) << 0) | ((i & (1 << 7)) >> 2)
	green := ((i & (1 << 2)) << 1) | ((i & (1 << 5)) >> 1) | ((i & (1 << 8)) >> 3)
	blue := ((i & (1 << 3)) << 0) | ((i & (1 << 6)) >> 2) | ((i & (1 << 9)) >> 4)

	return red, green, blue
}
*/
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	screen := i2c.NewGroveLcdDriver(board, "screen")
	sensorRotary := gpio.NewGroveRotaryDriver(board, "sensor", "0")
	sensorLight := gpio.NewGroveLightSensorDriver(board, "light", "1")
	sensorTemp := gpio.NewGroveTemperatureSensorDriver(board, "temp", "2")

	work := func() {
		var r, g, b int

		gobot.On(sensorRotary.Event("data"), func(data interface{}) {
			r = data.(int) >> 2
		})

		gobot.On(sensorLight.Event("data"), func(data interface{}) {
			fmt.Printf("%d\n", data)
			g = data.(int) * 255 / 790
		})

		gobot.Every(time.Millisecond*500, func() {
			b = int(gobot.ToScale(gobot.FromScale(sensorTemp.Temperature(), 25, 35), 0, 255))
			screen.Clear()
			screen.Home()
			screen.SetRGB(r, g, b)
			screen.Write(fmt.Sprintf("#%02X%02X%02X", r, g, b))
		})

	}

	robot := gobot.NewRobot("screenBot",
		[]gobot.Connection{board},
		[]gobot.Device{screen, sensorRotary, sensorLight, sensorTemp},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Beispiel #4
0
func main() {
	gbot := gobot.NewGobot()

	board := joule.NewJouleAdaptor("joule")
	screen := i2c.NewGroveLcdDriver(board, "screen")

	work := func() {
		screen.Write("hello")

		screen.SetRGB(255, 0, 0)

		gobot.After(5*time.Second, func() {
			screen.Clear()
			screen.Home()
			screen.SetRGB(0, 255, 0)
			// set a custom character in the first position
			screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"])
			// add the custom character at the end of the string
			screen.Write("goodbye\nhave a nice day " + string(byte(0)))
			gobot.Every(500*time.Millisecond, func() {
				screen.Scroll(false)
			})
		})

		screen.Home()
		<-time.After(1 * time.Second)
		screen.SetRGB(0, 0, 255)
	}

	robot := gobot.NewRobot("screenBot",
		[]gobot.Connection{board},
		[]gobot.Device{screen},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Beispiel #5
0
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	lidar := NewLIDARLiteDriver(board, "lidar")
	screen := i2c.NewGroveLcdDriver(board, "screen")

	work := func() {
		gobot.Every(500*time.Millisecond, func() {
			distance, err := lidar.Distance()
			if err != nil {
				fmt.Println("error: ", err)
			}
			dist := float32(distance) / 2.54
			fmt.Println("Distance (in)", dist)
			screen.Clear()
			screen.Home()
			screen.Write(fmt.Sprintf("%f\"", dist))
		})
	}

	robot := gobot.NewRobot("screenBot",
		[]gobot.Connection{board},
		[]gobot.Device{lidar, screen},
		work,
	)

	gbot.AddRobot(robot)

	/*
		if errs := screen.Start(); len(errs) > 0 {
			for _, err := range errs {
				fmt.Println(err)
			}
		}
	*/

	gbot.Start()
}
Beispiel #6
0
		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()

			screen.SetRGB(255, 255, 255)

			if err := screen.Write("Furby say hi!!"); err != nil {
				log.Fatal(err)
			}

			gobot.On(jenkinsDriver.Event("jobResult"), func(data interface{}) {
				jobResult, ok := data.(jenkinsconnect.JobOutcome)
				if ok {
Beispiel #7
0
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()
}
func main() {
	//AWS MQTT Broker SSL Configuration
	tlsconfig := NewTLSConfig()
	fmt.Println("TLSConfig initiation Completed")
	opts := MQTT.NewClientOptions()
	opts.AddBroker("ssl://AEV5KR4BW3J9L.iot.us-east-1.amazonaws.com:8883")
	opts.SetClientID("iot-sample").SetTLSConfig(tlsconfig)
	fmt.Println("Invoking Publish Handler method ")
	opts.SetDefaultPublishHandler(f)

	// Start the connection
	c := MQTT.NewClient(opts)
	if token := c.Connect(); token.Wait() && token.Error() != nil {
		panic(token.Error())
	}
	// _ = "breakpoint"
	fmt.Println("MQTT Connection established")

	c.Subscribe("/go-mqtt/sample", 0, nil)

	// Gobot initiation
	gbot := gobot.NewGobot()
	board := edison.NewEdisonAdaptor("board")
	sensort := gpio.NewGroveTemperatureSensorDriver(board, "tempsensor", "0")
	screen := i2c.NewGroveLcdDriver(board, "screen")

	// Struct to hold sensor data
	type Sensord struct {
		Temp float64 `json:"temp"`
	}

	work := func() {
		screen.Write("Thermostat is On !!")
		screen.SetRGB(255, 0, 0)

		gobot.Every(5*time.Second, func() {
			fmt.Println("current temp (c): ", math.Floor(sensort.Temperature()))

			// LCD showing the temperature
			screen.Clear()
			screen.Home()
			screen.SetRGB(0, 255, 0)
			//screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"])

			//Update the struct with sensor data, Jsonify & Convert to string
			res1Z := Sensord{
				Temp: math.Floor(sensort.Temperature()),
			}

			jData, err := json.Marshal(res1Z)
			if err != nil {
				fmt.Println(err)
				return
			}

			s := string(jData)

			// Writes to the LCD Screen & publish to AWS MQTT Broker.

			screen.Write(s)
			gobot.Every(2*time.Second, func() {
				screen.Scroll(false)
			})

			fmt.Println("The json data to be published in IOT topic is", s)
			c.Publish("/go-mqtt/sample", 0, false, s)
			//c.Disconnect(250)

			//screen.Home()
			//<-time.After(2 * time.Second)
			//screen.SetRGB(0, 0, 255)
		})
	}

	robot := gobot.NewRobot("sensorBot",
		[]gobot.Connection{board},
		[]gobot.Device{sensort, screen},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()

}