Physical Computing Code for Arduino - Exercise 2.1
/*Brenner Pacelli de Castro
Lab #3
DIGF 2B03 Physical Computing
March 23rd 2014
Simple code to rotate a Servo motor attached to a string holding a ball based on the position a circle in Processing
*/
#include <Servo.h>
Servo motor;
void setup() {
Serial.begin(9600);
motor.attach(9);
}
void loop()
{
byte getRotation;
if (Serial.available()) {
getRotation = Serial.read();
motor.write(getRotation);
}
}
/*Brenner Pacelli de Castro
Lab #3
DIGF 2B03 Physical Computing
March 23rd 2014
Simple code to move a circle bouncing from right to left and send its position to the serial.
*/
import processing.serial.*;
Serial port;
float position, tax;
void setup() {
ellipseMode(CENTER);
size(180, 10);
println("Available serial ports:");
println(Serial.list());
port = new Serial(this, Serial.list()[9], 9600);
tax = 10/frameRate;
rotation = 0;
}
void draw() {
stroke(1);
fill(255);
rect(0, 0, width, height);
fill(0);
ellipse(position, height/2, height - 2, height - 2);
if (position > 180 || position < 0)
tax = -tax;
rotation += tax;
port.write(int(rotation));
}