#Task 1
In this task, I created an interesting bug. The /*…*/ part in the code will lead to a “shivering” problem. Iris, Amber, and I work a really long time together to find out which part had a problem. Until professor Rudi came and told me why: In the original code the sensorvalue is already printed, so if I wrote println, the serial monitor will read the number twice and cause the bug. This is an unforgettable lesson: don’t gild the lily when you’re coding! (Besides this, everything went well><)
My final “painting”⬇️
#include "SerialRecord.h" // Change this number to send a different number of values SerialRecord writer(2); void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); int sensorValue2 = analogRead(A1); writer[0] = sensorValue; writer[1] = sensorValue2; /*Serial.println("left"); Serial.println(sensorValue); Serial.println("right"); Serial.println(sensorValue2);*/ writer.send(); // This delay slows down the loop, so that it runs less frequently. This can // make it easier to debug the sketch, because new values are printed at a // slower rate. delay(10); }
The interaction is using your hands to draw on a computer screen, crossing the real world and the digital world. Unlike all other ways of drawing, such painting is uncertain. You need some practice to see how your action will lead to a result, this is the most attractive part to me — and this will lead to the user’s constant exploration, which aligns with my interactive principle.
#Task 2
For task 2, I worked together with Amber again. As we used servo in our midterm project before, we are relatively familiar with the code for servo. After adjusting the angles for several times, we successfully realized the goal. (Sadly, we didn’t have time to use the full screen function).
I don’t think this project includes much interaction element, but watching it bouncing back and forth is still interesting.
The code for processing⬇️
import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; float x = 0; float spd=10; void setup() { size(600, 600); //background(176,131,250); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 2); //serialRecord.logToCanvas(false); } void draw() { background(176,131,250); circle(x,height/2,20); x+=spd; int move = int (map(x,0,width,0,width)); if (x>=width){ spd= -spd; } if (x<=0){ spd= -spd; } serialRecord.values[0] = move; serialRecord.send(); }
The code for Arduino⬇️
#include "SerialRecord.h" #include <Servo.h> // Change this number to the number of values you want to receive SerialRecord reader(1); Servo servo1; Servo servo2; void setup() { Serial.begin(9600); servo1.attach(9); servo2.attach(10); pinMode(9, OUTPUT); pinMode(10,OUTPUT); } void loop() { reader.read(); servo1.write(50); if (reader[0]>580){ servo1.write(180); }; servo2.write(180); if (reader[0]<10){ servo2.write(90); }; }