Skip to content

Instantly share code, notes, and snippets.

@tonussi
Last active December 17, 2015 00:48
Show Gist options
  • Save tonussi/5523350 to your computer and use it in GitHub Desktop.
Save tonussi/5523350 to your computer and use it in GitHub Desktop.
ap (arduino e processing) via serial
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
color cor = color(30, 90, 80, 40);
color cor2 = color(40, 60, 25, 80);
void setup() {
size(470, 280);
arduino = new Arduino(this, Arduino.list()[0], 9600);
arduino.pinMode(4, Arduino.INPUT);
smooth();
}
void draw() {
background(255);
if (arduino.digitalRead(4) == Arduino.HIGH) {
fill(cor);
noStroke();
rect(width/2 - 75, height/2 - 75, 150, 150);
println(arduino.digitalRead(2));
arduino.digitalWrite(8, Arduino.HIGH);
}
else {
fill(cor2);
noStroke();
rect(width/2 - 75, height/2 - 75, 150, 150);
println(arduino.digitalRead(2));
arduino.digitalWrite(8, Arduino.LOW);
}
noFill();
}
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
PShape pessoas[];
int svg, x, y, startTime, duration, quantidade, deslocation, zoom, ledPin = 13, sensorPIR = 4;
float position;
void setup() {
size(600, 600);
frameRate(15);
if (frame != null)
frame.setResizable(true);
// The file "bot.svg" must be in the data folder
// of the current sketch to load successfully
pessoas = new PShape[6];
for (int pessoa = 0; pessoa < pessoas.length; pessoa++) {
pessoas[pessoa] = loadShape("p" + pessoa + ".svg");
}
deslocation = width;
position = 1;
quantidade = 0;
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 9600);
arduino.pinMode(4, Arduino.INPUT);
arduino.pinMode(ledPin, Arduino.OUTPUT);
background(255);
}
void draw() {
background(255);
// if (arduino.digitalRead(sensorPIR) != 0)
//
//
// arduino.digitalWrite(ledPin, Arduino.HIGH);
// arduino.digitalWrite(ledPin, Arduino.LOW);
// float a = arduino.analogRead(0);
//if (arduino.digitalRead(sensorPIR, Arduino.HIGH) == 1)
switch (quantidade) {
case 0:
shape(pessoas[0], (x+=position)%deslocation + 0, y, width/3, height);
break;
case 1:
shape(pessoas[0], (x+=position)%deslocation + 0, y, width/3, height);
shape(pessoas[1], (x+=position)%deslocation + 100, y, width, height);
break;
case 2:
shape(pessoas[0], (x+=position)%deslocation + 0, y, width/3, height);
shape(pessoas[1], (x+=position)%deslocation + 100, y, width, height);
shape(pessoas[2], (x+=position)%deslocation + 200, y, width/3, height);
break;
case 3:
shape(pessoas[0], (x+=position)%deslocation + 0, y, width/3, height);
shape(pessoas[1], (x+=position)%deslocation + 100, y, width, height);
shape(pessoas[2], (x+=position)%deslocation + 200, y, width/3, height);
shape(pessoas[3], (x+=position)%deslocation + 300, y, width/3, height);
break;
case 4:
shape(pessoas[0], (x+=position)%deslocation + 0, y, width/3, height);
shape(pessoas[1], (x+=position)%deslocation + 100, y, width, height);
shape(pessoas[2], (x+=position)%deslocation + 200, y, width/3, height);
shape(pessoas[3], (x+=position)%deslocation + 300, y, width/3, height);
shape(pessoas[4], (x+=position)%deslocation + 400, y, width/3, height);
break;
case 5:
shape(pessoas[0], (x+=position)%deslocation + 100, y, width/3, height);
shape(pessoas[1], (x+=position)%deslocation + 200, y, width, height);
shape(pessoas[2], (x+=position)%deslocation + 300, y, width/3, height);
shape(pessoas[3], (x+=position)%deslocation + 400, y, width/3, height);
shape(pessoas[4], (x+=position)%deslocation + 500, y, width/3, height);
shape(pessoas[5], (x+=position)%deslocation + 0, y, width/3, height);
break;
default:
break;
}
if (arduino.digitalRead(4) == Arduino.HIGH) {
quantidade = (quantidade + 1) % pessoas.length;
}
else if (arduino.digitalRead(3) == Arduino.HIGH) {
quantidade = (quantidade - 1) % pessoas.length;
}
}
//void movePeople() {
// shape(pessoas[svg], (x+=position)%deslocation, y, width/5, height);
//}
//void mouseClicked() {
// svg = (svg + 1) % pessoas.length;
//}
//boolean sketchFullScreen() {
// return true;
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment