|
Intro to Physical Computing Syllabus Research & Learning Other Class pages
ITP Help Pages |
Dano F2011-1
Contact:Class List :
WEEK1 FINAL PROJECT PROPS
WEEK2 FINAL PROJECT PROPS
Notes from Class
void setup(){ pinMode(7,OUTPUT); pinMode(6,INPUT); } void loop(){ if(digitalRead(6) == true && digitalRead(5) == true){
digitalWrite(7,true);
delay(1000);
digitalWrite(7, false);
delay(1000);
}
}
void setup(){ Serial.begin(9600); } void loop(){ int litypoo = analogRead(A0);
Serial.println(litypoo);
litypoo = map(litypoo, 380, 760,0,255);
litypoo = max(litypoo,0);
litypoo = min(litypoo,255);
if (litypoo > 200){
digitalWrite(2,true);
}else if (litypoo > 150){
digitalWrite(3,true);
}
//litypoo = litypoo -450;
//litypoo = litypoo/2;
analogWrite(9,litypoo);
}
ARDUINO
Servo servoMotor; int input = 127; int lastTime; void setup(){ Serial.begin(9600);
servoMotor.attach(3); // attaches the servo on pin 2 to the servo object
Serial.print("Start");
} void loop(){ int photo = analogRead(A1);
Serial.write(photo);
input = Serial.read();
if (input != -1) {
servoMotor.write(input);
}
} PROCESSINGimport processing.serial.*; Serial myPort; int xpos; void setup() { println(Serial.list()); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); size(1800, 200); stroke(255); } void draw() { } void serialEvent(Serial _whichPort) { int input = _whichPort.read();
println(input);
stroke(0);
line(xpos, 0, xpos, height);
stroke(255);
line(xpos, input, xpos, height);
xpos++;
if (xpos > width) {
xpos = 0;
}
stroke(255, 0, 0);
line(0, height/4, width, height/4);
line(0, height/2, width, height/2);
int mousePos = int(map(mouseX, 0, width, 0,255));
myPort.write(mousePos);
}
Might be Last Arduino Code You Will Ever Writevoid setup(){ Serial.begin(9600); } void loop(){ int x = analogRead(A0);
Serial.print(x);
Serial.print(",");
int y = analogRead(A1);
Serial.print(y);
Serial.print(",");
int z = analogRead(A2);
Serial.print(z);
Serial.print(",");
Serial.print('\n');
}
Serial Event Function Processing for listening to itimport processing.serial.*; Serial port; // The serial port int xpos, ypos; // position of the ball void setup() { size(255, 255); // Stage size ellipseMode(CENTER); xpos = width/2; ypos = height/2; // Print a list of the serial ports, for debugging purposes to find out what your ports are called: println(Serial.list()); port = new Serial(this, Serial.list()[0], 9600); //you can pull the name out of the list } void draw() { fill(255,255,255); ellipse(xpos,ypos,10,10); } void serialEvent(Serial port) { String input = port.readStringUntil('\n'); // you can use '\n' or 10 make sure you print("\n") or write(10) at the end of your transmission in arduino
if (input != null){
print("Raw Input: " + input);
String[ ] parts = input.split(","); //this will only work if you put commas (Ascii 44) between things in your transmission
if (parts.length > 2){ //make sure it is a full valid message, might have joined conversation in the middle of message
int xtilt = int(parts[0]); //turn the "222" into 222
int h = int(parts[1]);
int l = int(parts[2]);
xpos = int( map(xtilt,400,600,0,width) ); //you were putting this off in arduino but you have to do it some time
heat = int( map(h,200,400,0,height) ); //these will be used in draw function so you have to declared outside of this function.
light = int( map(l,100,900,0,height) ); //these will be used in draw function so you have to declared outside of this function.
}
}
}
|