ALLEN ZHOU / PRODUCT DESIGN WORK
Week 5 Processing Introduction
Task 1 Make a basic processing code after watching the tutorials. I use 3d transform to build a small figure which can change its color and shape with the movement & click of the mouse.
Here is the code I wrote.
void setup()
{
size(500,400,P3D);
}
void draw()
{
int Z = mouseX/2 + mouseY/2;
int i;
background(0,138,120);
stroke(255);
fill(Z,mouseY, mouseX);
ellipse(mouseX,mouseY-150,100,100);
stroke(255);
fill(mouseX,mouseY,Z);
rect(mouseX-50,mouseY-100,100,200);
if(mousePressed)
{
for(i=0;i<300;i++)
{
translate(-i,i,-mouseY);
rect(mouseX-50,mouseY-100,100,200);
}
}
}
Here is the short video I filmed after I finished the code:
Task 2 Use photocell to control the led. In this task, I'm gonna use a photocell to control the brighness of the led. The photocell can etect the light brightness of the environment and then thansfer the light strength to the resistor of the sensor. I use the function analogRead() to get the range of number detected by the photocell(from 0 to 1023). And if the brightness(minLight in my code) is smaller than a certain amount(for example, 500 in my code), the led will be turned on(HIGH), else, the led will be turned off(LOW).
Here is the code I wrote.
int photocellPin = 2;
int photocellVal = 0; // photocell variable
int minLight = 500;
int ledPin = 9;
int ledState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
photocellVal = analogRead(photocellPin);
Serial.println(photocellVal);
if (photocellVal < minLight && ledState == 0) {
digitalWrite(ledPin, HIGH); // turn on LED
ledState = 1;
}
if (photocellVal > minLight && ledState == 1) {
digitalWrite(ledPin, LOW); // turn off LED
ledState = 0;
}
delay(100);
}
Here is the short video I filmed after I finished the code:
Task3-Dim-ON&OFF
Task4-Dim-Blinking Speed
Task5-Dim-Pushswitch