Sei sulla pagina 1di 9

/* Definimos pines */

#define PIN_LED1 9 // Conectamos una LED en el pin 9

#define PIN_LED2 10 // Conectamos una LED en el pin 10

#define PIN_LED3 13 // Conectamos una LED en el pin 10

#define PIN_LUZ1 A0 // Conectamos un fotorresistor en el pin analógico A0

#define PIN_LUZ2 A1 // Conectamos un fotorresistor en el pin analógico A5

#define PIN_LUZ3 A2 // Conectamos un fotorresistor en el pin analógico A5

String dato; // Para enviar un dato por el puerto serie

void setup()

/* Establecemos los pines de las LED como salida */

pinMode(PIN_LED1, OUTPUT);

pinMode(PIN_LED3, OUTPUT);

pinMode(PIN_LED3, OUTPUT);

/* Establecemos los fotorresistores como entrada */

pinMode(PIN_LUZ1, INPUT);

pinMode(PIN_LUZ2, INPUT);

pinMode(PIN_LUZ3, INPUT);

/* Iniciamos el puerto serie */

Serial.begin(9600);

void loop()

/* Obtenemos valores de los fotorresistores (varían de 0 a 900) */

int nivelDeLuz1 = analogRead(PIN_LUZ1); // fotorresistor1

int nivelDeLuz2 = analogRead(PIN_LUZ2); // fotorresistor2

int nivelDeLuz3 = analogRead(PIN_LUZ3); // fotorresistor2

/* Escalamos los valores para el brillo de las LED */

// nivelDeLuz1 = map(nivelDeLuz1, 0, 900, 0, 255);


nivelDeLuz1 = map(nivelDeLuz1, 500, 800, -45, 45);

// if(nivelDeLuz1 < 15){ // si el valor es muy bajo...

// nivelDeLuz1 = 0; // ...lo hago 0 directamente

// }

nivelDeLuz2 = map(nivelDeLuz2, 330, 130, -20, 20);

// if(nivelDeLuz2 < 15){

// nivelDeLuz2 = 0;

//}

nivelDeLuz3 = map(nivelDeLuz3, 0, 400, 0, 255);

// if(nivelDeLuz3 < 15){

// nivelDeLuz2 = 0;

// }

/* Nos aseguramos de que los niveles de luz son correctos */

nivelDeLuz1 = constrain(nivelDeLuz1, -100, 255);

nivelDeLuz2 = constrain(nivelDeLuz2, -30, 200);

nivelDeLuz3 = constrain(nivelDeLuz3, 0, 255);

/* Aplicamos el brillo a las LED */

analogWrite(PIN_LED1, nivelDeLuz1);

analogWrite(PIN_LED2, nivelDeLuz2);

analogWrite(PIN_LED3, nivelDeLuz3);

/* Enviamos dato por puerto serie */

dato = "";

dato += nivelDeLuz1;

dato += ",";

dato += nivelDeLuz2;

dato += ",";

dato += nivelDeLuz3;
Serial.println(dato);

delay(50); // pequeña pausa para no saturar el puerto serie

}
import processing.serial.*; // Para usar el puerto serie

ArrayList<Punto> onda1; // Conjunto de puntos para representar la onda1

ArrayList<Punto> onda2; // Conjunto de puntos para representar la onda2

ArrayList<Punto> onda3; // Conjunto de puntos para representar la onda2

int valores[] = {0, 0, 0}; // Array para obtener los dos valores del puerto serie

float altura[] = {0.0, 0.0, 0.0}; // Array para las alturas recibidas

Serial puerto; // Puerto serie

//

PrintWriter output; //Para crear el archivo de texto donde guardar los datos

int rquad=40; //Radio del quadrado

int xquad=200; //Posición X de rect

int yquad=200; //Posición Y de rect

boolean overRect = false; //Estado del mouse si está encima de rect o no

//Colores del botón

int red=100;

int green=100;

int blue=100;

boolean status=false; //Estado del color de rect

//String texto="LED OFF";//Texto del status inicial del LED

int xlogo=400;//Posición X de la imagen

int ylogo=120;//Posición Y de la imagen


int valor;//Valor de la temperatura

//Colores esfera temperatura

float rojo;

float verde;

float azul;

//

