// PwmWrite writes the 0-254 value to the specified pin
434418
func (d *Adaptor) PwmWrite(pin string, value byte) (err error) {
	if !d.pwm {
		if err = d.littleWire.pwmInit(); err != nil {
			return
		}

		if err = d.littleWire.pwmUpdatePrescaler(1); err != nil {
			return
		}
		d.pwm = true
	}

	return d.littleWire.pwmUpdateCompare(value, value)
}
233956
func (w *Writer) Write(p []byte) (n int, err error) {
	return w.buf.Write(p)
}
174661
func (w *fdSyncWriter) Write(p []byte) (n int, err error) {
	w.Lock()
	n, err = w.fdWriter.Write(p)
	w.Unlock()
	return n, err
}
1127747
func (b *Adaptor) DigitalWrite(pin string, val byte) (err error) {
	if strings.Contains(pin, "usr") {
		fi, e := sysfs.OpenFile(b.usrLed+pin+"/brightness", os.O_WRONLY|os.O_APPEND, 0666)
		defer fi.Close()
		if e != nil {
			return e
		}
		_, err = fi.WriteString(strconv.Itoa(int(val)))
		return err
	}
	sysfsPin, err := b.DigitalPin(pin, sysfs.OUT)
	if err != nil {
		return err
	}
	return sysfsPin.Write(int(val))
}
585771
func (s *serialWriteCloser) Write(data []byte) (int, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	return s.wc.Write(data)
}
613689
func (module *BBPWMModule) EnablePin(pin Pin, enabled bool) error {
	if module.definedPins[pin] == nil {
		return fmt.Errorf("Pin %d is not known as a PWM pin on module %s", pin, module.GetName())
	}

	openPin := module.openPins[pin]
	if enabled {
		// ensure pin is enabled by creating an open pin
		if openPin == nil {
			p, e := module.makeOpenPin(pin)
			if e != nil {
				return e
			}
			module.openPins[pin] = p
			return p.enabled(true)
		}
	} else {
		// disable the pin if enabled
		if openPin != nil {
			return openPin.enabled(false)
		}
	}
	return nil
}
644182
func (rc *rawConn) Write(fn func(fd uintptr) (done bool)) error {
	return rc.opError(opRawWrite, rc.rc.Write(fn))
}
953518
func (m *MCP23017Driver) WriteGPIO(pin uint8, val uint8, portStr string) (err error) {
	selectedPort := m.getPort(portStr)
	// read current value of IODIR register
	iodir, err := m.read(selectedPort.IODIR)
	if err != nil {
		return err
	}
	// set pin as output by clearing bit
	iodirVal := clearBit(iodir, uint8(pin))
	// write IODIR register bit
	err = m.write(selectedPort.IODIR, uint8(pin), uint8(iodirVal))
	if err != nil {
		return err
	}
	// read current value of OLAT register
	olat, err := m.read(selectedPort.OLAT)
	if err != nil {
		return err
	}
	// set or clear olat value, 0 is no output, 1 is an output
	var olatVal uint8
	if val == 0 {
		olatVal = clearBit(olat, uint8(pin))
	} else {
		olatVal = setBit(olat, uint8(pin))
	}
	// write OLAT register bit
	err = m.write(selectedPort.OLAT, uint8(pin), uint8(olatVal))
	if err != nil {
		return err
	}
	return nil
}
1303079
func (w *Writer) Write(p []byte) (int, error) {
	w.Lock()
	defer w.Unlock()
	return w.w.Write(p)
}
1325390
func (f *Adaptor) ServoWrite(pin string, angle byte) (err error) {
	p, err := strconv.Atoi(pin)
	if err != nil {
		return err
	}

	if f.Board.Pins()[p].Mode != client.Servo {
		err = f.Board.SetPinMode(p, client.Servo)
		if err != nil {
			return err
		}
	}
	err = f.Board.AnalogWrite(p, int(angle))
	return
}
1348822
func (w *QWriter) Write(p []byte) (int, error) {
	if w.err != nil {
		return 0, w.err
	}
	n, err := w.w.Write(p)
	if err != nil {
		w.err = err
	}
	return n, err
}
350746
func (w *Writer) Write(i interface{}) {
	var s string
	switch i.(type) {
	case string:
		s = i.(string)
	case []byte:
		for _, b := range i.([]byte) {
			s += fmt.Sprintf("%.8b", b)
		}
	case bool:
		if i.(bool) {
			s = "1"
		} else {
			s = "0"
		}
	case uint8:
		s = fmt.Sprintf("%.8b", i)
	case uint16:
		s = fmt.Sprintf("%.16b", i)
	case uint32:
		s = fmt.Sprintf("%.32b", i)
	case uint64:
		s = fmt.Sprintf("%.64b", i)
	default:
		return
	}

	for _, c := range s {
		w.remainingBits = w.remainingBits + string(c)
		if len(w.remainingBits) == 8 {
			var nb byte
			var power float64
			for idx := len(w.remainingBits) - 1; idx >= 0; idx-- {
				if w.remainingBits[idx] == '1' {
					nb = nb + uint8(math.Pow(2, power))
				}
				power++
			}
			w.b = append(w.b, nb)
			w.remainingBits = ""
		}
	}
}
92865
func (wpr *Wrapper) Write(p []byte) (n int, err error) {
	return wpr.WriteAt(p, wpr.L)
}
503042
func WritePin(pin Pin, state State) {
	p := uint8(pin)

	// Set register, 7 / 8 depending on bank
	// Clear register, 10 / 11 depending on bank
	setReg := p/32 + 7
	clearReg := p/32 + 10

	memlock.Lock()

	if state == Low {
		gpioMem[clearReg] = 1 << (p & 31)
	} else {
		gpioMem[setReg] = 1 << (p & 31)
	}
	memlock.Unlock() // not deferring saves ~600ns
}
1248380
func (w *minifyWriter) Write(b []byte) (int, error) {
	return w.pw.Write(b)
}
794326
func (w *stdWriter) Write(p []byte) (n int, err error) {
	if w == nil || w.Writer == nil {
		return 0, errors.New("Writer not instantiated")
	}
	if p == nil {
		return 0, nil
	}

	header := [stdWriterPrefixLen]byte{stdWriterFdIndex: w.prefix}
	binary.BigEndian.PutUint32(header[stdWriterSizeIndex:], uint32(len(p)))
	buf := bufPool.Get().(*bytes.Buffer)
	buf.Write(header[:])
	buf.Write(p)

	n, err = w.Writer.Write(buf.Bytes())
	n -= stdWriterPrefixLen
	if n < 0 {
		n = 0
	}

	buf.Reset()
	bufPool.Put(buf)
	return
}
324675
func (rwops *RWops) Write(buf []byte) (n int, err error) {
	return rwops.Write2(buf, 1, uint(len(buf)))
}