Egg Diffuser – Lab 2

Description: For lab 2, I made my RGB LEDs have the following control mechanism:

“R” -> increase red brightness by 10%

“r” -> decrease red brightness by 10%

Similar pattern for capital and lowercase b and g for blue and green.

I experimented with a few things with the setup of my wiring and diffuser. First I had laid out the LEDs in a way where they were too far from each other to mix well, then I realized that it would be good to move them farther away from the resistors so that they had more space for the diffuser, so I did that by adding a few extra wires.

For the diffuser, I tried a few different things including a sugar packet, a coffee filter, a napkin, a disposable coffee cup top…

Then I tried half of an eggshell, which worked alright, but similarly to some of the other things that I tried, the color was coming through as three dots, rather than mixing nicer together. What worked best was a piece of napkin placed between the LEDs and the eggshell.

Components:

  1. Adruino board
  2. Breadboard
  3. 3 LEDs (red, green, blue)
  4. 3 220 ohm resistors
  5. 7 wires
  6. 0.5 eggshell
  7. 1 small piece of napkin

IMG_6639 IMG_6670 IMG_6673

Code:

/* 
Jake Petterson
Lab 2 -- Info 262
9/9/16

Below is the program that I wrote to control the RGB LED setup.
Users can use capital R,G,B to increase the brightness of each
LED, and lowercase r,g,b to decrease the brightness.
 */

char colorCommand; // char that will be the commmand from the user

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

double redVal = 0;
double greenVal = 0;
double blueVal = 0;

void setup() {
 pinMode(redPin, OUTPUT); // sets the pins as output
 pinMode(greenPin, OUTPUT); 
 pinMode(bluePin, OUTPUT);
 Serial.begin(9600);
 
 analogWrite(redPin, 0); // set them all to zero brightness
 analogWrite(greenPin, 0);
 analogWrite(bluePin, 0);
 
 Serial.println("Press R to increase the red brightness by 10%.\nPress"
 " G to increase the green brightness by 10%. \nPress B to increase"
 " the blue brightness by 10%.\n\nPress r, g, or b to decrease the brightness "
 "by 10%.");
 Serial.println("\nType the single letter, then press enter."); 
 
}

void loop () {
 // set the colorCommand to a space as a placeholder.
 colorCommand = ' ';
 
 // send data only when you receive data:
 while (Serial.available() > 0) {
 // read the incoming byte:
 colorCommand = Serial.read();

 Serial.println("colorCommand: ");
 Serial.println(colorCommand);
 
 // use the adjustBrightness function' 
 adjustBrightness(colorCommand, redVal, greenVal, blueVal);

 
 
 Serial.println("red: ");
 Serial.println(redVal);
 Serial.println("green: ");
 Serial.println(greenVal);
 Serial.println("blue: ");
 Serial.println(blueVal);
 
 colorCommand = ' ';
 }
}

// this function adjusts the brightness by 
// 10% depending on the command
void adjustBrightness(char colorCommand, double &redVal, double &greenVal, double &blueVal) {
 if(colorCommand == 'r' || colorCommand == 'R') {
 if(colorCommand == 'r' && redVal != 0) {
 redVal = redVal - 25.5;
 analogWrite(redPin, redVal);
 Serial.println("Red down 10%");
 }
 else if(colorCommand == 'R' && redVal != 255) {
 redVal = redVal + 25.5;
 Serial.println("Red up 10%");
 analogWrite(redPin, redVal);
 }
 }
 if(colorCommand == 'g' || colorCommand == 'G') {
 if(colorCommand == 'g' && greenVal != 0) {
 greenVal = greenVal - 25.5;
 analogWrite(greenPin, greenVal);
 Serial.println("Green down 10%");
 }
 else if(colorCommand == 'G' && greenVal != 255) {
 greenVal = greenVal + 25.5;
 analogWrite(greenPin, greenVal);
 Serial.println("Green up 10%");
 }
 }
 if(colorCommand == 'b' || colorCommand == 'B') {
 if(colorCommand == 'b' && blueVal != 0) {
 blueVal = blueVal - 25.5;
 analogWrite(bluePin, blueVal);
 Serial.println("Blue down 10%");
 }
 else if(colorCommand == 'B' && blueVal != 255) {
 blueVal = blueVal + 25.5;
 analogWrite(bluePin, blueVal);
 Serial.println("Blue up 10%");
 }
 }
}

