Part 1:
At the beginning, I can’t build circuits properly. And then I realized that I probably used a wrong element so that the processing can’t use the data which was received fro the Arduino. Then, I change the element to potential-meter and finally it works.
Video:IMG_1370
Arduino Code:
int potmeterPin = A0; int potmeterVal = 0; void setup(){ Serial.begin(9600); } void loop(){ potmeterVal = analogRead(potmeterPin); Serial.println(potmeterVal); delay(100); }
Processing Code:
import processing.serial.*; PImage photo; Serial mySerial; String myString = null; int nl = 10; float myVal; void setup(){ size(900,900); String myPort = Serial.list() [2]; mySerial = new Serial(this, myPort, 9600); photo = loadImage(“food.jpg”); } void draw(){ while (mySerial.available() >0) { myString = mySerial.readStringUntil(nl); if (myString != null){ background(255); myVal = float(myString); image(photo, 0, 0, myVal, myVal); } } }
Part2:
In this recitation, I learned how to use the processing to control the camera and then show on the screen. I think that the hardest part of this is the code. I finished it under the help of my friend who was study in interaction lab lats semester to help me fixed some tiny problems in my code.
import processing.video.*; String[] cameras = Capture.list(); Capture cam; float b, pb; import processing.sound.*; SinOsc sine; Env env; float attackTime = 0.001; float sustainTime = 0.004; float sustainLevel = 0.3; float releaseTime = 0.4; int s = 20; void setup() { size(640, 480); printArray(cameras); cam = new Capture(this, cameras[0]); cam.start(); sine = new SinOsc(this); env = new Env(this); //sine.play(); } void draw() { background(0); if (cam.available()) { cam.read(); } color c = cam.get(width/2, height/2); b = blue(c); float difference = abs(b-pb); for (int i=0; i<width; i = i + s) { for (int j=0; j<height; j = j + s) { float size = map(b, 0, 255, 5, 80); color all =cam.get(i, j); fill(all); noStroke(); rect(i, j, size, size); } } if (difference>10) { sine.play(); sine.freq(map(b, 0, 255, 100, 800)); env.play(sine, attackTime, sustainTime, sustainLevel, releaseTime); } pb=b; }
Video:Screen Recording 2022-05-20 at 10.35.17 AM