Recitation 8: Serial Communication – By Skyler Liu

Exercise 1: Sketch

Diagram:

Video:

Code: 

Processing:

import processing.serial.*;

String myString = null;
Serial myPort;

int NUM_OF_VALUES = 2;
int[] sensorValues;

void setup() {
size(500, 500);
background(0);
setupSerial();
}

void draw() {
updateSerial();
printArray(sensorValues);
fill(sensorValues[0], sensorValues[1], 20);
ellipse(sensorValues[0], sensorValues[1], 20, 20);
}

void setupSerial() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[ 1 ], 9600);

myPort.clear();
myString = myPort.readStringUntil( 10 );
myString = null;

sensorValues = new int[NUM_OF_VALUES];
}

void updateSerial() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil( 10 );
if (myString != null) {
String[] serialInArray = split(trim(myString), “,”);
if (serialInArray.length == NUM_OF_VALUES) {
for (int i=0; i<serialInArray.length; i++) {
sensorValues[i] = int(serialInArray[i]);
}
}
}
}
}

Arduino:

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A0)/ 4;
int sensorValue2 = analogRead(A1)/ 4;

Serial.print(sensorValue);
Serial.println(“,”);
Serial.print(sensorValue2);
Serial.println();

delay(10);
}

Process: I started this exercise from the circuit. At first, I kind of forgot which legs of the potentiometers should be connected with which pin on the Arduino, so I sought help from my deskmate and soon solved this question. Then I began to work on the code part based on the sample code. It was not hard to find out which parts in the sample code should be modified into the required function, such as the port number and the value number. I also add the variation of colors following the value variation from potentiometers. The effect was pretty. 

Exercise 2: Music Instrument

Diagram:

Video:

Code:

Arduino:

#define NUM_OF_VALUES 2

int tempValue = 0;
int valueIndex = 0;
int values[NUM_OF_VALUES];

void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);
}

void loop() {
getSerialData();
tone(9,values[0],values[1]);
}

void getSerialData() {
if (Serial.available()) {
char c = Serial.read();

switch (c) {
case ‘0’…’9′:
tempValue = tempValue * 10 + c – ‘0’;
break;
case ‘,’:
tempValue = 0;
valueIndex++;
break;
case ‘n’:
values[valueIndex] = tempValue;
tempValue = 0;
valueIndex = 0;
break;
case ‘e’:
for (int i = 0; i < NUM_OF_VALUES; i++) {
Serial.print(values[i]);
if (i < NUM_OF_VALUES – 1) {
Serial.print(‘,’);
}
else {
Serial.println();
}
}
break;
}
}
}

Processing:

import processing.serial.*;

int NUM_OF_VALUES = 2;

Serial myPort;
String myString;

int values[] = new int[NUM_OF_VALUES];

void setup() {
size(500, 500);
background(0);

printArray(Serial.list());
myPort = new Serial(this, Serial.list()[ 1 ], 9600);

myPort.clear();
myString = myPort.readStringUntil( 10 );
myString = null;
}

void draw() {
background(0);
for (int i=0; i<values.length; i++) {
values[0] = mouseX;
values[1] = mouseY;
}

sendSerialData();
echoSerialData(200);
}

void sendSerialData() {
String data = “”;
for (int i=0; i<values.length; i++) {
data += values[i];
if (i < values.length-1) {
data += “,”;
}
else {
data += “n”;
}
}
myPort.write(data);
}

void echoSerialData(int frequency) {
if (frameCount % frequency == 0) myPort.write(‘e’);

String incomingBytes = “”;
while (myPort.available() > 0) {
incomingBytes += char(myPort.read());
}
print( incomingBytes );
}

Process: Exercise two were made very smoothly after the experience of exercise 1. I found the parts in the sample codes which needed to be rewritten very fast and changed them to fit the requirement. And my first try succeeded. 

Final Project Proposal – By Skyler Liu

Project Title

Beduffled Snake 

Project Statement of Purpose

During my research, I have been influenced a lot by the project Anti-Drawing Machine, which allows either a disrupted or collaborative drawing by manipulating the rotation and position of an ordinary paper material. Its purpose is to explore the possible alternatives of how we engage with intelligent device today – instead of purely utilitarian and precise. Inspired by this idea, I want to design a unique snake game which avoids players using the inertial thinking method while playing. Snake is a classic game and remains many memories in our childhood, but it is losing voice in modern game development. It used to be popular because of its simple operation; it’s easy to be used by people who first touch digital games, but it is also the simple gaming style making it look less interesting to us now among numerous new challenging games. Thus, I want to help it by redesigning its gaming method for it.  It will challenge people’s general sense of control when playing games and requires one hundred percent of concentration and flexible thinking process. It is a game designed for everyone who wants to train their ability of mobile brain coordination and wants to gain a sense of achievement by challenging themselves. Differing from the traditional gaming method, this project intends to explore more alternatives of how players can get joy from games by challenging their inertial thinking about the game’s playing method. 

Project Plan

