pls can you edit your posts and format the code?
use the
</> code tag
ok i show you my version for
- processing IDE 3.5.3 / JAVA mode
- arduino IDE 1.8.9 nightly
running on Raspberry Pi 3B+ / Raspbian OS
Arduino:
#include <CapacitiveSensor.h>
// http://playground.arduino.cc/Main/CapacitiveSensor
CapacitiveSensor cs_4_2 = CapacitiveSensor(4, 2); // (byte sendPin, byte receivePin)
long val_cs_4_2;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // for LEONARDO needed
}
Serial.println("0,0,<Arduino is ready>"); // as you expect CSV line and use first value as number
// cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
}
void loop() {
val_cs_4_2 = cs_4_2.capacitiveSensor(30);
Serial.print(val_cs_4_2); // -2 is timeout
Serial.println(",0,");
delay(10);
}
Processing:
// https://discourse.processing.org/t/help-with-code-please/8800 // kll cleaned version
import processing.serial.*; //import the Serial library so can read from arudino input via serial communication
Serial port; // The serial port, this is a new instance of the Serial class (an Object)
String inserial; // declare a new IN string called ‘serial’
int lf = 10; // the number 10 is ASCII for linefeed (end of serial.println),
String[] SensorInput = {"0", "0"}; // splitted CSV line to string array
PImage zom;
int val_cs_4_2;
void setup() {
size (500, 500); //1000,1000
printArray(Serial.list());
port = new Serial(this, Serial.list()[6], 9600);
port.clear();
zom = loadImage("zom1.jpg");
}
void draw() {
background(200);
image(zom, 0, 0, 500, 500);
if (val_cs_4_2 >= 1000) background(0); // reset screen
if (val_cs_4_2 == -2) text("sensor problem", 10, 20); // warning
}
void serialEvent(Serial p) {
inserial = p.readStringUntil(lf);
if (inserial != null) { // if the string is not empty, do this
SensorInput = split(inserial, ','); // capsense Input form Arduino, each value is seperated and split depending on the ‘,’ //and then saved in seperate cells of the array so we can access each
printArray(SensorInput); // can help to print these to console at this point to check it’s working
val_cs_4_2 = int(SensorInput[0]); // the first is our sensor
}
}
but i get the “-2” timeout as no hardware “sensor” connected.