Slider - adjust sound cp5

How do I adjust the value of a slider in controlP5 in Processing?
For example. I’ve made a slider using the cp5 library, and I would like to change the volume from low to high whenever I move the slider up and down. So if the slider is moved up the sound gets louder and louder and vice versa. I hope this makes sense. Thank you.

import controlP5.*;
ControlP5 controlP5;
import processing.sound.*;  
foundFile file;  
int from = color(255,0,0);
int to = color(0,120,200);

void setup() {
 file = new SoundFile(this, "Sweetdreams.mp3");    //loading my sound file;                                                     

 controlP5 = new ControlP5(this);
 //change the default font to Verdana;
 PFont p = createFont("Verdana",20); //skrifttype og størrelse
 ControlFont font = new ControlFont(p);
 //change the original colors
 controlP5.setColorForeground(lerpColor(from, to, 0.5)); 
 controlP5.setColorActive(lerpColor(from, to, 0.5)); 

void draw() { 
 background(0); // background black 

please post your code into the

</> code button in editor menu

is that a question about

  • sound lib volume


  • cp5 slider ( change event )

for both i see no code?

possibly start from each lib closely from a RUNNING example

import processing.sound.*;
SoundFile soundfile;

void setup() {
  size(640, 360);
  soundfile = new SoundFile(this, "vibraphon.aiff");
  println("use: mouseY for volume");

void draw() {
  float amplitude = map(mouseY, 0, width, 0.2, 1.0);
import controlP5.*;
ControlP5 cp5;

void setup() {
  cp5 = new ControlP5(this);

void draw() {

void slider(float val) {
  println("a slider event: "+val);

now try to combine them.


i asked you to format your code,
not to delete it.

vandalizing your question AFTER you got answers
might make the whole thread worthless for following readers,

this is not a private helpline ( from a company selling software for 600 TALER )

in a public forum the questions and the answers should express the will of a community
to help each other and also to learn from each other to make a better codebase, free for all.

I’m fairly new to programmation,
I tried to recreate this code for a class, I download the P5 library as well as the Sound library. When I want to run the program, the error box indicates the “foundFile” doesn’t exists. Am I missing something to download here, or is it directly in the code?