Experimenting with Capillary tubes

LED diffusion has in my minimal experience usually meant sanding: sanding acrylic surfaces in layers and sanding the LEDs too. This time I wanted to experiment with an object I’ve had in my possession for a few years for reasons unknown: a canister of capillary tubes. My goal was to put the LEDs at the bottom of the container to see what would happen with the light and how it would diffuse both sideways through the tubes and also up along them. Between the LEDs and the bottoms of the tubes I put some stuffing to help with the diffusion process, and carefully cut a plastic cup to fit inside for the tubes to stand on. 

 

I also had ambitions to make the code translate normal strings of text into different colored patterns, brightnesses, and fade lengths, but my shortcomings with C ended up forcing me to settle for the simpler interaction (increasing brightness with key presses). Still, it’s an interesting looking object both with the tubes bunched and unbunched, and does a great job of diffusing light.

 

Materials:

Arduino Uno

Arduino Mini

Wires

Capillary Tubes; container

3 LEDs, (R, G, B)

3 Resistors (220 ohm)

Soldering iron, solder

 

Code: 

/* 
* Serial RGB LED
* —————
* Serial commands control the brightness of R,G,B LEDs 
*
* Command structure is “<colorCode><colorVal>”, where “colorCode” is
* one of “r”,”g”,or “b” and “colorVal” is a number 0 to 255.
* E.g. “r0” turns the red LED off. 
* “g127” turns the green LED to half brightness
* “b64” turns the blue LED to 1/4 brightness
*
* Created 18 October 2006
* copyleft 2006 Tod E. Kurt <tod@nulltodbot.com
* http://todbot.com/
*
*
* Special thanks to Neera, whose post I looked at in order to troubleshoot my own 🙂
*/

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// -> you must state how long the array will be else it won’t work properly
char colorCode;
int colorVal;

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

int brightNess = 0;

int i = 0; // Loop counter 
int wait = 20; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 0; // 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);
Serial.begin(9600);
analogWrite(redPin, 255); // set them all to v bright
analogWrite(greenPin, 255); 
analogWrite(bluePin, 255); 
Serial.println(“enter color command”); 
}

void loop () 
{
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);
brightNess = strlen(serInString);

colorCode = serInString[0];
if( colorCode == ‘r’ || colorCode == ‘g’ || colorCode == ‘b’) {
colorVal = int(brightNess * 10 * 2.55);
Serial.print(“setting color “);
Serial.print(colorCode);
Serial.print(” to “);
Serial.print(colorVal);
Serial.println();
serInString[0] = 0; // indicates we’ve used this string
if(colorCode == ‘r’) 
analogWrite(redPin, colorVal);
else if(colorCode == ‘g’)
analogWrite(greenPin, colorVal);
else if(colorCode == ‘b’)
analogWrite(bluePin, colorVal);

}

delay(wait); // Pause for ‘wait’ milliseconds before resuming the loop 
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int j = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[j] = Serial.read();
j++;
}
}

 

Video:

https://www.youtube.com/watch?v=fxTJK_eC5Xw&feature=youtu.be

4 3 2 1

Colored Smoke Cylinder

Description:
I used dryer sheets, ping pong balls and the cotton-like material that we had used in class to create an impression of a smoke chimney. The diffuser gives a very close approximation of white and the output is in RGB format. Of the things I had trouble with was using only a single input (no carriage return) and changing the color. The blue was also the strongest LED in the set and hence the resultant white had a tinge of blue.

Components:
I used dryer sheets, ping pong balls and the cotton-like material that we had used in class to create an

  • 1 Arduino Uno
  • 1 Breadboard
  • Resistors, Jumper cables
  • Ping pong balls
  • Dryer sheets
  • Cotton-like material for impression of smoke

Code:


/* 
Smoke cylinder by Ganesh Iyer
 */

char serInString[100];  // array that will hold the different bytes of the string. 100=100characters;
                        // -> you must state how long the array will be else it won't work properly
char colorCode;
int colorValRed = 0;
int colorValBlue = 0;
int colorValGreen = 0;

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

