3 sensors on individual codes, processing interactive visuals

Hello! We're doing a project where we have to use 3 sensors (one of them a push button) to create interactive visuals on processing. We've made three individual codes, however, we cannot make them run at once. Can anyone help?
1st is the arduino code 2nd is the processing code

FIRST CODE:
int val;
int val1;
int potPin1 = 0;
int switchPin = 2; // Switch connected to pin 2

void setup() {
pinMode(switchPin, INPUT); // Set pin 0 as an input
Serial.begin(9600);
}

void loop() {
potentiometer();
potentiometer1();
switch1();
}

void potentiometer() { // potentiometer
val = (analogRead(A0) / 4);
Serial.write(val);
delay(100);
}

void potentiometer1() { // potentiometer
int val1 = map(analogRead(potPin1), 0, 1023, 0, 255);
Serial.println(val);
delay(50);
}

void switch1() { // knap
if (digitalRead(switchPin) == HIGH) { // If switch is ON,
Serial.write(1); // send 1 to Processing
} else { // If the switch is not ON,
Serial.write(0); // send 0 to Processing
}
delay(50); // Wait 100 milliseconds
}

SECOND CODE:

import processing.serial.*;

Serial port; // Create object from Serial class
int val; // Data received from the serial port
float m;
float brightness = 0;
int value;
int padding = 100;

void setup()
{
size(1440, 900);
println("Available serial ports:");
println(Serial.list());
port = new Serial(this, "COM3", 9600);
port.bufferUntil('\n');

smooth();
strokeWeight(3);
stroke(100);
}

void draw()
{
del1();
del2();
del3();
}

void del1() // når der trykkes på knappen bliver cirklen større
{
if ( port.available() > 0) { // If data is available,
val = port.read(); // read it and store it in val
}
// background(255); // Set background to white
if (val == 0) { // If the serial value is 0,
ellipse(m, height/2, 150, 150);
} else { // If the serial value is not 0,
ellipse(m, height/2, 250, 250);
}
}

void del2() // potentiometer kører med cirklen på linjen
{
// background(#FFFFF0);
if (port.available() > 0) {
value = port.read();
println(value);
m = map(value, 255, 0, padding, width-padding);
}
line(padding, height/2, width-padding, height/2);
noStroke();
fill(#FFDE14);
ellipse(m, height/2, 150, 150);
stroke(100);
}

void del3() // potentiometer skifter baggrundsfarve
{
background(255, 125, brightness);
fill(255, 0, 0);
ellipse(50, 200, 160, 160);
}
void serialEvent (Serial port) {

{
brightness = float(port.readStringUntil('\n'));
}
}

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.