Recitatioin 8–Tao Wen

Exercise one:

Regarding coding, there’s one aspect to notice: the map function. Otherwise, the circle will go out of the frame.

Exercise one- Etch A Sketch:

The difference between this and the last step is that this one uses “line” function. I tried to use tiny little ellipse to consist a line, but the fact is that not the whole trajectory would be shown on canvas. And when using line, it’s not enough just to connect(x1,y1) and (x2,y2), otherwise nothing would be drawn.  You have to use the previous coordinate, just like what we do with pmouseX and pmouseY.

Concerning the interaction experience, I don’t like it at all, probably because I’m not used to drawing by thinking about its horizontal and vertical coordiantes. However, I think it’s a useful way of algorithmic thinking when designing drawing-related projects.

Code that matters(Arduino):

void setup() {
  Serial.begin(9600);
}
 
void loop() {
  int sensor1 = analogRead(A0);
  int sensor2 = analogRead(A1);
  int mapped1= map(sensor1,0,1023,0,500);
   int mapped2= map(sensor2,0,1023,0,500);
  Serial.print(mapped1);
  Serial.print(“,”);
  Serial.print(mapped2);
  Serial.println();
}

Code that matters(Processing):

void draw() {
  updateSerial();
  printArray(sensorValues);
 
println ("sensor1=",sensorValues[0]);
println ("sensor2=",sensorValues[1]);

line(p1,p2,sensorValues[0],sensorValues[1]);
p1=sensorValues[0];
p2=sensorValues[1];
}

Exercise two:

The idea is to create a piano key board, which requires two variables: the on-and-off option and the tone, corresponded by mouse press and mouseX. Since I wasn’t familiar with coding, the interaction experience is not ideal. The five sounds, put together, are so disturbing to play. I would like to expand on this idea: the user can choose a music style (e.g Japanese, Chinese pentatonic, Arabian), the tone of keys will switch accordingly, and then the user (ideally amateurs) can explore and create their own melodies.

Code that matters(Processing)

void draw() {
background(0);
values[0] = pmouseX;
if (mousePressed){
values[1]=1;
}else{
values[1]=0;
}
printArray(values);
sendSerialData();
echoSerialData(200);
}

Code that matters (Arduino):

int melody[] = {
  262, 349, 196, 440, 4186, 2093, 3136, 175
};
int freq;
 
void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}
 
void loop() {
  getSerialData();
 
freq= melody[int(map(values[0],0,500,0,8))];
if (values[1] == 1) {
    tone(13, freq);
  } else {
    noTone(13);
  }
}

Leave a Reply