void setup() {
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  Serial.begin(9600);
  analogWrite(redPin,   0);   // set them all to mid brightness
  analogWrite(greenPin, 0);   // set them all to mid brightness
  analogWrite(bluePin,  0);   // set them all to mid brightness
  Serial.println("Use the r, g and b keys to manipulate and mix colors!");  
}

void loop () {
  // clear the string
  memset(serInString, 0, 100);
  //read the serial port and create a string out of what you read
  readSerialString(serInString);
    
  colorCode = serInString[0];
  if (colorCode == 'r'){
    serInString[0] = 0;
    if (colorValRed == 255){
      colorValRed = 0;
      analogWrite(redPin, colorValRed);
    }
    else{
    colorValRed = colorValRed + 20;
    }
    if (colorValRed < 255){
      analogWrite(redPin, colorValRed);
    }
    else{
      colorValRed = 255;
      analogWrite(redPin, colorValRed);
    }
    Serial.print("RGB( ");
    Serial.print(colorValRed);
    Serial.print(", ");
    Serial.print(colorValGreen);
    Serial.print(", ");
    Serial.print(colorValBlue);
    Serial.print(" )");
    Serial.println();
  }

  if (colorCode == 'g'){
    serInString[0] = 0;
    if (colorValGreen == 255){
      colorValGreen = 0;
      analogWrite(greenPin, colorValGreen);
    }
    else{
    colorValGreen = colorValGreen + 20;
    }

    if (colorValGreen < 255){
      analogWrite(greenPin, colorValGreen);
    }
    else{
      colorValGreen = 255;
      analogWrite(greenPin, colorValGreen);
    }
    Serial.print("RGB( ");
    Serial.print(colorValRed);
    Serial.print(", ");
    Serial.print(colorValGreen);
    Serial.print(", ");
    Serial.print(colorValBlue);
    Serial.print(" )");
    Serial.println();
  }

  if (colorCode == 'b'){
    serInString[0] = 0;
    if (colorValBlue == 255){
      colorValBlue = 0;
      analogWrite(bluePin, colorValBlue);
    }
    else{
    colorValBlue = colorValBlue + 20;
    }
    if (colorValBlue < 255){
      analogWrite(bluePin, colorValBlue);
    }
    else{
      colorValBlue = 255;
      analogWrite(bluePin, colorValBlue);
    }
    Serial.print("RGB( ");
    Serial.print(colorValRed);
    Serial.print(", ");
    Serial.print(colorValGreen);
    Serial.print(", ");
    Serial.print(colorValBlue);
    Serial.print(" )");
    Serial.println();
  }
  
//  if( colorCode == 'r' || colorCode == 'g' || colorCode == 'b' ) {
//    colorVal = atoi(serInString+1);
//    Serial.print("setting color ");
//    Serial.print(colorCode);
//    Serial.print(" to ");
//    Serial.print(colorVal);
//    Serial.println();
//    serInString[0] = 0;                   // indicates we've used this string
//    if(colorCode == 'r') 
//      analogWrite(redPin, colorVal);
//    else if(colorCode == 'g')
//      analogWrite(greenPin, colorVal);
//    else if(colorCode == 'b')
//      analogWrite(bluePin, colorVal);
//  }
  
  delay(100);  // wait a bit, for serial data
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
  int i = 0;
  if(!Serial.available()) {
    return;
  }

  if (Serial.available() > 0) {
    strArray[i] = Serial.read();
  }
}

Smoke cylinder

Lab 02

Description

I used Arduino with three LEDs (red, blue and green). I edited the sketch code to turn on the LED with keyboard interaction.  Each enter of the corresponding key is 255/10 of the brightness. I also use bubble rap to create an air balloon as a diffuser. I then turn the red and blue LED to 127 and green LED to zero to make a purple air balloon. However, the result is not as expected. Blue and Red are still somehow separated. Lastly, I  uploaded the code and took pictures of the result.

Components

  • 1 Arduino
  • 3 LED
  • 3 Resistor (220Ω)
  • 1 Breadboard
  • One difuser

Code

