Documentation
Task #1 Documentation
- Document your process for completing the task: (what went well? what was difficult? any surprises?).
Programing the first step was fairly simple as I just used the example codes given. The second step I ran into some difficulties. The first time I ran the code, the circle was the one that tracing over the background with a line in the center of the screen. I realized that I didn’t change all the variables for the example line code and I had to change the code from being controlled with the mouse. After I changed those variables, the code ran smoothly and processing looked like an etch-e-sketch. The way people would interact with this would be by spinning the two potentiometers to draw on the screen. After the person spins, the line moves in the x and y direction according to the amount of “spin” is used.
Arduino code:
#include “SerialRecord.h”
// Change this number to send a different number of values
SerialRecord writer(2);
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
writer[0] = map(sensorValue2,0, 1023, 0, 500);
writer[1] = map(sensorValue1, 0, 1023, 0, 500);
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);
}
Processing Code:
import processing.serial.*;
import osteele.processing.SerialRecord.*;
Serial serialPort;
SerialRecord serialRecord;
float pvalue1;
float pvalue2;
void setup() {
size(500, 500);
background(0);
String serialPortName = SerialUtils.findArduinoPort();
serialPort = new Serial(this, serialPortName, 9600);
// If the Arduino sketch sends a different number of values, modify the number
// `2` on the next line to match the number of values that it sends.
serialRecord = new SerialRecord(this, serialPort, 2);
}
void draw() {
serialRecord.read();
int value1 = serialRecord.values[0];
int value2 = serialRecord.values[1];
stroke(255);
line(value1, value2, pvalue1, pvalue2);
pvalue1 = value1;
pvalue2 = value2;
}
Task #2 Documentation
Document the process for completing the task: (what went well? what was difficult? any surprises? what was your process of teamwork?).
When I first attempted to program this, I could not figure out how to get the servo to work. When the circle hit the opposite side, the servo wouldn’t move. I then realized that there was an example code in the library that helped me make the servo work. Another problem I faced was that when the circle hit the left side, the servo moved 90 degrees, but on the right the servo didn’t tick as far. I realized that with my parameters, the servo didn’t have time to turn all the way 90. So I changed those as well and everything started to work. I don’t think I could call this part “interactive” because only the servo is responding to the code. And one could argue since, the code makes up both parts, the whole mechanism is only responding to itself. I think this contradicts my perception of interaction as it doesn’t create a conversation between two separate bodies.
Arduino:
#include “SerialRecord.h”
#include
Servo myservo;
// Change this number to the number of values you want to receive
SerialRecord reader(1);
void setup() {
Serial.begin(9600);
myservo.attach(4); // attaches the servo on pin 4 to the servo object
}
void loop() {
reader.read();
if (reader[0] > 1425 || reader[0] < 20) { //when it hits the boundary
myservo.write(90); //move to 90
} else {
myservo.write(0); //in middle it returns to zero
}
// myservo.write(val);
}
Processing:
import processing.serial.*;
import osteele.processing.SerialRecord.*;
float x = 40;
int d = 3;
Serial serialPort;
SerialRecord serialRecord;
void setup() {
fullScreen();
String serialPortName = SerialUtils.findArduinoPort();
serialPort = new Serial(this, serialPortName, 9600);
// In order to send a different number of values, modify the number `2` on the
// next line to the number values to send. In this case, the corresponding
// number in the Arduino sketch should be modified as well.
serialRecord = new SerialRecord(this, serialPort, 1);
}
void draw() {
background(0);
circle(x, height/2, 20);
x += d;
if (x>width – 10 || x < 10){
d = -d;
}
// store some values in serialTransport.values, and send them to the Arduino
serialRecord.values[0] = int(x);
//serialRecord.values[1] = int(map(mouseY, 0, height – 1, 0, 1023));
serialRecord.send();
}
Leave a Reply