RGB code Problem

i put a post up before but it was not visible by some so i have copy and pasted the code. this is the code which i have wrote and am struggling to control the colours to increase by PWM.

this is the part of the code which is not working

void loop()
{
  if (Serial.available()) {
    value = Serial.readString();
  }

  if (value == "q") {
    redValue += 5;
  } 
  else if (value == "w") {
    greenValue += 5;
  }
  else if (value == "e") {
    blueValue += 5;
  }
  else if (value == "a") {
    redValue -= 5;
  } 
  else if (value == "s") {
    greenValue -= 5;
  }
  else if (value == "d") {
    blueValue -= 5;
  }

this is the code complied.

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;
String value = "";

void setup()
{
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    
    Serial.begin(9600);
}

void loop()
{
  if (Serial.available()) {
    value = Serial.readString();
  }

  if (value == "q") {
    redValue += 5;
  } 
  else if (value == "w") {
    greenValue += 5;
  }
  else if (value == "e") {
    blueValue += 5;
  }
  else if (value == "a") {
    redValue -= 5;
  } 
  else if (value == "s") {
    greenValue -= 5;
  }
  else if (value == "d") {
    blueValue -= 5;
  }
  
  setColor(redValue, greenValue, blueValue);

}

void setColor(int red, int green, int blue)
{
    analogWrite(redPin, red);
    analogWrite(greenPin, green);
    analogWrite(bluePin, blue);
}

I agree.
Change String value = "";
to

char value;

and change

Serial.readString()

to

Serial.read()

and replace all your double-quotes with single-quotes.

Paul

Much more readable - old topic deleted.

hey guys thanks for that it worked great really appreciate the advice

i also have another problem lol hope to catch you help if possible again.. i made a new topic so if you guy can have a look and give me any guidance i would be much grateful.

topic under:

code problem

http://forum.arduino.cc/index.php?topic=232309.msg1674453#msg1674453

hi guys i got another problem with my code for the RGB LED and i cant figure out what it is. when i press a function key to jump up by 5 or -5 it seem to carry on without stopping going al the way up or all the way down.

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;
char value ;

void setup()
{
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    
    Serial.begin(9600);
}

void loop()
{
  if (Serial.available()) {
    value = Serial.read();
  }

  if (value == 'q') {
    redValue += 5;
  } 
  else if (value == 'w') {
    greenValue += 5;
  }
  else if (value == 'e') {
    blueValue += 5;
  }
  else if (value == 'a') {
    redValue -= 5;
  } 
  else if (value == 's') {
    greenValue -= 5;
  }
  else if (value == 'd') {
    blueValue -= 5;
  }
  Serial.print(redValue);
        Serial.print(" / ");
        Serial.print(greenValue);
        Serial.print(" / ");  
        Serial.println(blueValue); 

  setColor(redValue, greenValue, blueValue);

}

void setColor(int red, int green, int blue)
{
    analogWrite(redPin, red);
    analogWrite(greenPin, green);
    analogWrite(bluePin, blue);
}

hi guys i got another problem with my code for the RGB LED and i cant figure out what it is. when i press a function key to jump up by 5 or -5 it seem to carry on without stopping going al the way up or all the way down.

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;
char value ;

void setup()
{
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    
    Serial.begin(9600);
}

void loop()
{
  if (Serial.available()) {
    value = Serial.read();
  }

  if (value == 'q') {
    redValue += 5;
  } 
  else if (value == 'w') {
    greenValue += 5;
  }
  else if (value == 'e') {
    blueValue += 5;
  }
  else if (value == 'a') {
    redValue -= 5;
  } 
  else if (value == 's') {
    greenValue -= 5;
  }
  else if (value == 'd') {
    blueValue -= 5;
  }
  Serial.print(redValue);
        Serial.print(" / ");
        Serial.print(greenValue);
        Serial.print(" / ");  
        Serial.println(blueValue); 

  setColor(redValue, greenValue, blueValue);

}

void setColor(int red, int green, int blue)
{
    analogWrite(redPin, red);
    analogWrite(greenPin, green);
    analogWrite(bluePin, blue);
}

Move all the code inside the Serial.available() conditional.
Think what happens to "value"

ill give that a try thank see what the outcome is also my led seems to jst be flashing with the PWM but its very noticeable any way i can rid of this ??

Most people can't see flicker much above 60 Hz, certainly not at nearly 500Hz, unless they're moving quickly.

All grounds are connected it happend before ingot rid of the problem but it just happend again ill jst mess about with the circuit see if anything changes. But thanks for the advice on that

i got it working so a big thanks and the LED stopped flashing/flickering don't know what the cause it but im glad it stopped