Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Importamos las librerías de ControlP5 y Serial
- import controlP5.*;
- import processing.serial.*;
- // Creamos las variables para ControlP5, el Slider y el puerto Serial
- ControlP5 cp5;
- Slider sliderRojo;
- Slider sliderAzul;
- Slider sliderVerde;
- Serial serial;
- int valor;
- // Solo se ejecuta una vez, al iniciar el Sketch
- void setup() {
- // Tamaño de la Ventana
- size(600, 400);
- // Creamos el objeto de ControlP5
- cp5 = new ControlP5(this);
- // Creamos el objeto Slider (nombre, minimo, maximo, inicial, esq superiro izq, ancho, alto)
- sliderRojo = cp5.addSlider("Rojo", 0, 255, 70, 40, 40, 250, 40).setColorBackground(color(250, 0, 0));
- sliderVerde = cp5.addSlider("Verde", 0, 255, 70, 40, 100, 250, 40).setColorBackground(color(0, 250, 0));
- sliderAzul = cp5.addSlider("Azul", 0, 255, 70, 40, 160, 250, 40).setColorBackground(color(0, 0, 250));
- cp5.addButton("Patron1").setValue(0).setPosition(400, 30).setSize(50, 50);
- cp5.addButton("Patron2").setValue(0).setPosition(400, 90).setSize(50, 50);
- cp5.addButton("Patron3").setValue(0).setPosition(400, 150).setSize(50, 50);
- cp5.addButton("Patron4").setValue(0).setPosition(400, 210).setSize(50, 50);
- cp5.addButton("Patron5").setValue(0).setPosition(470, 30).setSize(50, 50);
- cp5.addButton("Patron6").setValue(0).setPosition(470, 90).setSize(50, 50);
- cp5.addButton("Patron7").setValue(0).setPosition(470, 150).setSize(50, 50);
- cp5.addButton("Patron8").setValue(0).setPosition(470, 210).setSize(50, 50);
- // Creamos el objeto del puerto Serial
- serial = new Serial(this, Serial.list()[1], 9600);
- }
- // Se ejecuta N frames por segundo
- void draw() {
- // En este caso no debe dibujar nada
- }
- // Cuando ocurra un evento, aquí lo procesamos
- void controlEvent(ControlEvent evento) {
- String nombre = evento.getController().getName();
- // dependiendo del nombre del evento se carga una letra
- if (nombre == "Patron1") {
- valor = 1;
- }
- if (nombre == "Patron2") {
- valor = 2;
- }
- if (nombre == "Patron3") {
- valor = 3;
- }
- if (nombre == "Patron4") {
- valor = 4;
- }
- if (nombre == "Patron5") {
- valor = 5;
- }
- if (nombre == "Patron6") {
- valor = 6;
- }
- if (nombre == "Patron7") {
- valor = 7;
- }
- if (nombre == "Patron8") {
- valor = 8;
- }
- //se envia el valor por el puerto serial
- println(valor);
- serial.write("S"+valor);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement