Arduino code const int led=13; void setup() { pinMode(led,OUTPUT); Serial.begin(9600); } void loop() { if(Serial.available()){ char c=Serial.read(); if(c=='H'){ digitalWrite(led,HIGH); } if(c=='L'){ digitalWrite(led,LOW); } } }
Processing code
import processing.serial.*; Serial myPort; void setup() { String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); size(1000, 1000); background(255,255,255); fill(255,255,255); rectMode(CENTER); rect(500,600,500,650); fill(240,233,22); triangle(500,65,850,275,150,275); strokeWeight(10); line(500,275,500,425); fill(12,43,165); triangle(500,425,400,525,600,525); PFont myfont=createFont("宋体",50); textFont(myfont); textSize(48); text("Eva's home",350,200); fill(255,255,255); rect(350,400,100,100); fill(237,230,86); text("on",300,420); fill(255,255,255); rect(650,400,100,100); fill(237,230,86); text("off",610,420); } void draw() { if((mouseX>=300)&(mouseX<=400)&(mouseY>=350)&(mouseY<=450)&mousePressed&(mouseButton==LEFT)){ fill(230,233,22); ellipse(500,600,150,150); println("led turn on"); myPort.write("H"); } else if((mouseX>=600)&(mouseX<=700)&(mouseY>=350)&(mouseY<=450)&mousePressed&(mouseButton==LEFT)){ fill(0,0,0); ellipse(500,600,150,150); println("led turn off"); myPort.write("L"); } else{ println("no data"); } }
Documentation
Q1:Document your work on your blog, detail how your process of building the circuits and writing the code went. Any success? Any failures? What did you learn?
I want to use Processing to realize the effect of turning on and off the light, which reminds me of today’s smart home. People can control the lights in the room and so on. In the Arduino part, I quickly completed the effect of lighting up the LED. But in Processing, it took a little bit of calculation to design the part of the house. I ended up connecting the two, and I failed several times. I learned how to step by step check if my code is correct and successfully connect!
Q2: Use this week’s reading, Computer Vision for Artist and Designers, as inspiration to write a reflection about the ways in which technology was used in your recitation project.
I love Myron Krueger’s Video place, whose concept is that the camera needs to capture the surrounding colors and then send a signal to a light fixture connected to the Arduino. I think this week’s technology makes the connection between Processing and Arduino excellent. I also hope to add some sensors that can correspond well to my project. For example, a response is made in Processing when a hand is waved.