This project will be an interactive game built on both Processing and Arduino. The goal is to eat as many apples as possible while keeping the snake survive. 

Arduino will be connected with joysticks, in charge of the snake’s moving direction. And Processing will be used to display the interface of the game and code the game’s rules. 

The gaming method would include the length and speed change of the snake after eating the apple, and death punishment when the snake touches the frame or itself like a traditional snake game. But the direction control keys would all be the opposite to the normal setting. Every 20 seconds the direction keys would transfer to the normal style for 10 seconds. There would be both sound notification and visible count-down shown in the game interface before 5 seconds of the transformation. I also plan to add occasional events that would be triggered to switch the position of apple which hasn’t been eaten in the game. In addition, there will be a multiple-player gaming style. In this function, besides all the rules in the single-player style, the player would also lose the game if he/she hits one another. I will also make special design of the snake’s appearance and background animation, maybe even include some narrative plots for the game.

In the next three weeks, I am going to complete these tasks:

In the first week, I will complete the circuit and the basic code of the game in Processing.

The second week, combine Arduino and Processing together and further consummate the code.

Last week, user test; make final modifications.

Context and Significance

In my previous research and analysis, I defined interaction as the process of a device receiving signals from at least one other subjects, then going through intelligent thinking, finally reacting to the signals. In this way, my project which runs code with both Arduino and Processing as the response to joystick movements and involves at least one player certainly aligns with my definition of interaction. The uniqueness of it is that it challenges people’s sense of control while playing a game and challenges players’ inertial thinking style. And designing new gaming method for a classical work is also a kind of meaningful exploration. The new playing method I design for my project can lead people to think about what the meaning of a game and its gaming method should be, and if less strength of control in an interactive game certainly means a less interesting work.

Recitation 7: Processing Animation – Skyler Liu

Video:

Code:

boolean play;
int x, y;
int size = 50;
int speedX, speedY ;

void setup() {
play = true;
size(600, 600);
background(0);
fill(58,90,150);
speedX = int(random(10,20));
speedY = int(random(5,10));
rectMode(CENTER);
}

void draw() {
if (play) {
background(0);
if (mousePressed == true) {
}
ellipse(x,y,size,size);
x = x + speedX;
y = y + speedY;
ballBounce();
}
}
void mousePressed() {
int r = int(random(0, 255));
int g = int(random(0, 255));
int b = int(random(0, 255));

fill (r, g, b);
noStroke();

ellipse(x,y,size,size);
}
void ballBounce(){
if ((x > width) || (x < 0)){
speedX *= -1;
}

if ((y >height)||(y<0)){
speedY *= -1;
}
}

void keyPressed() {
play = !play;
}

Process:

I used the code of a bouncing ball which we learned in the last course as the basis of my work. And I added two more functions to it: every time when you press the mouse, the ball would change to a random color; and when you press a random key, the ball’s moving would be paused until next key press. 

I wanted to achieve an idea that when you pause the ball and press the key at that time, a new ball with random color would appear, and when you press next key to restart the ball’s moving, the new ball would be reserved and move with the original one together; in this way, there can be more and more balls on the screen through pause and mouse press. But due to the lack of my knowledge about coding and the time limit in the class, I did not complete this idea. I will continue to work on it in my free time.

Preparatory Research and Analysis – by Skyler Liu

A. Definition Evolvement 

During our group project before, I defined interaction as the process of a device receiving signals from other subjects, then going through an intelligent thinking process, finally reacting to the signals; and I considered it as a conversation between two subjects, including the exchange of information.

However, after working on my midterm project and learning about Processing, I realize there were limitations in my definition of interaction. In the previous definition, I stated that interaction is a conversation between only “two subjects”. During the midterm project, we made an instrument that can respond to the player’s hand movements – there can be one player only, but of course, can also be two players together to combine their melodies. I also experienced many other groups’ projects which involve multiple users to interact with both other users and the device, such as the laser aiming game I saw in the user test, which contained competition between two users through the device; and the princess rescue game, which constructed a story about four players and the “prince” and “dragon” set in the device. All these experiences about my midterm project inspire me that interaction could be a conversation involves multiple subjects instead of limited in two. Moreover, I didn’t mention the purpose of interaction in my previous definition. Through the midterm project and the learning process of Processing, I think I could evolve this part in my definition. The midterm project has taught me that interaction can not only be achieved in a useful device but also can be used for an artistic or recreational device. And during learning Processing, we created several programs that could work out random outcomes without certain purposes of usage, artistry or entertainment. But the results showed us many impressive possibilities for creation. Thus, I think the definition of interaction should also include its purposes which are to output either useful, artistic, recreational, or exploratory product.

B. Project Research

One project that aligns with my definition is Anti-Drawing Machine. As in its description, the device “allows either a disrupted or collaborative drawing by manipulating the rotation and position of an ordinary paper material”. People can either try to insist on their drawing direction or let the machine lead their drawing; there can also be multiple users drawing their picture together on the same piece of paper. The machine often makes users feel funny when it disrupting or collaborating out of the users’ expectation, and the users may get surprised by the unpredictable and unique work at last. It involves amazing interaction because through the “conversation” with users, it can either output a surprising artistic work or bring brightness to the users, or both.

