Reference+
Name
transfer()
Class
SPI
Description
Transfers data over the SPI bus
With SPI, data is simultaneously being exchanged between the master device
and the slave device. For every byte that is being sent out, there's also one
byte being read in.
Examples
import processing.io.*; SPI adc; void setup() { //printArray(SPI.list()); adc = new SPI(SPI.list()[0]); adc.settings(500000, SPI.MSBFIRST, SPI.MODE0); } void draw() { // read in values over SPI from an analog-to-digital // converter // dummy write, actual values don't matter byte[] out = { 0, 0 }; byte[] in = adc.transfer(out); // some input bit shifting according to the datasheet int val = ((in[0] & 0x1f) << 5) | ((in[1] & 0xf8) >> 3); // val is between 0 and 1023 println(val); }
Syntax
.transfer(out)
Parameters
out
(byte[], String, int, byte)
bytes to sendout
(String, byte, int)
string to sendout
(int, byte)
single byte to send, e.g. numeric literal (0 to 255, or -128 to 127)out
(byte, int)
single byte to send
Return
byte[]
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.