# Need help with arduino program

**URL:** https://discourse.processing.org/t/need-help-with-arduino-program/11287
**Category:** Electronics (Arduino, etc.)
**Created:** [May 15, 2019, 9:14pm UTC](https://discourse.processing.org/t/need-help-with-arduino-program/11287 "2019-05-15T21:14:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![S.L.C.S](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@S.L.C.S](https://discourse.processing.org/u/S.L.C.S)
#### Post date: [May 15, 2019, 9:14pm UTC](https://discourse.processing.org/t/need-help-with-arduino-program/11287/1 "2019-05-15T21:14:14Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

### Author: ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)
#### Post date: [May 15, 2019, 9:40pm UTC](https://discourse.processing.org/t/need-help-with-arduino-program/11287/2 "2019-05-15T21:40:01Z")

</div>

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

```auto
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()`

```auto
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;
}

```

---

<div class="post-metadata">

### Author: ![S.L.C.S](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@S.L.C.S](https://discourse.processing.org/u/S.L.C.S)
#### Post date: [May 15, 2019, 9:52pm UTC](https://discourse.processing.org/t/need-help-with-arduino-program/11287/3 "2019-05-15T21:52:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)
#### Post date: [May 15, 2019, 9:58pm UTC](https://discourse.processing.org/t/need-help-with-arduino-program/11287/4 "2019-05-15T21:58:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![S.L.C.S](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@S.L.C.S](https://discourse.processing.org/u/S.L.C.S)
#### Post date: [May 15, 2019, 10:01pm UTC](https://discourse.processing.org/t/need-help-with-arduino-program/11287/5 "2019-05-15T22:01:56Z")

</div>

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