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 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.
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);
}
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 ??
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