Controlp5 (cp5): Sync color displayed by colorwheel when variable is changed

I use a colorwheel in my sketch to change the background color. I also have a key set to choose and set random background color from an array. I would like the color wheel to update and display the actual background color when it is changed via the key event. But the colorwheel only displays the last color it was manually set too.

I tried this:
cp5.getController("colorWheel").setValue(currentBackgroundColor) but it yields no result.

I also fiddled with setRGB() instead of setValue(). But to no result. Sliders & Knobs sync seamlessly via setValue() when their variables are changed through keys. I might just miss a tiny detail here but im new to Processing and especially Controlp5. And searching the web did not help much.

Hi @Len,

Welcome to the community!

It helps to troubleshoot your problem if you post your code.
Anyway, please find my attempt to solve your problem in the code below:

import controlP5.*;

ControlP5 cp5;

void setup() {
  size(800, 400);
  cp5 = new ControlP5( this );
  cp5.addColorWheel("c" , 250 , 10 , 200 ).setRGB(color(128,0,255));
int c = color(100);

void draw() {  
  fill( c );

void keyPressed(){
 color keyColor = color(0);
   case 'r':
   keyColor = color(255,0,0);
   case 'g':
   keyColor = color(0,255,0);
   case 'b':
   keyColor = color(0,0,255);

Hope it helps!

1 Like

Perfect solution! Thank you so much. :pray: