// AnalogWrite writes value to pin.
760008
func (b *Client) AnalogWrite(pin int, value int) error {
	b.pins[pin].Value = value
	return b.write([]byte{AnalogMessage | byte(pin), byte(value & 0x7F), byte((value >> 7) & 0x7F)})
}
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
}
609814
func (nw *NullIO) Write(v []byte) (int, error) {
	return len(v), nil
}
910228
func (module *BBAnalogModule) AnalogRead(pin Pin) (int, error) {
	var e error

	// Get it if it's already open
	openPin := module.openPins[pin]
	if openPin == nil {
		// If it's not open yet, open on demand
		openPin, e = module.makeOpenAnalogPin(pin)
		// return 0, errors.New("Pin is being read for analog value but has not been opened. Have you called PinMode?")
		if e != nil {
			return 0, e
		}
	}
	return openPin.analogGetValue()
}
97549
func (d *Adaptor) ServoWrite(pin string, angle uint8) (err error) {
	if !d.servo {
		if err = d.littleWire.servoInit(); err != nil {
			return
		}
		d.servo = true
	}
	return d.littleWire.servoUpdateLocation(angle, angle)
}
73226
func (p *PCA9685Driver) PwmWrite(pin string, val byte) (err error) {
	i, err := strconv.Atoi(pin)
	if err != nil {
		return
	}
	v := gobot.ToScale(gobot.FromScale(float64(val), 0, 255), 0, 4096)
	return p.SetPWM(i, 0, uint16(v))
}
929079
func (c Conn) CloseWrite() error {
	if cw, ok := c.Wire.(interface {
		CloseWrite() error
	}); ok {
		return cw.CloseWrite()
	}
	return errors.New("pinned: underlying connection does not support CloseWrite")
}
941116
func (w *influxDBWriter) Write(bp influxdb.BatchPoints) error {
	c, err := w.initWriteClient()
	if err != nil {
		return err
	}

	defer c.Close()

	if writeErr := c.Write(bp); writeErr != nil {
		ctx := log.With(context.Background(), log.Str(log.MetricsProviderName, "influxdb"))
		log.FromContext(ctx).Errorf("Error while writing to InfluxDB: %s", writeErr.Error())

		if handleErr := w.handleWriteError(ctx, c, writeErr); handleErr != nil {
			return handleErr
		}
		// Retry write after successful handling of writeErr
		return c.Write(bp)
	}
	return nil
}
228962
func (d *MCP3204Driver) AnalogRead(pin string) (value int, err error) {
	channel, _ := strconv.Atoi(pin)
	value, err = d.Read(channel)
	if err != nil {
		value = int(gobot.ToScale(gobot.FromScale(float64(value), 0, 4095), 0, 1023))
	}

	return
}
812490
func binaryWrite(w io.Writer, order binary.ByteOrder, data interface{}) (n int64, err error) {
	buf := bytes.Buffer{}
	if err = binary.Write(&buf, order, data); err != nil {
		return 0, err
	}

	written, err := w.Write(buf.Bytes())
	return int64(written), err
}
282680
func (p *port) Write(b []byte) (n int, err error) {
	n, err = syscall.Write(p.fd, b)
	return
}
423024
func (w *AtomicWriter) Write(bs []byte) (int, error) {
	if w.err != nil {
		return 0, w.err
	}
	n, err := w.next.Write(bs)
	if err != nil {
		w.err = err
		w.next.Close()
	}
	return n, err
}
1142867
func (l *MuxWriter) Write(b []byte) (int, error) {
	l.Lock()
	defer l.Unlock()
	return l.fd.Write(b)
}
814156
func (d *GrovePiDriver) writeDigital(pin byte, val byte) error {
	buf := []byte{CommandWriteDigital, pin, val, 0}
	_, err := d.connection.Write(buf)

	time.Sleep(2 * time.Millisecond)

	_, err = d.connection.ReadByte()

	return err
}
510138
func (c *Client) Write(ctx context.Context, points []chronograf.Point) error {
	if !c.opened {
		return chronograf.ErrUninitialized
	}
	return c.nextDataNode().Write(ctx, points)
}
621372
func (e *encoder) Write(t int64) {
	e.ts = append(e.ts, uint64(t))
}
503022
func AnalogRead(key interface{}) (int, error) {
	pin, err := NewAnalogPin(key)
	if err != nil {
		return 0, err
	}

	return pin.Read()
}