In addition, the project Bit does not align with my definition. This project presents “a natural random process” based on the principle of a Markov chain. It contains four machines and each one consists of special “information” engraved on its arm as input and “event” which is a move caused by the motor as output. And each event would trigger a corresponding piece of “information” on another machine, then make the machine have a move as next “event”. Though the rule of how four machines move one by one is interesting and it may have a kind of initial interaction among four machines, this project does not take an external input and the experiencers’ possible interaction with it is very limited – it seems that what the audience can do is only predicting which of the machines will move next. Thus, there cannot be an interactive conversation between multiple users and the project,  as the device does not accept signals from the external world.

Bit
Principle of Bit

C. “New” Definition

Though Crowford, Igoe, and many other authors almost all give a three-part definition to “interaction” which emphasize its function, I think there are also other elements worth mentioning in the definition, such as its participants and purpose. Based on all the above experiences and projects, I want to redefine interaction as the process of a device receiving signals from at least one other subjects, then going through intelligent thinking, finally reacting to the signals; it is a conversation between two subjects or more, for achieving an either useful, artistic, recreational or exploratory work. In my opinion, usage, art, entertainment, and exploration are four dimensions crucial to our human civilization, and the designers always try to create meanings for humans by achieving values in the four dimensions, including in the way of interaction. Therefore, from my perspective, “interaction” should always be a human-centered concept, no matter regarding its participants or its purposes.

Recitation 6: Processing Basics – Skyler Liu

Three Sounds by Vasily Kandinsky

I chose Vasily Kandinsky’s Three Sounds as the motif because it first caught my eyes among so many sample images.  It gave me a sense of Cyberpunk and mystery, attracting me with its beauty. When I decided to choose it, I knew it would be a complicated work with so many components in it, but I still made my decision without much hesitation because I thought there was nothing in the picture could not be achieved as if I took longer energy and sought for help when necessary. 

Three Sounds by Skyler

As you can see, what I wanted to create in Processing is a replication of Vasily Kandinsky’s painting (due to the time limit and the complexity of the picture, I only completed 30% in class). The first challenge to me was that there were too many components with so many different vertexes. In the beginning, I only estimated the coordinates by my feeling. So at many times the position or shape of the components was not accurate, differing much from the original motif I chose. Luckily, when Leon saw me doing this work, he came to me and told me that he also did this before. And he taught me a little trick: upload the picture with the pixel size you plan to create to Illustrator, then open the information window, there will be small window recording every pixel coordinates where your mouse arrow points at. With this method, I got the coordinates I needed much faster and more accurate; each component I replicated in my work was almost exactly the same position and size with the original image. The second challenge was the color choice. I felt that I could not set the exact colors which were used in the original work no matter how I tried; there was always little difference. And even if I set the transparency in my work, I could not imitate somewhere in the original work having a sense of dizzy dye and very natural color transition. I think it is because of the pigment artist used in the real world has more uncontrollable imperceptible disequilibrium and sometimes the artist can also create a sense of color transition freely by himself, which would be hard to achieve by the digital drawing method like Processing.

I think Processing might not be able to replicate full spiritual works of art as artists created by their hands – even we could replicate the shapes, the spirit in the existing artwork would be hard to express in our digital work. But I think it can certainly help us to explore the artwork and understand it. We can realize why the artist chose each position or size of each patterning – understand more about the patternings’ relative positions by coding their coordinates; we can also understand more about the artful color choices made by the artist during our search for similar colors in Processing – sometimes the wrong tries would destroy the concordance of image even if they were similar to the original colors.

Code of my work:

size(500, 500);
background(26, 30, 57);
fill(171,213,214,240); //big blue
stroke(0, 0, 0);
strokeWeight(0.3);
beginShape(); //blue hexagon
vertex(124, 42);
vertex(42, 130);
vertex(86, 472);
vertex(456, 360);
vertex(363, 110);
vertex(293, 52);
endShape(CLOSE);
fill(31,31,31,250); //black line
rect(94, 363, 304,5);
fill(255,20,8,180); // red triangle
triangle(271,212,182,291,285,341);
fill(38,25,180,180); //blue tree
triangle(272,350,255,363,288,363);
triangle(272,326,260,350,284,350);
triangle(272,306,264,326,280,326);
triangle(272,280,265,306,279,306);
fill(254,255,0,150); //yellow triangle
triangle(294,161,211,218,255,264);
fill(33,121,50,220); //green tree
triangle(311,350,288,363,334,363);
fill(54,90,61,255);
triangle(311,326,294,350,328,350);
fill(70,129,107,255);
triangle(311,306,294,326,328,326);
fill(69,126,116,255);
triangle(311,293,298,306,324,306);
fill(45,134,129,255);
triangle(311,276,302,293,320,293);