示例#1
0
文件: leds.go 项目: ljcrapo/GoEV3
// Turns off the given LED with the specified color.
func TurnOff(color Color, position Position) {
	if color == Amber {
		utilities.WriteIntValue(findFilename(Green, position), "brightness", 0)
		utilities.WriteIntValue(findFilename(Red, position), "brightness", 0)
	} else {
		utilities.WriteIntValue(findFilename(color, position), "brightness", 0)
	}
}
示例#2
0
文件: leds.go 项目: tthk/GoEV3
// Set Brightness (0 - 255)
func SetBrightness(color Color, position Position, brightness uint8) {
	if color == Amber {
		utilities.WriteIntValue(findFilename(Green, position), "brightness", int64(brightness))
		utilities.WriteIntValue(findFilename(Red, position), "brightness", int64(brightness))
	} else {
		utilities.WriteIntValue(findFilename(color, position), "brightness", int64(brightness))
	}

}
示例#3
0
文件: motors.go 项目: ljcrapo/GoEV3
func setSpeed(folder string, speed int16) {
	regulationMode := utilities.ReadStringValue(folder, regulationModeFD)

	switch regulationMode {
	case "on":
		utilities.WriteIntValue(folder, speedSetterFD, int64(speed))
	case "off":
		if speed > 100 || speed < -100 {
			log.Fatal("The speed must be in range [-100, 100]")
		}
		utilities.WriteIntValue(folder, powerSetterFD, int64(speed))
	}
}
示例#4
0
文件: motors.go 项目: tthk/GoEV3
// Runs the motor at the given port.
// The meaning of `speed` parameter depends on whether the regulation mode is turned on or off.
//
// When the regulation mode is off (by default) `speed` ranges from -100 to 100 and
// it's absolute value indicates the percent of motor's power usage. It can be roughly interpreted as
// a motor speed, but deepending on the environment, the actual speed of the motor
// may be lower than the target speed.
//
// When the regulation mode is on (has to be enabled by EnableRegulationMode function) the motor
// driver attempts to keep the motor speed at the `speed` value you've specified
// which ranges from about -1000 to 1000. The actual range depends on the type of the motor - see ev3dev docs.
//
// Negative values indicate reverse motion regardless of the regulation mode.
func Run(port OutPort, speed int16) {
	folder := findFolder(port)
	regulationMode := utilities.ReadStringValue(folder, regulationModeFD)

	switch regulationMode {
	case "on":
		utilities.WriteIntValue(folder, speedSetterFD, int64(speed))
		utilities.WriteStringValue(folder, runFD, "run-forever")
	case "off":
		if speed > 100 || speed < -100 {
			log.Fatal("The speed must be in range [-100, 100]")
		}
		utilities.WriteIntValue(folder, powerSetterFD, int64(speed))
		utilities.WriteStringValue(folder, runFD, "run-forever")
	}
}
示例#5
0
文件: motors.go 项目: ljcrapo/GoEV3
func setAngle(folder string, angle int16) {
	utilities.WriteIntValue(folder, desiredPositionFD, int64(angle))
}
示例#6
0
文件: motors.go 项目: ljcrapo/GoEV3
// InitializePosition sets the position of the motor at the given port.
func InitializePosition(port OutPort, value int32) {
	utilities.WriteIntValue(findFolder(port), positionFD, int64(value))
}
示例#7
0
文件: motors.go 项目: ljcrapo/GoEV3
func setTime(folder string, seconds int32) {
	utilities.WriteIntValue(folder, timeFD, int64(seconds))
}