Fading and Flashing!

Description:

Today I decided to try to have my 3 LED lights change based on 2 potentiometers. I have one pot into the Analog input A0 and another into the Analog input A1. If I change A0 pot manually, it changes how bright the light is. If I change A1 pot manually, it changes how fast the blinking is.

Movie of my potentiometers in action!

Components:

  • Arduino Uno
  • Breadboard
  • 2x potentiometers
  • 3x LEDs (red, green, blue)
  • 3x 220Ω resistors
  • jumper wires
  • USB cable
  • computer

Code:


int sensorPin = A0; // select the input pin for the potentiometer
int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot

int sensorPin_blink = A1; // select the input pin for the potentiometer
int potPin_blink = 0; // Analog input pin that the potentiometer is attached to
int potValue_blink = 0; // value read from the pot

int redledPin = 9;
int blueledPin = 10;
int greenledPin = 11;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(redledPin, OUTPUT);
pinMode(blueledPin, OUTPUT);
pinMode(greenledPin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
potValue = analogRead(potPin); // read the pot value
analogWrite(redledPin, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
analogWrite(blueledPin, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
analogWrite(greenledPin, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
Serial.println("hello"); // print the pot value back to the debugger pane
delay(10);// wait 10 milliseconds before the next loop
////Blinking
potValue_blink = analogRead(sensorPin_blink);
// turn the ledPin on
analogWrite(redledPin, potValue/4);
analogWrite(blueledPin, potValue/4);
analogWrite(greenledPin, potValue/4);
// stop the program for milliseconds:
delay(potValue_blink);
// turn the ledPin off:
analogWrite(redledPin, 0);
analogWrite(blueledPin, 0);
analogWrite(greenledPin, 0);
// stop the program for for milliseconds:
delay(potValue_blink);

}

Diffuser and Changing Lights

IMG_1514Description:

In this assignment, we expanded our 1 blinking LED light circuit to be 3 LED blinking lights, and then explored how different diffusers change how we perceive the light, and how we can modify the code to take user input.

I looked through past student’s presentations for examples (http://courses.ischool.berkeley.edu/i290-13/f07/assignments/39.html) and I decided to play around with users increasing/decreasing the LED light brightness. You increase the light with a capital letter (R = red, B = blue, G = green) and decrease with a lowercase letter.

For the diffuser I tried a few different techniques. I initially used the cotton provided in class, and decided that I wanted to see how colored diffusers made a difference. I found some black tissue paper and wrapped it around, and put all of it in a uniqlo bag. It worked really well if the brightness was at max.

Components:

  • 1x Arduino Uno
  • 1x Breadboard
  • Breadboard wires
  • 3x LEDs
    • 1 Red
    • 1 Green
    • 1 Blue
  • 3x 220Ω Resistors
  • USB cable

Code:


/*
* 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
* Clay Shirky <clay.shirky@nyu.edu>
*
* Adapted by Ken-ichi Ueda <kueda@ischool.berkeley.edu>
* Adapted by Michelle Carney from http://courses.ischool.berkeley.edu/i290-13/f07/assignments/39.html
*/

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

// Program variables
int redVal= 127;
int greenVal = 10;
int blueVal = 10;
char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;

int wait = 5; // millesconds to wait btwn fade increments
int inc = 10; // increment value for brightening or dimming LEDs
int i = 0; // Loop counter
char cmd; // holds a command character
char tled; // target LED of a command ('r', 'g', 'b')

void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
writeAllValues();

Serial.println("Commands:");
Serial.println(" r -- decreases red LED brightness by 10");
Serial.println(" RRR -- increases red LED brightness by 30");
Serial.println(" fr -- fade out red LED");
Serial.println(" Fr -- fade in red LED to max brightness");
Serial.println();
Serial.println("Enter a command: ");
}

// Main program
void loop()
{
readSerialString(serInString, 100);
cmd = serInString[0];

// fade controls
if (cmd == 'f') {
//Serial.println("Fade out requested...");//test
tled = serInString[1];
fadeOut(tled);
}
else if (cmd == 'F') {
//Serial.println("Fade in requested...");//test
tled = serInString[1];
fadeIn(tled);
}
// brightness control: look for rgb chars, uppercase brightens and lowercase
// dims
else if (cmd == 'r' || cmd == 'R' || cmd == 'g' || cmd == 'G' || cmd == 'b' || cmd == 'B') {
Serial.println("Changing brightness...");//test
for(i=0; i < 100 && serInString[i] != '\0'; i++) {
//Serial.println("Looping over brightness commands...");//test
switch (serInString[i]) {
case 'r':
redVal -= inc;
break;
case 'R':
redVal += inc;
break;
case 'g':
greenVal -= inc;
break;
case 'G':
greenVal += inc;
break;
case 'b':
blueVal -= inc;
break;
case 'B':
blueVal += inc;
break;
}
}

trimValues();
writeAllValues();
}

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

// ensure brightness remains within 0-255 range
void trimValues() {
if (redVal > 255) {
redVal = 255;
}
else if (redVal < 0) {
redVal = 0;
}
if (greenVal > 255) {
greenVal = 255;
}
else if (greenVal < 0) {
greenVal = 0;
}
if (blueVal > 255) {
blueVal = 255;
}
else if (blueVal < 0) {
blueVal = 0;
}
}

// write all brightness values to the pins
void writeAllValues() {
//Serial.println("Writing values...");//test
analogWrite(redPin, redVal);
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
}

// fade in LED in by pin number
void fadeIn(int pin) {
Serial.print("Fading in pin ");
Serial.print(pin);
Serial.println("...");
switch (pin) {
case 9:
while (redVal < 255) {
redVal += 1;
analogWrite(pin, redVal);
delay(wait);
}
break;
case 10:
while (greenVal < 255) {
greenVal += 1;
analogWrite(pin, greenVal);
delay(wait);
}
break;
case 11:
while (blueVal < 255) {
blueVal += 1;
analogWrite(pin, blueVal);
delay(wait);
}
break;
}
}

// fade in LED in by color
void fadeIn(char colorCode) {
Serial.print("Fading in ");
Serial.print(colorCode);
Serial.println(" pin...");
switch (colorCode) {
case 'r':
fadeIn(redPin);
break;
case 'g':
fadeIn(greenPin);
break;
case 'b':
fadeIn(bluePin);
break;
}
}

// fade out LED in by pin number
void fadeOut(int pin) {
Serial.print("Fading out pin ");
Serial.print(pin);
Serial.println("...");
switch (pin) {
case 9:
while (redVal > 0) {
redVal -= 1;
analogWrite(pin, redVal);
delay(wait);
}
break;
case 10:
while (greenVal > 0) {
greenVal -= 1;
analogWrite(pin, greenVal);
delay(wait);
}
break;
case 11:
while (blueVal > 0) {
blueVal -= 1;
analogWrite(pin, blueVal);
delay(wait);
}
break;
}
}

// fade out LED in by color
void fadeOut(char colorCode) {
switch (colorCode) {
case 'r':
fadeOut(9);
break;
case 'g':
fadeOut(10);
break;
case 'b':
fadeOut(11);
break;
}
}

// full input arr with null values
void resetSerialString (char *strArray, int length) {
for (int i = 0; i < length; i++) {
strArray[i] = '\0';
}
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray, int maxLength) {
int i = 0;

if(!Serial.available()) {
return;
}
while (Serial.available() && i < maxLength) {
strArray[i] = Serial.read();
i++;
}
}

Fiber Arts and VR

Creativity can come from different experiences, both tangible and imaginable, but I believe that how one physically interacts with the world greatly shapes how one imagines the world in their mind. One needs the experience of touching and interacting with physical objects in order to shape what can be imagined. McCullogh stated in “Hands” that “learning through the hands shapes creativity itself” and I feel this to be true.

In my experience working with fiber arts, I know each type of fiber to be different. Even when I feel like I know the material, each type of fiber still brings its own character to the piece to shape it – something that my mind could never predict until I physically interact with the fiber. My hands are guiding my mind through the experience, and shaping what is physically possible for my art (for example, thick wool with a tight knit yielding more of a structure than a stockinette with a more elastic yarn).

I feel the same is true with the latest advancements in Virtual Reality, where we try to capture different textures and physical experiences in the virtual space. I recently watched a Paper Fashion artist design a virtual reality dress (Video Demo Link, ~1:12:00), and it made me realize how fabric and fibers are more difficult to predict in both the physical and virtual world. As the artist created a dress in virtual reality with her hands, one could see her learning with each virtual textile she created with her hands. It was a new instantiation of “learning through the hands shapes creativity itself,” not the computer inherently being a tool for the mind. It was in this VR space that she was creating a new physical interaction through the computer to expand what is imaginable and capable for her art.

 

 

 

Lab 1 – Making Arduino LED light blink

Description:

For this lab, I used an Arduino to make a red LED light blink very fast (50 ms, or 0.05 seconds).

Tools:

  • 1 Arduino
  • 1 red LED
  • 1 resistor (220Ω)
  • 1 breadboard
  • 3 wires
  • 1 PC
  • USB – Arduino wire

Code:

void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for 0.05 second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for 0.05 second
}

 

Radio

Even with the popularity of streaming, my radio is one of my favorite possessions. When I wake up, it is the first thing I switch on. Instantly, I hear chatter of wacky morning DJ’s and new music without needing to look at a screen or open an app. If I want to change to one of my favorite broadcasts in the afternoon, I can adjust the knobs on the side without looking – only listening for a familiar voice. The simplicity of a switch and two knobs (and the occasional antenna adjustment) allows dozens of channels of information to come streaming in with barely any effort on my part to select a source or curate a playlist, and I am exposed to new and interesting topics and artists which influence my own behavior, an example of cultural determinism (Acting with Technology, p 39). When framing this experience in the view of activity theory (Vygotsky 1982a), I am the subject, the radio my tool, and my objective to learn about what is relevant in my local community. It is also more than just the tool, but how simple it is to operate.