Skip to content

Instantly share code, notes, and snippets.

@krishnan793
Created September 12, 2016 16:19
Show Gist options
  • Save krishnan793/01fa1d16f0ba620f9c375efc51b55e47 to your computer and use it in GitHub Desktop.
Save krishnan793/01fa1d16f0ba620f9c375efc51b55e47 to your computer and use it in GitHub Desktop.
int RED_LED = 12;
int BLUE_LED = 13;
int GREEN_LED = 14;
void setup() {
// Initialisation
pinMode(RED_LED,OUTPUT);
pinMode(BLUE_LED,OUTPUT);
pinMode(GREEN_LED,OUTPUT);
Serial.begin(9600);
digitalWrite(RED_LED, HIGH);
digitalWrite(BLUE_LED, HIGH);
digitalWrite(GREEN_LED, HIGH);
}
void fade(int PIN)
{
for(int i=0;i<1024;i++)
{
analogWrite(PIN,i);
delay(5);
}
delay(1000);
}
void setColor(int R, int G, int B)
{
analogWrite(RED_LED,(1024-R*4));
analogWrite(BLUE_LED,(1024-B*4));
analogWrite(GREEN_LED,(1024-G*4));
}
void RGB_Spectrum()
{
int i,j,k = 0;
for(i=0; i<255; i+=40)
{
for(j=0; j<255; j+=40)
{
for(k=0; k<255; k+=40)
{
setColor(i,j,k);
delay(10);
}
}
}
}
void loop() {
// put your main code here, to run repeatedly:
//RGB_Spectrum();
delay(200);
setColor(random(0, 255),random(0, 255),random(0, 255));
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// look for the newline. That's the end of your
// sentence:
if (Serial.read() == '\n') {
setColor(red,green,blue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment