2. Qwerty Rainbow with Plastic Cup Diffuser (w/ video)

Posted by Erich

Erich's picture

Using a plastic cup wrapped in masking tape, I diffused the light being produced by RGB LEDs. The code would fade from color to color depending on what keys were typed. The letters of "qwerty" each represented a color of the rainbow.

Video: http://www.youtube.com/watch?v=GcCyi_XIGAU

 

My code for the qwerty rainbow: (other code same as sample code provided)

 

/ * Command structure is "qwerty", where each letter of "qwerty"
 is one of the colors of the rainbow.
 E.g. "qw"   turns the color to red then fades to yellow.  
      "qet"  goes from red to green to blue
      "qwerty" spans the rainbow, ending on violet */
 
void processRainbow(char *strArray, int maxLength) {

 

  int i = 0;
 
  while (i < maxLength && strArray[i] != '\0') {
    colorCode = serInString[i];
    Serial.println("o");
    if (colorCode == 'q') {
      redValueNew = 255;
      greenValueNew = 0;
      blueValueNew = 0;
      Serial.println("red");
      
    } else if (colorCode == 'w') {
      redValueNew = 255;
      greenValueNew = 255;
      blueValueNew = 0;
      Serial.println("yellow");
      
    } else if (colorCode == 'e') {
      redValueNew = 0;
      greenValueNew = 255;
      blueValueNew = 0;
      Serial.println("green");
      
    } else if (colorCode == 'r') {
      redValueNew = 0;
      greenValueNew = 255;
      blueValueNew = 255;
      Serial.println("cyan");
      
    } else if (colorCode == 't') {
      redValueNew = 0;
      greenValueNew = 0;
      blueValueNew = 255;
      Serial.println("blue");
      
    } else if (colorCode == 'y') {
      redValueNew = 255;
      greenValueNew = 0;
      blueValueNew = 255;
      Serial.println("magenta");
      
    }
    
    while (redValueNew != redValue || greenValueNew != greenValue || blueValueNew != blueValue){
      if (redValueNew > redValue){ 
        redValue += 5;
        analogWrite(redPin, redValue);
        delay(10);
      }
      else if (redValueNew < redValue){ 
        redValue += -5;
        analogWrite(redPin, redValue);
        delay(10);
      }
      
      if (greenValueNew > greenValue){ 
        greenValue += 5;
        analogWrite(greenPin, greenValue);
        delay(10);
      }
      else if (greenValueNew < greenValue){ 
        greenValue += -5;
        analogWrite(greenPin, greenValue);
        delay(10);
      }
      
      if (blueValueNew > blueValue){ 
        blueValue += 5;
        analogWrite(bluePin, blueValue);
        delay(10);
      }
      else if (blueValueNew < blueValue){ 
        blueValue += -5;
        analogWrite(bluePin, blueValue);
        delay(10);
      }
    }
      
     i++;
  }
}
Plastic Cup with Masking Tape Diffuser
Circuit.jpg
0
Your rating: None