DESCRIPCIÓN DEL LABORATORIO: Controlar un LED RGB desde el Arduino, vía PWM con una interfaz gráfica en Processing/ControlP5 para controlar el valor de cada color.
MATERIALES:
- Arduino
- Protoboard
- Led RGB
- Cable UTP
- 3 Resistencias
- Cables
DIAGRAMAS:
En Protoboard
ESQUEMATICO:
FOTOS DEL MONTAJE:
VIDEO:
CODIGO ARDUINO:
- #define MAXLED 3
- int led[MAXLED] = {9,10,11};
- int valor = 0;
- int i = 0;
- void setup()
- {
- Serial.begin(9600);
- for(int i = 0; i < MAXLED ; i++)
- {
- pinMode(led[i], OUTPUT);
- }
- }
- void loop()
- {
- if(Serial.available() > 0)
- {
- valor = Serial.read();
- if(valor == 'R')
- i = 0;
- if(valor == 'G')
- i = 1;
- if(valor == 'B')
- i = 2;
- valor = Serial.parseInt();
- analogWrite(led[i], valor);
- }
CODIGO PROCESSING:
- import controlP5.*;
- import processing.serial.*;
- ControlP5 cp5;
- Knob rojo, verde, azul;
- Textlabel texto1, texto2, texto3, texto4, texto5, texto6;
- Serial serial;
- void setup()
- {
- serial = new Serial(this, Serial.list()[0],9600);
- String puerto = Serial.list()[0];
- size(620,400);
- cp5 = new ControlP5(this);
- rojo = cp5.addKnob("R",0,255,0,70,120,100);
- rojo.setColor(newCColor(0xFFff0000,0xFF9f9f00,0xFF5f0000,0xFFFFFFFF,0xFFFFFFFF));
- verde = cp5.addKnob("G",0,255,0,260,120,100);
- verde.setColor(newCColor(0xFF00FF00,0xFF9f9f00,0xFF005F00,0xFFFFFFFF,0xFFFFFFFF));
- azul = cp5.addKnob("B",0,255,0,450,120,100);
- azul.setColor(newCColor(0xFF0000ff,0xFF9f9f00,0xFF00005f,0xFFFFFFFF,0xFFFFFFFF));
- texto1 = cp5.addTextlabel("label")
- .setText("CONTROL DE LED RGB")
- .setPosition(25,48)
- .setColorValue(0xffff0000)
- .setFont(createFont("Ravie",30))
- ;
- texto2 = cp5.addTextlabel("label1")
- .setText("AZUL")
- .setPosition(475,235)
- .setColorValue(0xffff0000)
- .setFont(createFont("Comic Sans MS",15))
- ;
- texto3 = cp5.addTextlabel("label2")
- .setText("VERDE")
- .setPosition(280,235)
- .setColorValue(0xffff0000)
- .setFont(createFont("Comic Sans MS",15))
- ;
- texto4 = cp5.addTextlabel("label3")
- .setText("ROJO")
- .setPosition(95,235)
- .setColorValue(0xffff0000)
- .setFont(createFont("Comic Sans MS",15))
- ;
- texto4 = new Textlabel(cp5,"Estudiante: Juberth Andres Renteria",40,280,600,200);
- texto4.setFont(createFont("MV Boli",15));
- texto5 = new Textlabel(cp5,"Ingenieria Electronica",40,295,600,200);
- texto5.setFont(createFont("MV Boli",15));
- texto6 = new Textlabel(cp5,"Noveno semestre",40,310,600,200);
- texto6.setFont(createFont("MV Boli",15));
- }
- void draw()
- {
- background(100,70,20);
- texto4.draw(this);
- texto5.draw(this);
- texto6.draw(this);
- }
- void controlEvent (ControlEvent evento)
- {
- String nombre = evento.getController().getName();
- int valor = int(evento.getController().getValue());
- serial.write(nombre + ":" + valor);
- println(nombre + ":" + valor);
- }