/* 
 * Serial RGB LED
 * ---------------
 * Serial commands control the brightness of R,G,B LEDs 
 *
 * Command structure is "&lt;colorCode&gt;&lt;colorVal&gt;", where "colorCode" is
 * one of "r","g",or "b" and "colorVal" is a number 0 to 255.
 * E.g. "r0" turns the red LED off. 
 * "g127" turns the green LED to half brightness
 * "b64" turns the blue LED to 1/4 brightness
 *
 * Created 18 October 2006
 * copyleft 2006 Tod E. Kurt &lt;tod@todbot.com
 * http://todbot.com/
 */

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
 // -&gt; you must state how long the array will be else it won't work properly
char colorCode;
int colorVal;

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

void setup() {
 pinMode(redPin, OUTPUT); // sets the pins as output
 pinMode(greenPin, OUTPUT); 
 pinMode(bluePin, OUTPUT);
 Serial.begin(9600);
 analogWrite(redPin, 127); // set them all to mid brightness
 analogWrite(greenPin, 127); // set them all to mid brightness
 analogWrite(bluePin, 127); // set them all to mid brightness
 Serial.println("Please enter color corresponding key to change the brightness (i.e. 'r' for RED; ''g' for GREEN; and 'b' for BLUE :"); 
}

void loop () {
 // clear the string
 memset(serInString, 0, 100);
 //read the serial port and create a string out of what you read
 readSerialString(serInString);
 
 colorCode = serInString[0];
 if( colorCode == 'r' || colorCode == 'g' || colorCode == 'b' ) {
 colorVal = atoi(serInString+1);
 colorVal = strlen(serInString);
 colorVal = (colorVal*255/10); // increase the value by 10% by calculating the number of times you type r, g or b defines the brightness (% of)
 if (colorVal&gt;255)
 { // need a way to turn off colors
 colorVal = 0;}
 Serial.print("setting color ");
 Serial.print(colorCode);
 Serial.print(" to ");
 Serial.print(colorVal);
 Serial.println();
 serInString[0] = 0; // indicates we've used this string
 if(colorCode == 'r') 
 analogWrite(redPin, colorVal);
 else if(colorCode == 'g')
 analogWrite(greenPin, colorVal);
 else if(colorCode == 'b')
 analogWrite(bluePin, colorVal);
 }
 
 delay(100); // wait a bit, for serial data
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
 int i = 0;
 if(!Serial.available()) {
 return;
 }
 while (Serial.available()) {
 strArray[i] = Serial.read();
 i++;
 }
}
IMAG1131

Go Bears !

Ever since I came to Berkeley and became a part of this beautiful campus and amazing community, I have been fascinated by the Campanile. With this lab, I have tried to recreate the lights part of the Light and Music Show at the Campanile.

It very exciting to think about how much diverse and cutting edge work is happening on these 1232 acres of land and yet at the end of every hour these bells unify us (our awareness)  across the diversity, thus strengthening the sense of community. Go Bears!

Components:

  • Arduino Uno
  • Breadboard
  • 3 LEDs (rgb)
  • 3 220Ω Resistors
  • jumper wires
  • USB cable
  • laptop

Code:

/*
* Serial RGB LED
* —————
* Serial commands control the brightness of R,G,B LEDs
*
* Command structure is “<colorCode(1)><colorCode(n)>”, where “colorCode” is
* one of “r”,”g”,or “b”.
* E.g. “rr” sets the red LED to 20% brightness.
* “gggg” sets the green LED to 40% brightness
* “bbb” sets the blue LED to 30% brightness
*
* Created 13 Sep 2016
*
*/

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// -> you must state how long the array will be else it won’t work properly
char colorCode;
int colorVal;

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
int lenStr = 0;

void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 127); // set them all to mid brightness
analogWrite(greenPin, 127); // set them all to mid brightness
analogWrite(bluePin, 127); // set them all to mid brightness
Serial.println(“enter color command (e.g. ‘r43’) :”);
}

