We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I'm novice at using Processing.
In my code I want to change the background to white when the capacitive sensor is held down, and then back to black when the sensor is released.
I have attempted at writing this code in both capacitive sensor code in Arduino, however when I run my code in Processing nothing is shown or changes.
Any help would be greatly appreciated.
MY ARDUINO CODE IS BELLOW
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2);
void setup(){
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
Serial.begin(9600);
}
void loop(){
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
Serial.println(total1);
Serial.print(",");
delay(10);
}
MY PROCESSING CODE IS BELLOW
import processing.serial.*;
int touch1Value = 0;
int threshold = 30;
Serial myPort;
void setup(){
size (500,500);
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
}
void draw(){
background (0);
println("touch1Value:"+touch1Value);
if (touch1Value == 1){
background (255,255,255);
}
}
void serialEvent(Serial myPort){
String inString = myPort.readStringUntil('\n');
if (inString != null){
inString = trim (inString);
float[] touches = float (split(inString, ","));
if (touches.length >=1){
touch1Value = touches[0] >= threshold ? 1: 0;
}
}
}
Answers
Try removing line 17 in your ino code and see if that fixes it.
Kf
Success, can't believe I missed that!
I am also trying to make a capacitive sensor display a random image each time my sensor is held down.
I have added all the images I want to be included in this randomisation, however when my sensor is held down it skips constantly through all of my images when I infect just want one to be displayed at a time.
The key thing I want to keep is the fact that the sensor has to be held down and not pressed.
Here is my Processing code altered:
Answered here:
https://forum.processing.org/two/discussion/21213/help-please-utilising-capacitive-sensor-images
Closed this.