Sonntag, 8. November 2009

test drive speed by photocell





//-----drive speed by photocell -----//

import cc.arduino.*;
import processing.serial.*;

Arduino myArduino;

float value;
int count=0;
float multi;
float x=(random (0,600));
float y=(random (0,600));
float xspeed=1;
float yspeed=1;
float vx = 0;
float vy = 0;
float swx,swy;

void setup() {
colorMode(HSB,100);
size(600,600);
myArduino = new Arduino(this, Arduino.list()[1], 57600);
background(0);
smooth();
count=0;
}

void draw(){
move();
border();
fill(0,0,0,0);
noStroke();
rect(0,0,width,height);
value=5*(myArduino.analogRead(0));
stroke(value,100,100,50);
strokeWeight(10/5);
noFill();
ellipse(x,y,value*2,value*2);

if ( (count% 100 >= 5) && (count% 100 <= 50) ) {
myArduino.digitalWrite(13, myArduino.HIGH);
}
else{
myArduino.digitalWrite(13, myArduino.LOW);
}
if (count==100) xspeed= (random(-1,1));
if (count==100) yspeed= (random(-1,1));
if (count==100) count=0;
count++;
saveFrame("anim/circles-####.png");
}

void move() {
vx = xspeed;
vy = yspeed;
multi=(5-(value*0.03));
x += vx*multi;
y += vy*multi;

}

void border() {
float radius= (value*2)*0.0;
if (x < -radius) x = width+radius;
if (y < -radius) y = height+radius;
if (x > width+radius) x = -radius;
if (y > height+radius) y = -radius;
}

Samstag, 7. November 2009

blingblingsensor

//test with two photocells and a led
/*
the photocells are connected to analog 0 and 1;
and the led is connected to dgital port 13;
*/

import cc.arduino.*;
import processing.serial.*;

Arduino myArduino;

float value,valueb;
int count;
float x,y,dirx,diry,vorx,vory;


void setup() {
size(600,600);
myArduino = new Arduino(this, Arduino.list()[1], 57600);
background(100);
smooth();
count=0;
}

void draw(){
borders();
fill(100,80);
noStroke();
rect(0,0,width,height);
value=5*(myArduino.analogRead(0));
valueb=5*(myArduino.analogRead(1));
stroke(value,50,50);
strokeWeight(value/5);
noFill();
ellipse(mouseX,mouseY,value,value);
stroke(value-50,80,80);
noFill();
strokeWeight(valueb/5);

x=x+1;
y=y+1;

ellipse(mouseX,mouseY,valueb,valueb);

if ( (count% 100 >= 5) && (count% 100 <= 50) ) {
myArduino.digitalWrite(13, myArduino.HIGH);
}
else{
myArduino.digitalWrite(13, myArduino.LOW);
}

count++;
//saveFrame("anim/circles-####.png");
}

void borders() {
if (x < 0) x = 0;
if (y < 0) y = 0;
if (x > width) x = 0;
if (y > height) y = 0;

}