void loop () {
//Serial.println(“in the loop”);
// clear the string
memset(serInString, 0, 100);

//read the serial port and create a string out of what you read
readSerialString(serInString);
//Serial.println(serInString);
lenStr = strlen(serInString);
//Serial.println(lenStr);

colorCode = serInString[0];
if( colorCode == ‘r’ || colorCode == ‘g’ || colorCode == ‘b’ ) {
colorVal = int(lenStr * 10 * 2.55);
//Serial.println(colorVal);
Serial.print(“setting color “);
Serial.print(colorCode);
Serial.print(” to “);
Serial.print(colorVal);
Serial.println();
if(colorCode == ‘r’)
analogWrite(redPin, colorVal);
else if(colorCode == ‘g’)
analogWrite(greenPin, colorVal);
else if(colorCode == ‘b’)
analogWrite(bluePin, colorVal);
}

delay(100); // wait a bit, for serial data
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int i = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[i] = Serial.read();
i++;
}
}

20160913_224117 20160913_224204 20160913_224009

Rainbow Ball

Description

I created a rainbow ball. It allows users to type the initial character of a rainbow color, and LEDs inside the ball will graduate changes their brightness to show this color. It accepts 7 characters from users:

  1. ‘r’: set the ball to red;
  2. ‘o’: set the ball to orange;
  3. ‘y’: set the ball to yellow;
  4. ‘g’: set the ball to green;
  5. ‘c’: set the ball to cyan;
  6. ‘b’: set the ball to blue;
  7. ‘p’: set the ball to purple.

Components

  • 1 Arduino
  • 1 Diffuser (cotton ball)
  • 3 LEDs
  • 3 Resistors (220Ω)
  • 7 Jumper wires
  • 1 USB cable
  • 1 Breadboard

Code

char serInString[100];  
int redVal, greenVal, blueVal;
int redCurr = 127;
int greenCurr = 127;
int blueCurr = 127;
int increRed, increBlue, increGreen;
int redPin   = 9;   
int greenPin = 10;  
int bluePin  = 11; 
int redPre = 127;
int bluePre = 127;
int greenPre = 127;

void setup() {
  pinMode(redPin,   OUTPUT);  
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  Serial.begin(9600);
  analogWrite(redPin,   redPre);   
  analogWrite(greenPin, bluePre);   
  analogWrite(bluePin,  greenPre);  
  Serial.println("enter a rainbow color 
  ('r' for Red, 
  'o' for Orange,
  'y' for Yellow, 
  'g' for Green, 
  'c' for Cyan, 
  'b' for Blue,
  'p' for Purple)");  
}

void printSerial() {
  Serial.print("setting color ");
  Serial.print("red");
  Serial.print(" to ");
  Serial.print(redCurr);
  Serial.println(); 

  Serial.print("setting color ");
  Serial.print("blue");
  Serial.print(" to ");
  Serial.print(blueCurr);
  Serial.println();

  Serial.print("setting color ");
  Serial.print("green");
  Serial.print(" to ");
  Serial.print(greenCurr);
  Serial.println();
}

void loop () {
  memset(serInString, 0, 100);
  readSerialString(serInString);
    
  if( serInString[0]== 'r') {
    redCurr = 255;
    greenCurr = 0;
    blueCurr = 0;
    printSerial();
    serInString[0] = ' ';                  
  }
  if( serInString[0]== 'o') {
    redCurr = 255;
    greenCurr = 127;
    blueCurr = 0;
    printSerial();
    serInString[0] = ' ';                  
  }
  if( serInString[0]== 'y') {
    redCurr = 255;
    greenCurr = 255;
    blueCurr = 0;
    printSerial();
    serInString[0] = ' ';  
  }
  if( serInString[0]== 'g') {
    redCurr = 0;
    greenCurr = 255;
    blueCurr = 0;
    printSerial();
    serInString[0] = ' ';
  }
  if( serInString[0]== 'c') {
    redCurr = 0;
    greenCurr = 255;
    blueCurr = 255;
    printSerial();
    serInString[0] = ' ';
  }
  if( serInString[0]== 'b') {
    redCurr = 0;
    greenCurr = 0;
    blueCurr = 255;
    printSerial();
    serInString[0] = ' '; 
  }
  if( serInString[0]== 'p') {
    redCurr = 127;
    greenCurr = 0;
    blueCurr = 255;
    printSerial();
    serInString[0] = ' '; 
  }
  
  if(redPre &gt; redCurr) {
    increRed = -1;
  }
  else {
    increRed = 1;
  }
  redVal = redPre;
  while(redVal != redCurr) {
    analogWrite(redPin, redVal);
    delay(10);
    redVal += increRed;
  }
  redPre = redCurr;
  
  if(bluePre &gt; blueCurr) {
    increBlue = -1;
  }
  else {
    increBlue = 1;
  }
  blueVal = bluePre;
  while(blueVal != blueCurr) {
    analogWrite(bluePin, blueVal);
    delay(10);
    blueVal += increBlue;
  }
  bluePre = blueCurr;
  if(greenPre &gt; greenCurr) {
    increGreen = -1;
  }
  else {
    increGreen = 1;
  }

  greenVal = greenPre;
  while(greenVal != greenCurr) {
    analogWrite(greenPin, greenVal);
    greenVal += increGreen;
    delay(10);
  }
  greenPre = greenCurr;
  
delay(100);
}

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

Lab 2

Part 1:  LIGHT DIFFUSER

I made an origami flower out of waxed paper. I was curious how the wax coating on the paper would affect the light quality. The origami flower is folded in a way that the center is a hollow sphere, with the petals attached to this sphere. I like how the light reaches beyond the sphere and is reflected on the petals.

Part 2: MANUAL LED OPERATION

I wanted to set the LED lights so they could be each be individually turned on by increments of 50 with each letter of their color typed in. At the beginning of a load-in, the lights are all off, but when the first letter of a color (i.e. “r” for red) is typed in the serial monitor, that color is lit by increments of 50. So the first “r” will bring the light to 50, second “r” brings the light to 100, third to 150 and so on. When the brightness reaches maximum (250), the next “r” brings it back to 0, or off.

This control is repeated for the other two lights: “g” for green and “b” for blue.

materials:
—1 Arduino

—3 LEDs

—3 220 ohm resistors

—1 breadboard

—7 wires

 

CODE

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// -> you must state how long the array will be else it won’t work properly
char colorCode;
int colorVal;

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
int redVal = 0; // brightness value for red LED, must be between 0 and 255
int greenVal = 0; // brightness value for green LED, must be between 0 and 255
int blueVal = 0; // brightness value for blue LED, must be between 0 and 255

void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 0); // set them all to mid brightness
analogWrite(greenPin, 0); // set them all to mid brightness
analogWrite(bluePin, 0); // set them all to mid brightness
Serial.println(“enter color command (e.g. ‘r43’) :”);
}

