Commit fc0ff2bf authored by Nelso Jost's avatar Nelso Jost

ADD: importado sample de processing em https://bitbucket.org/gestore/respirometro

parent fe6d69cb
// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 13; // pin that the LED is attached to
//const int threshold = 540; // an arbitrary threshold level that's in the range of the analog input
const int deltaParado=20;
const int deltaRespirando=20;
//estados possiveis:
const int estadoCalibragem = 0;
const int estadoParado = 1;
const int estadoExpirando = 2;
const int estadoInspirando = 3;
int ambiente;
int anterior;
int atual=0;
boolean processing=false;
int deltaAtual=0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
ambiente= analogRead(analogPin);
anterior=ambiente;
}
void loop() {
int value=analogRead(analogPin);
int value4=value/4;
//Serial.write(analogRead(value4));
//Serial.println(value4);
int analogValue = analogRead(analogPin);
atual=analogValue;
deltaAtual= anterior - analogValue;
if ((anterior - analogValue) > 1) {
toSerial(estadoExpirando);
}
else if ((anterior - analogValue) < -1){
toSerial(estadoInspirando);
}
else if ((analogValue - anterior) == 0){
toSerial(estadoParado);
}
// print the analog value:
//Serial.println(analogValue2);
anterior=analogValue;
delay(200); // delay in between reads for stability
}
void toSerial(int value)
{
if (processing)
{
Serial.write(value);
}
else
{
if (value==estadoInspirando) Serial.print(" inspirando");
if (value==estadoExpirando) Serial.print("expirando:");
if (value==estadoParado) Serial.print("--parado:");
/*if (atual>512)
{
Serial.print("sobrou:");
Serial.print(atual-512,DEC);
Serial.print("--");
}*/
Serial.print(anterior,DEC);
Serial.print(" atual->");
Serial.print(atual,DEC);
Serial.print(" delta->");
Serial.println(deltaAtual,DEC);
}
}
import processing.serial.*;
Serial Port; // Create object from Serial class
float data; // Data received from the serial port
int y,w,h,speedX,speedY;
int paddleX, paddleY, paddleW,paddleH, paddleS;
boolean up, down;
/*void setup2()
{
size(500, 500);
x = width/2;
y = height/2;
w = 50;
h = 50;
speedX = 2;
speedY = 3;
paddleX = 50;
paddleY = height/2;
paddleW = 30;
paddleH = 100;
paddleS = 5;
rectMode(CENTER);
Port = new Serial(this, Serial.list()[0], 9600);
}*/
void drawPaddle(){
fill(255,255,255);
rect(paddleX, paddleY, paddleW, paddleH);
}
void restrictPaddle() {
if(paddleY - paddleH/2 < 0) {
paddleY = paddleY + paddleS;
}
if(paddleY + paddleH/2 > height) {
paddleY = paddleY - paddleS;
}
}
void contactPaddle() {
if(x - w/2 < paddleX + paddleW/2 &&
y - h/2 < paddleY + paddleH/2 &&
y + h/2 > paddleY - paddleH/2)
{
speedX = -speedX;
}
}
void movePaddle() {
if(data == 2) {//expirando
paddleY = paddleY + paddleS;
}
if(data == 3) {//inspirando
paddleY = paddleY - paddleS;
}
}
/*
void keyPressed() {
if(key == 'w' || key == 'W') {
up = true;
}
if(key == 's' || key == 'S') {
down = true;
}
}
void keyReleased() {
if(key == 'w' || key == 'W') {
up = false;
}
if(key == 's' || key == 'S') {
down = false;
}
}
*/
//fase 1
// Baseado no exemplo RestartTest
/**
* Loop.
*
* The loop() function causes draw() to execute
* continuously. If noLoop is called in setup()
* the draw() is only executed once. In this example
* click the mouse to execute loop(), which will
* cause the draw() the execute continuously.
*/
float x = width/2;
// The statements in the setup() function
// run once when the program begins
void setup() {
size(2000, 360); // Size should be the first statement
Port = new Serial(this, Serial.list()[0], 9600);
stroke(255); // Set stroke color to white
///PADDLE:
paddleX = 50;
paddleY = height/2;
paddleW = 30;
paddleH = 30;
paddleS = 3;
rectMode(CENTER);
//fim PADDLE
noLoop();
x = 0;
}
// The statements in draw() are run until the
// program is stopped. Each statement is run in
// sequence and after the last line is read, the first
// line is run again.
void draw() {
background(0); // Set the background to black
//linhas de baixo
line(0+x, height, 500+x, height-300);
line(500+x, height-300, 1000+x, height);
line(1000+x, height, 1500+x, height-300);
line(1500+x, height-300, 2000+x, height);
line(2000+x, height, 2500+x, height-300);
line(2500+x, height-300, 3000+x, height);
line(3000+x, height, 3500+x, height-300);
line(3500+x, height-300, 4000+x, height);
// linhas de cima
line(0+x, height-100, 500+x, 0);
line(500+x, 0, 1000+x, height-100);
line(1000+x, height-100, 1500+x, 0);
line(1500+x, 0, 2000+x, height-100);
line(2000+x, height-100, 2500+x, 0);
line(2500+x, 0, 3000+x, height-100);
line(3000+x, height-100, 3500+x, 0);
line(3500+x, 0, 4000+x, height-100);
//Desenha a 'nave'
if ( Port.available() > 0) { // If data is available,
data = Port.read(); // read it and store it in val
}
println(data);
drawPaddle();
movePaddle();
restrictPaddle();
contactPaddle();
x = x - 5;
if (x < -2000) {
x = 0;
}
}
void mousePressed() {
loop();
}
mode.id=processing.mode.java.JavaMode
mode=Java
import processing.serial.*;
Serial Port; // Create object from Serial class
float data; // Data received from the serial port
void setup()
{
size(500, 500);
x = width/2;
y = height/2;
w = 50;
h = 50;
speedX = 2;
speedY = 3;
paddleX = 50;
paddleY = height/2;
paddleW = 30;
paddleH = 100;
paddleS = 5;
rectMode(CENTER);
Port = new Serial(this, Serial.list()[0], 9600);
}
void draw()
{
background(0);
drawCircle();
moveCircle();
bounceOFF();
drawPaddle();
movePaddle();
restrictPaddle();
contactPaddle();
if ( Port.available() > 0) { // If data is available,
data = Port.read(); // read it and store it in val
}
println(data);
}
int x,y,w,h,speedX,speedY;
int paddleX, paddleY, paddleW,paddleH, paddleS;
boolean up, down;
void drawPaddle(){
fill(255,255,255);
rect(paddleX, paddleY, paddleW, paddleH);
}
void drawCircle(){
fill(200,0,0);
ellipse(x, y, w, h);
}
void moveCircle(){
x = x + speedX;
y = y + speedY;
}
void bounceOFF(){
if ( y > height - 25) {
speedY = -speedY;
} else if ( y < 25) {
speedY = -speedY;
}
if ( x > width - 25) {
speedX = -speedX;
}
else if ( x < 25) {
speedX = -speedX;
}
}
void restrictPaddle() {
if(paddleY - paddleH/2 < 0) {
paddleY = paddleY + paddleS;
}
if(paddleY + paddleH/2 > height) {
paddleY = paddleY - paddleS;
}
}
void contactPaddle() {
if(x - w/2 < paddleX + paddleW/2 && y - h/2 < paddleY + paddleH/2 && y + h/2 > paddleY - paddleH/2) {
speedX = -speedX;
}
}
void movePaddle() {
if(data == 2) {//expirando
paddleY = paddleY + paddleS;
}
if(data == 3) {//inspirando
paddleY = paddleY - paddleS;
}
}
/*
void keyPressed() {
if(key == 'w' || key == 'W') {
up = true;
}
if(key == 's' || key == 'S') {
down = true;
}
}
void keyReleased() {
if(key == 'w' || key == 'W') {
up = false;
}
if(key == 's' || key == 'S') {
down = false;
}
}
*/
mode.id=processing.mode.java.JavaMode
mode=Java
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment