Hi, there!
I'm new on arduino and I'm messing around with the most basic stuff... In this case, RGB leds.
I've found a pretty nice code for changing colors on RGB and I decided to make one from scratch to practice - it's different to do it by hart, than just copy/pasting and read it.
After a few hickups, it was as I wanted. Then, I turned on the Serial Monitor and it got so slow... I've realised that increasing the baud rate would speed up things.
My questions are:
1- Is this normal?
2- Is there something on my code that's slowing the program, other than the serial monitor?
3- Is there a way to keep the serial monitor on, while not afecting my program speed?
My code:
const int redPin=9;
const int greenPin=6;
const int bluePin=11;
const int tempo=10;
int redBRI;
int greenBRI;
int blueBRI;
void setup() {
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
Serial.begin(9600);
}
void loop() {
redBRI=255;
greenBRI=0;
blueBRI=0;
for(int i=0; i<255; i+=1){
redBRI-=1;
greenBRI+=1;
analogWrite(redPin,redBRI);
analogWrite(greenPin,greenBRI);
delay(tempo);
Serial.print("R: ");Serial.print(redBRI);Serial.print(" ");Serial.print("G: ");Serial.print(greenBRI);Serial.print(" ");Serial.print("B: ");Serial.println(blueBRI);
}
redBRI=0;
greenBRI=255;
blueBRI=0;
for(int i=0; i<255; i+=1){
blueBRI+=1;
greenBRI-=1;
analogWrite(bluePin,blueBRI);
analogWrite(greenPin,greenBRI);
delay(tempo);
Serial.print("R: ");Serial.print(redBRI);Serial.print(" ");Serial.print("G: ");Serial.print(greenBRI);Serial.print(" ");Serial.print("B: ");Serial.println(blueBRI);
}
redBRI=0;
greenBRI=0;
blueBRI=255;
for(int i=0; i<255; i+=1){
redBRI+=1;
blueBRI-=1;
analogWrite(redPin,redBRI);
analogWrite(bluePin,blueBRI);
delay(tempo);
Serial.print("R: ");Serial.print(redBRI);Serial.print(" ");Serial.print("G: ");Serial.print(greenBRI);Serial.print(" ");Serial.print("B: ");Serial.println(blueBRI);
}
}
Thanks in advance!