Capacitive Sensor Within Processing

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

This discussion has been closed.