IO: Reorganize OOP examples

This commit is contained in:
gohai
2018-06-29 08:23:30 -07:00
parent e19fab1b2b
commit def4a9b4db
13 changed files with 63 additions and 43 deletions

View File

@@ -0,0 +1,25 @@
import processing.io.*;
SPI spi;
// MCP3001 is a Analog-to-Digital converter using SPI
// datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf
// see setup.png in the sketch folder for wiring details
// also see AnalogDigital_SPI_MCP3001 for how to write the
// same sketch in an object-oriented way
void setup() {
//printArray(SPI.list());
spi = new SPI(SPI.list()[0]);
spi.settings(500000, SPI.MSBFIRST, SPI.MODE0);
}
void draw() {
// dummy write, actual values don't matter
byte[] out = { 0, 0 };
byte[] in = spi.transfer(out);
// some input bit shifting according to the datasheet p. 16
int val = ((in[0] & 0x1f) << 5) | ((in[1] & 0xf8) >> 3);
// val is between 0 and 1023
background(map(val, 0, 1023, 0, 255));
}