void loop () {
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);

colorCode = serInString[0];
if( colorCode == ‘r’ || colorCode == ‘g’ || colorCode == ‘b’ ) {
colorVal = atoi(serInString+1);

serInString[0] = 0; // indicates we’ve used this string
if(colorCode == ‘r’){
redVal = redVal + 50;
if (redVal > 255){
redVal = 0;
}
Serial.print(“setting color “);
Serial.print(colorCode);
Serial.print(” to “);
Serial.print(redVal);
Serial.println();

analogWrite(redPin, redVal);
}
else if(colorCode == ‘g’){
greenVal = greenVal + 50;
if (greenVal > 255){
greenVal = 0;
}
Serial.print(“setting color “);
Serial.print(colorCode);
Serial.print(” to “);
Serial.print(greenVal);
Serial.println();

analogWrite(greenPin, greenVal);
}
else if(colorCode == ‘b’){
blueVal = blueVal + 50;
if (blueVal > 255){
blueVal = 0;
}
Serial.print(“setting color “);
Serial.print(colorCode);
Serial.print(” to “);
Serial.print(blueVal);
Serial.println();
}
analogWrite(bluePin, blueVal);
}

delay(100); // wait a bit, for serial data
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int i = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[i] = Serial.read();
i++;
}

 

 

 

IMG_4398 IMG_4401 IMG_4409 20160913_215453 waxed paper origami flower IMG_4390

LED Light Mixer with Origami Lamp Diffuser

Introduction

For this project, I got very interested in creating a paper origami lamp as the diffuser, and got interested in how to create a mixed color of purple, orange, yellow out of the R, G, B LED lights we have in our kit.

I compared a series of paper origami lamps online and tried one which turned out to be too long in scale for our mini LED lights. So the one I used in this project is my second attempt, which matches the scale of the LED lights, yay! :p