void setup(){

/* Configuración de ventana */

size(1000, 700); // Tamaño de ventana

frameRate(30); // FPS

smooth(); // Suavizado activado

/* Inicialización de variables */

onda1 = new ArrayList<Punto>();

onda2 = new ArrayList<Punto>();

onda3 = new ArrayList<Punto>();

/* Configuración de puerto serie */

String nombrePuerto = Serial.list()[0];

println("Puerto establecido a " + nombrePuerto + ".");

puerto = new Serial(this, nombrePuerto, 9600);

puerto.bufferUntil('\n'); // guardo datos hasta que encuentro salto de línea

void draw(){

// background(0); // Pintamos color de fondo

background(255,255,255);//Fondo de color blanco


//Creamos un texto de color negro con la palabra LED

fill(0,0,0);

PFont f = loadFont("Calibri-48.vlw");//Tipo de fuente

textFont(f, 20);

int height = 100;

imageMode(CENTER);//Esta función hace que las coordenadas de la imagne sean el centro


de esta y no la esquina izquierda arriba

PImage imagen=loadImage("u.png");

PImage imagen1=loadImage("volante.jpg");

PImage imagen2=loadImage("a.jpg");

image(imagen,width/2,ylogo,500,150);

if(valores != null){

altura[0] = map((float) valores[0], 0, 255, 0, height);

altura[1] = map((float) valores[1], 0, 255, 0, height);

altura[2] = map((float) valores[2], 0, 255, 0, height);

onda1.add(new Punto(altura[0]));

onda2.add(new Punto(altura[1]));

onda3.add(new Punto(altura[2]));

text("INGENIERÍA AUTOMOTRIZ",410,200);

text("Integrantes:",150,400);

text("López Sergio",150,430);

text("Angamarca Andrés",150,460);

text("Atupaña David",150,490);

text("Medina Daniel",150,520);

text("Cárdenas Roger",150,550);

text("San Andrés Amy",150,580);

text(valores[0], 510, 500);

text("Ángulo", 440, 500);


text(valores[1], 810, 500);

text("Ángulo", 740, 500);

text("Materia: Chasis, suspensión y freno", 340, 600);

fill(#FF0000); // relleno color rojo (para el texto)

text("Valor 1: " + valores[0] , 20, 30);

// text("Valor 1: " + altura[0], 20, 30);

fill(#FFFF00); // relleno color amarillo (para el texto)

text("Valor 2: " + altura[1], 20, 50);

fill(#FFFFFF); // relleno color amarillo (para el texto)

text("Valor 3: " + altura[2], 20, 70);

noFill(); // sin relleno

strokeWeight(2); // grosor del lápiz

stroke(#FF0000); // color del lápiz

dibujaCurva(onda1);

stroke(#FFFF00); // color del lápiz

dibujaCurva(onda2);

stroke(#FFFF00); // color del lápiz

dibujaCurva(onda3);

//Esfera color visualización temperatura

/*float temp = map (altura[0], -90,90, 0, 255);//Escalamos la temperatura donde maximo sea
32ºC y mínimo 15ºC

//rojo=temp;

temp=altura[0];

//Dibujamos una esfera para colorear la temperatura


noStroke();

fill(rojo-180,temp/3-180,temp/3-180);

ellipseMode(CENTER);

ellipse(590,500,20,20);

fill(-temp+180,-temp/3+180,-temp/3-180);

ellipse(410,500,20,20);

*/

// translate(width/2, height/2);

translate(500, 350);

rotate(radians((valores[0])));

image(imagen1,0,0,200,200);

// move the origin to the pivot point

resetMatrix();

translate(800, 350);

rotate(radians((valores[1])));

image(imagen2,0,0,200,200);

void dibujaCurva(ArrayList<Punto> onda){

beginShape(); // empieza curva

for(int i = 0; i < onda.size(); i++){

Punto punto = onda.get(i);

punto.desplazar();

curveVertex(punto.getX(), punto.getY()); // añado un punto a la curva

// punto.dibujar(); // dibujo el punto

/* Borrar punto si se ha desplazado demasiado a la izquierda */


if(punto.getX() < -width){

onda.remove(i);

if(onda.size() > 0){

curveVertex(onda.get(onda.size() - 1).getX() + 1, onda.get(onda.size() - 1).getY());

line(onda.get(onda.size() - 1).getX(), onda.get(onda.size() - 1).getY(), width,


onda.get(onda.size() - 1).getY());

/* Dibujar curva */

endShape(); // termina curva

void serialEvent(Serial p){

String dato = p.readStringUntil('\n'); // leemos el buffer del puerto serie

if(dato != null){

dato = trim(dato);

valores = int(split(dato, ','));

Potrebbero piacerti anche