system
13
int signal1 = 1;
int signal0 = 0;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
byte check;
if (Serial.available()>0) {
check = Serial.read();
if(check == 1) {
digitalWrite(13, HIGH);
delay(3000);
Serial.write(signal1);
} else {
digitalWrite(13, LOW);
Serial.write(signal0);
}
}
}
import processing.opengl.*;
import processing.serial.*;
Serial myPort;
int signal;
Mover[] mover;
int nummover = 7;
int sta;
void setup() {
frameRate(30);
size(1000,1000,OPENGL);
smooth();
background(0);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
mover = new Mover[nummover];
for(int i=0; i<nummover; i++) {
mover[i]=new Mover();
}
}
void draw() {
noStroke();
background(255);
for (int i=0; i<nummover; i++) {
mover[i].update();
mover[i].checkedge();
mover[i].display();
}
if(mover[0].putAhold == true) {
sta = 1;
}
else {
sta = 3;
}
myPort.write(sta);
println(sta);
}
void serialEvent(Serial myPort) {
signal = myPort.read();
// println(signal);
if(signal == 1) {
for (int i=0; i<nummover; i++) {
mover[i].putAhold = false;
}
}
}
class Mover {
PVector[] location;
PVector velocity;
PVector acc;
float theta=random(360);
float ra=6;
float co=20;
int tail = 250;
boolean putAhold = false;
Mover () {
location = new PVector[tail];
for (int i=0; i<tail; i++) {
location[i] = new PVector(0,height/2);
}
velocity = new PVector(0,0);
}
void update() {
acc = new PVector(ra,cos(radians(theta))*ra);
acc.normalize();
velocity.add(acc);
if(putAhold == true) {
velocity.limit(0);
}
if(putAhold == false) {
velocity.limit(6);
}
for(int i=tail-2; i>=0; i--) {
location[i+1].x = location[i].x;
location[i+1].y = location[i].y;
location[i].add(velocity);
}
theta += 5;
}
void checkedge() {
for(int i=tail-2; i>=0; i--) {
if (location[i].x>width) {
location[i].x=0;
putAhold = true;
}
}
}
void display() {
for(int i=tail-2; i>=0; i--) {
strokeWeight(5);
stroke(0,(100-i*1));
if(location[i+1].x - location[i].x < 2) {
line(location[i].x, location[i].y, location[i+1].x, location[i+1].y);
}
}
}
}