Jelly Diffuser

I used a water bottle and played around with different materials. I wanted a material that had varying reflective/diffusive properties. Water alone was too clear, shaken with dish soap, too cloudy. Bits of foil floated to the top. Finally, I went with crumpled cling wrap stuffed into a water bottle and filled with paper, to get a translucent, “jelly” feel. I modified the code with the examples from the site so that each additional r entered increases the brightness of the red LED, resetting once maxed at 255.

/*
* Code for cross-fading 3 LEDs, red, green and blue, or one tri-color LED, using PWM
* The program cross-fades slowly from red to green, green to blue, and blue to red
* The debugging code assumes Arduino 0004, as it uses the new Serial.begin()-style functions
* Clay Shirky  
*/

char r_input[100];
int r_value = 0;

// Output
int redPin   = 9;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11

// Program variables
int redVal   = 0; // Variables to store the values to send to the pins
int greenVal = 255;   // Initial values are Red full, Green and Blue off
int blueVal  = 255;

int i = 0;     // Loop counter    
int wait = 50; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 1; // DEBUG counter; if set to 1, will write values back via serial

void setup()
{
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);         // If we want to see the pin values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput on 0004 style
}

// Main program
void loop()
{
  i += 5;      // Increment counter
  if (i < 255) // First phase of fades
  {
    greenVal += 1; // Green up
    blueVal   = 1; // Blue low
  }
  else if (i < 509) // Second phase of fades
  {
    greenVal -= 1; // Green down
    blueVal  += 1; // Blue up
  } 
  else if (i < 763) // Third phase of fades
  {
    greenVal = 1; // Green low
    blueVal -= 1; // Blue down
  }
  else // Re-set the counter, and start the fades again
  {
    i = 1;
  }  
  memset(r_input, 0, 100);   
      
  readSerialString(r_input);

  //Serial.print(r_input[0]); 
  if(r_input[0] == 'r'){
    r_value = r_value + 1;
    Serial.println(r_value); 
  }
  if (r_value == 5) {
    r_value = 0;
  }
  
  
  analogWrite(redPin,   r_value*51);   // Write current values to LED pins
  analogWrite(greenPin, greenVal); 
  analogWrite(bluePin,  blueVal);  
//  if (DEBUG) { // If we want to read the output
//    DEBUG += 1;     // Increment the DEBUG counter
//    if (DEBUG > 10) // Print every 10 loops
//    {
//      DEBUG = 1;     // Reset the counter
//
//      Serial.print(i);       // Serial commands in 0004 style
//      Serial.print("\t");    // Print a tab
//      Serial.print("R:");    // Indicate that output is red value
//      Serial.print(redVal);  // Print red value
//      Serial.print("\t");    // Print a tab
//      Serial.print("G:");    // Repeat for green and blue...
//      Serial.print(greenVal);
//      Serial.print("\t");    
//      Serial.print("B:");    
//      Serial.println(blueVal); // println, to end with a carriage return
//    }
//  }
  delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}

void readSerialString (char *strArray) {
  int i = 0;
  if(!Serial.available()) {
    return;
  }
  while (Serial.available()) {
    strArray[i] = Serial.read();
    //Serial.print(strArray);
    i++;
  }
}

I had some trouble converting/uploading the video file (I tried mp4, mov and wmv) so I uploaded it here:

Leave a Reply