For the color mixing part, I used Adobe Illustrator to figure out the basic RGB values for color mixing patterns for purple, orange and yellow, and it turned out to be quite interesting. So for purple, in my code, I use equal brightness of red light and blue light and turn the brightness of green light to 0; for yellow, it’s similarly mixed via equal brightness of red and green; while for orange, it requires the green light to have half or even lower brightness when compared to the red light.

Components

  • 1x Arduino Uno
  • 1x Breadboard
  • 3x Jumper Wires
  • 3x LEDs (R/G/B)
  • 3x 220Ω Resistors
  • 1x USB Cable
  • 1x Macbook Pro
  • 1x Paper
  • 1x Double-Sided Tape

Code
/* Safei modified version
* Serial RGB LED
* —————
* Serial commands control the brightness of R,G,B LEDs
*
* Command structure is “<colorCode><colorVal>”, where “colorCode” is
* one of “r”,”g”,or “b” and “colorVal” is a number 0 to 255.
* E.g. “r0” turns the red LED off.
* “g127” turns the green LED to half brightness
* “b64” turns the blue LED to 1/4 brightness
*
* Created 18 October 2006
* copyleft 2006 Tod E. Kurt <tod@nulltodbot.com
* http://todbot.com/
*/

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// ->you must state how long the array will be else it won’t work properly
char colorCode;
int colorVal;
int colorVal2;

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

void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 0); // set them all to mid brightness
analogWrite(greenPin, 0); // set them all to mid brightness
analogWrite(bluePin, 0); // set them all to mid brightness
Serial.println(“enter color command (e.g. you can press up to 10 times of the initial letter of 6 different colors – r, g, b, o (for orange), p (for purple), y (for yellow), the brightness of the color will increase 20% by one letter input) :”);
}

void loop () {
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);

colorCode = serInString[0];
if( colorCode == ‘r’ || colorCode == ‘g’ || colorCode == ‘b’ || colorCode == ‘o’ || colorCode == ‘p’ || colorCode == ‘y’ ) {
//colorVal = atoi(serInString+1);
colorVal = 0;
for (int i=0; i<strlen(serInString); i++) {
if( colorCode == ‘r’ || colorCode == ‘g’ || colorCode == ‘b’ || colorCode == ‘o’ || colorCode == ‘p’ || colorCode == ‘y’ )
{
colorVal += 1;
}
}
if (strlen(serInString) > 10){
colorVal = 0;
}

//colorVal = strlen(serInString);
colorVal = colorVal*25.5;
colorVal2 = colorVal/2;
Serial.print(“setting color “);
Serial.print(colorCode);
Serial.print(” to “);
Serial.print(colorVal);
Serial.println();
serInString[0] = 0; // indicates we’ve used this string
if(colorCode == ‘r’) {
analogWrite(redPin, colorVal);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);}
else if(colorCode == ‘g’) {
analogWrite(greenPin, colorVal);
analogWrite(bluePin, 0);
analogWrite(redPin, 0);}
else if(colorCode == ‘b’) {
analogWrite(bluePin, colorVal);
analogWrite(greenPin, 0);
analogWrite(redPin, 0);}
else if(colorCode == ‘o’) {
analogWrite(redPin, colorVal);
analogWrite(greenPin, colorVal2);
analogWrite(bluePin, 0);}
else if(colorCode == ‘y’) {
analogWrite(redPin, colorVal);
analogWrite(greenPin, colorVal);
analogWrite(bluePin, 0);}
else if(colorCode == ‘p’) {
analogWrite(redPin, colorVal);
analogWrite(bluePin, colorVal);
analogWrite(greenPin, 0);}
}

delay(100); // wait a bit, for serial data
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int i = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[i] = Serial.read();
i++;
}
}

Photos + Video

IMG_0553 IMG_0561 IMG_0555

Night light

Description

I altered the code to dim LEDs so it now takes input in form of ‘rrr’ or ‘gggggg’. I also tried different diffusers like paper and cloth, in addition to the cotton and styrofoam that we worked with in class. Finally, I settled on an LED lamp – which I removed the batteries from – and held it on top of my breadboard LEDs for the purposes of this assignment. This lamp can be kept in a corner and used as a nightlight, the color of which can be changed on your command.

