How to control light brightness from a slider

I want to make a slider in processing so that i can control the amount of red brightness with the mouse/slider.

What would the commands be to be able to do this in arduino & processing as i cannot find what commands would do this.

Thanks

I’ve done that. The Processing application looks like this:

import processing.serial.*;

int fontNumb = 156;
int theSize = 36;
PFont theFont;

int sliderH = 60;
int sliderW = 10;
int margin = 10;

int textH = sliderH;
int textW = 50;

int redFieldX = textW + margin;
int redFieldY = 15;

int redSliderX = redFieldX;
int redSliderY = redFieldY - 5;

int grnFieldX = redFieldX;
int grnFieldY = redFieldY + sliderH + margin;

int grnSliderX = grnFieldX;
int grnSliderY = grnFieldY - 5;

int bluFieldX = redFieldX;
int bluFieldY = grnFieldY + sliderH + margin;

int bluSliderX = bluFieldX;
int bluSliderY = bluFieldY - 5;

int fieldH = 50;
int fieldW = 255 + sliderW;

int colorH = 60;
int colorW = textW + fieldW;

int colorX = margin;
int colorY = bluSliderY + sliderH + margin;

int panelH = margin + 3 * (sliderH + margin) + colorH + margin + 40;
int panelW = margin + colorW + margin;

color redColor = color(255, 0, 0);
color grnColor = color(0, 255, 0);
color bluColor = color(0, 0, 255);
color blkColor = color(0, 0, 0);

boolean redMoving = false;
boolean grnMoving = false;
boolean bluMoving = false;

int mouseDownX = 0;
int sliderPos = 0;

Serial myPort;

void setup()
{
  size(panelW, panelH);
  noStroke();
  
  rectMode(CORNER);
  textAlign(LEFT);
  
  String[] fontList = PFont.list();
  println(fontList);
  
  String fontName = PFont.list()[fontNumb];
  println(fontName);
  
  theFont = createFont(fontName, theSize);
  
  // open a serial port:
  myPort = new Serial(this, Serial.list()[1], 9600);
}

void draw()
{
  background(192, 192, 192);
  
  textFont(theFont);
  textAlign(LEFT);
  
  fill(redColor);
  text("R", margin, redFieldY+fieldH-5);
  rect(redFieldX, redFieldY, fieldW, fieldH);
  
  fill(grnColor);
  text("G", margin, grnFieldY+fieldH-5);
  rect(grnFieldX, grnFieldY, fieldW, fieldH);
  
  fill(bluColor);
  text("B", margin, bluFieldY+fieldH-5);
  rect(bluFieldX, bluFieldY, fieldW, fieldH);
  
  fill(blkColor);
  if(redMoving)
    stroke(255, 255, 255);
  else
    noStroke();
  rect(redSliderX, redSliderY, sliderW, sliderH);

  if(grnMoving)
    stroke(255, 255, 255);
  else
    noStroke();
  rect(grnSliderX, grnSliderY, sliderW, sliderH);

  if(bluMoving)
    stroke(255, 255, 255);
  else
    noStroke();
  rect(bluSliderX, bluSliderY, sliderW, sliderH);
  
  color theColor = color((redSliderX - redFieldX),
                         (grnSliderX - grnFieldX),
                         (bluSliderX - bluFieldX));
  fill(theColor);
  rect(colorX, colorY, colorW, colorH);
  
  stroke(0, 0, 0);
  fill(255, 255, 255);
  textAlign(CENTER);
  String theColorStg = nf((redSliderX - redFieldX), 3) + ", " +
                       nf((grnSliderX - grnFieldX), 3) + ", " +
                       nf((bluSliderX - bluFieldX), 3);
  text(theColorStg, width/2, height - margin);
}

void mousePressed()
{
  if(mouseX > redSliderX && mouseX < (redSliderX + sliderW))
  {
    if(mouseY > redSliderY && mouseY < (redSliderY + sliderH))
    {
      println("Mouse pressed in red slider");
      redMoving = true;
      sliderPos = redSliderX;
      mouseDownX = mouseX;
    }
  }
  
  if(mouseX > grnSliderX && mouseX < (grnSliderX + sliderW))
  {
    if(mouseY > grnSliderY && mouseY < (grnSliderY + sliderH))
    {
      println("Mouse pressed in grn slider");
      grnMoving = true;
      sliderPos = grnSliderX;
      mouseDownX = mouseX;
    }
  }
  if(mouseX > bluSliderX && mouseX < (bluSliderX + sliderW))
  {
    if(mouseY > bluSliderY && mouseY < (bluSliderY + sliderH))
    {
      println("Mouse pressed in blu slider");
      bluMoving = true;
      sliderPos = bluSliderX;
      mouseDownX = mouseX;
    }
  }
}

void mouseDragged()
{
  if(redMoving)
  {
    redSliderX = sliderPos + mouseX - mouseDownX;
    if(redSliderX < redFieldX)
      redSliderX = redFieldX;
    if(redSliderX > redFieldX + 255)
      redSliderX = redFieldX + 255;
  }
  
  if(grnMoving)
  {
    grnSliderX = sliderPos + mouseX - mouseDownX;
    if(grnSliderX < grnFieldX)
      grnSliderX = grnFieldX;
    if(grnSliderX > grnFieldX + 255)
      grnSliderX = grnFieldX + 255;
  }
  
  if(bluMoving)
  {
    bluSliderX = sliderPos + mouseX - mouseDownX;
    if(bluSliderX < bluFieldX)
      bluSliderX = bluFieldX;
    if(bluSliderX > bluFieldX + 255)
      bluSliderX = bluFieldX + 255;
  }
}

void mouseReleased()
{
  redMoving = false;
  grnMoving = false;
  bluMoving = false;
  
  String theColorStg = "R" + nf((redSliderX - redFieldX), 3) +
                       "G" + nf((grnSliderX - grnFieldX), 3) +
                       "B" + nf((bluSliderX - bluFieldX), 3);
  myPort.write(theColorStg);
  println(theColorStg);
}

The Arduino then parses the command (“R020G150B200”) to set the PWM level for each of 3 pins, for an RGB LED. Trivial stuff, really.