Author Topic: Arduino software RGB controller  (Read 1040 times)

0 Members and 1 Guest are viewing this topic.

Offline lolimpolTopic starter

  • Contributor
  • Posts: 42
  • Country: nl
  • What level of irony are you on right now?
Arduino software RGB controller
« on: September 02, 2017, 08:02:30 am »
so, I made a post here a while ago about an Arduino code. that code controls my RGB led strips. now I want to add a rainbow functionality. I used an RGB speaker software for a while, this is what they used:
Code: [Select]
case 'f': speed = Serial.parseInt();
intensity = Serial.parseInt();
fadeRGB(speed, intensity);
flushSerial();
return true;
break;
In my code, 1 is off, 2 is on, and 3 + RGB value sets a color. so 4 +speed would make a rainbow!
could anyone help me with this? thanks!

code:
I am making a computer controlled RGB controller, I have my code made. but I want to add rainbow functionality on the serial string 4 + speed. please help me!
code:
Code: [Select]
int redpin = 3; //intialize all the pins
int greenpin = 5;
int bluepin = 6;
int r = 255; //initialize the rgb values
int g = 255;
int b = 255;
int serial; //initialize the variable to store the serial input

void setup() {
  pinMode(redpin, OUTPUT); //set the pins as output
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
  analogWrite(redpin, 0); //turn the pins off
  analogWrite(greenpin, 0);
  analogWrite(bluepin, 0);

  Serial.begin(9600); //begin the serial monitor at 9600 baud
  Serial.print("Hello"); //say Hello, be polite!
}

void loop() {
    int serial = Serial.read();

     
    if (serial == '1') //if it's 1 the pins turn off
    {
      analogWrite(redpin, 0); //turn the pins off
      analogWrite(greenpin, 0);
      analogWrite(bluepin, 0);
      Serial.print(" The led's are now off ");
      }

     
    else if (serial == '2')//if it's 2 the pins turn on
    {
      analogWrite(redpin, r); //turn the pins on
      analogWrite(greenpin, g);
      analogWrite(bluepin, b);
      Serial.print(" The led's are now on ");
      }

     
    else if (serial == '3')//if it's 3 change the colours
    {
      r = Serial.parseInt();//look for the next valid integer in the incoming serial stream
      g = Serial.parseInt();//do it again
      b = Serial.parseInt();//and again
     
      analogWrite(redpin, r); //turn the pins on
      analogWrite(greenpin, g);
      analogWrite(bluepin, b);
     
      //for debugging:
      Serial.print(" ");
      Serial.print(r);
      Serial.print(" ");
      Serial.print(g);
      Serial.print(" ");
      Serial.print(b);
      Serial.print(" ");
      }

     
      else if (serial == '4')//if it's 3 change the colours
    {
      Serial.print(" ");
      Serial.print(r);
      Serial.print(" ");
      Serial.print(g);
      Serial.print(" ");
      Serial.print(b);
      Serial.print(" ");
      }
}
« Last Edit: September 02, 2017, 12:32:30 pm by lolimpol »
*Insert cool inspirational text here*
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf