Need help with arduino program

so i was asked to make a Processing program that simulates an RGB LED changing through the color spectrum. Prompt the user for a speed when your program starts. The larger the speed value, the quicker your RGB LED will cycle through the color spectrum.

float speed;


void setup() {
  size(120, 120);
  stroke(0);

import javax.swing.JOptionPane;
speed = float(JOptionPane.showInputDialog("Enter speed value"));
}

void draw() { 
    fill(0, 255, 0);
    ellipse(60, 60, 50, 50);
}

so far i have this but i don’t know of a way to make the circle(RGB led ) change to the different colours after i input the speed in the user prompt.

i find it useful, give it a try,
https://codepen.io/SJF/pen/wBdpXV

float speed;
void setup() {
  size(120, 120);
  stroke(0);

  import javax.swing.JOptionPane;
  speed = float(JOptionPane.showInputDialog("Enter speed value"));
}

float t = 0;
float r = 255;
float g = 0;
float b = 0;
void draw() {
  if (r > 0 && b <= 0) {
    r -=speed;
    g +=speed;
  }
  if (g > 0 && r <= 0) {
    g -=speed;
    b +=speed;
  }
  if (b > 0 && g <= 0) {
    r +=speed;
    b -=speed;
  }
  color c = color(r, g, b);
  fill(c);
  ellipse(60, 60, 50, 50);
}

or you can play with sin(), cos()

float t = 0;
void draw() {
  float r = sin(t) * 255;
  float g = cos(t) * 255;
  float b = sin(t * t) * 255;
  color c = color(r, g, b);
  fill(c);
  ellipse(60, 60, 50, 50);
  t+= speed;
}
2 Likes

Could you tell me why g=0 and b= 0?

see in the website on how the transition from one channel to another. ideally, they start at Red =255, Green = 0, Blue = 0

I have checked the website but i want to know why they started with those values for r,g and b