Components

1 Arduino Uno
3 LEDs
3 220Ω Resistors
1 Breadboard
Jumper wires
USB cable


char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
char colorCode;
int colorVal;

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

void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 127); // set them all to mid brightness
analogWrite(greenPin, 127); // set them all to mid brightness
analogWrite(bluePin, 127); // set them all to mid brightness
Serial.println("enter color command (e.g. 'rrrr') :");
}

void loop () {
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);

colorCode = serInString[0];
colorVal = 0;
if( colorCode == 'r' || colorCode == 'g' || colorCode == 'b' ) {
for (int i=0; i &lt; strlen(serInString); i++) {
if( colorCode == 'r' || colorCode == 'g' || colorCode == 'b' )
{
colorVal += 1;
}
}

colorVal = (colorVal/200.0)*255;
Serial.print("setting color ");
Serial.print(colorCode);
Serial.print(" to intensity: ");
Serial.print(colorVal);
Serial.println();
serInString[0] = 0; // indicates we've used this string
if(colorCode == 'r')
analogWrite(redPin, colorVal);
else if(colorCode == 'g')
analogWrite(greenPin, colorVal);
else if(colorCode == 'b')
analogWrite(bluePin, colorVal);
}

delay(100); // wait a bit, for serial data
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int i = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[i] = Serial.read();
i++;
}
}

IMG_20160912_025841

IMG_20160912_025517

IMG_20160912_025502

Creating My Own Mini Glacier

For this project, I attempted to recreate the glaciers I saw on a recent trip to Iceland. The jagged edges of the ice coupled with the pure blue color was an image that I’ll never forget and wanted to replicate. I used an Arduino board and 3 LEDs – Red, Green, and Blue – and I used a plastic shower cap to diffuse the light. Using specific keystrokes I was able to control the intensity of each of the LED’s brightness. For example, by pressing capital “R”, “G”, or “B” would result in the corresponding LED to increase it’s brightness by 50. If the lowercase letter was pressed, the intensity would increase by 15.

Components:

  1. Adruino board
  2. Breadboard
  3. 3 LEDs (red, green, blue)
  4. 3 ohm resistors
  5. 4 wires
  6. 1 plastic shower cap

 

Code:

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// -> you must state how long the array will be else it won’t work properly
char colorCode;
int colorVal;
int redVal;
int greenVal;
int blueVal;
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
void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 127); // set them all mid-brightness
analogWrite(greenPin, 127); // set them all mid-brightness
analogWrite(bluePin, 127); // set them all mid-brightness
Serial.println(“enter color command using r’s, b’s, g’s, R’s, B’s, and G’s (e.g. ‘rrrrrrggggg’ ‘RRBBGG’ RRRRR’) :”);
}
void loop () {
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);
// initialize all back to zero for each loop
redVal = 0;
greenVal = 0;
blueVal = 0;
colorCode = serInString[0];
if( colorCode == ‘r’ || colorCode == ‘g’ || colorCode == ‘b’ || colorCode == ‘R’ || colorCode == ‘G’ || colorCode == ‘B’) {
// increment each color based on number of each letter
for (int i = 0; i < strlen(serInString); i++) {
switch(serInString[i]) {
case ‘r’:
redVal += 15;
break;
case ‘g’:
greenVal += 15;
break;
case ‘b’:
blueVal += 15;
break;
case ‘R’:
redVal += 50;
break;
case ‘G’:
greenVal += 50;
break;
case ‘B’:
blueVal += 50;
}
}
Serial.print(“Setting color “);
Serial.println();
Serial.print(“red to “);
Serial.print(redVal);
Serial.println();
Serial.print(“green to “);
Serial.print(greenVal);
Serial.println();
Serial.print(“blue to “);
Serial.print(blueVal);
Serial.println();
serInString[0] = 0; // indicates we’ve used this string
analogWrite(redPin, redVal);
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
}
delay(100); // wait a bit, for serial data
}
//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int i = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[i] = Serial.read();
i++;
}
}

 

DSC_0411

Below an Icelandic glacier; what I wanted to mimic.

 

IMG_7384 IMG_7385 IMG_7386 IMG_7387

Lights changing video