func (p *GoPiGo) DirectMotor1(direction, speed byte) error {
  p.mu.Lock()
  defer p.mu.Unlock()
  return p.sendCmd(cmdValues(m1Cmd, direction, speed))
}
DirectMotor1 sets the direction and speed of motor1.
package gopigo
import (
  "github.com/kidoman/embd"
  "fmt"
  _ "github.com/kidoman/embd/host/all"
  "math"
  "sync"
  "time"
)
const (
  address = 0x08
)
const (
  wheelRadius       = 3.25
  wheelDistance     = 2 * math.Pi * wheelRadius
  pulsesPerRotation = 18
)
const (
  fwdCmd            = 119
  motorFwdCmd       = 105
  motorBwdCmd       = 107
  bwdCmd            = 115
  stopCmd           = 120
  leftCmd           = 97   
  leftRotCmd        = 98   
  rightCmd          = 100  
  rightRotCmd       = 110  
  ispdCmd           = 116  
  dspdCmd           = 103  
  m1Cmd             = 111  
  m2Cmd             = 112  
  readMotorSpeedCmd = 114  
  voltCmd           = 118  
  usCmd             = 117  
  ledCmd            = 108  
  servoCmd          = 101  
  encTgtCmd         = 50   
  fwVerCmd          = 20   
  enEncCmd          = 51   
  disEncCmd         = 52   
  readEncStatusCmd  = 53   
  enServoCmd        = 61   
  disServoCmd       = 60   
  setLeftSpeedCmd   = 70   
  setRightSpeedCmd  = 71   
  enComTimeoutCmd   = 80   
  disComTimeoutCmd  = 81   
  timeoutStatusCmd  = 82   
  encReadCmd        = 53   
  trimTestCmd       = 30   
  trimWriteCmd      = 31   
  trimReadCmd       = 32
  digitalWriteCmd = 12  
  digitalReadCmd  = 13  
  analogReadCmd   = 14  
  analogWriteCmd  = 15  
  pinModeCmd      = 16  
  irReadCmd    = 21
  irRecvPinCmd = 22
  cpuSpeedCmd  = 25
)
type GoPiGo struct {
  mu  sync.Mutex
  bus embd.I2CBus
}
func New(bus embd.I2CBus) *GoPiGo {
  return &GoPiGo{
    bus: bus,
  }
}
func cmdValues(mainCmd byte, cmdParams ...byte) []byte {
  values := make([]byte, 4)
  values[0] = mainCmd
  for i, v := range cmdParams {
    values[i+1] = v
  }
  return values
}
func (p *GoPiGo) sendCmd(cmdValues []byte) error {
  err := p.bus.WriteToReg(address, 1, cmdValues)
  time.Sleep(5 * time.Millisecond)
  return err
}
func (p *GoPiGo) writeByte(b byte) error {
  return p.bus.WriteByte(address, b)
}
func (p *GoPiGo) readByte() (byte, error) {
  return p.bus.ReadByte(address)
}