jueves, 24 de septiembre de 2015

LABORATORIO #7

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:



Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  #define MAXLED 3
  2. int led[MAXLED] = {9,10,11};
  3. int valor = 0;
  4. int i = 0;
  5. void setup()
  6. {
  7.   Serial.begin(9600);
  8.   for(int i = 0; i < MAXLED ; i++)
  9.   {
  10.     pinMode(led[i], OUTPUT);
  11.   }
  12. }
  13. void loop()
  14. {
  15.   if(Serial.available() > 0)
  16.   {
  17.     valor = Serial.read();
  18.     if(valor == 'R')
  19.       i = 0;
  20.     if(valor == 'G')
  21.       i = 1;
  22.     if(valor == 'B')
  23.       i = 2;
  24.     valor = Serial.parseInt();
  25.     analogWrite(led[i], valor);
  26. }



CODIGO PROCESSING:


Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  import controlP5.*;        
  2. import processing.serial.*;  
  3. ControlP5 cp5;                
  4. Knob rojo, verde, azul;        
  5. Textlabel texto1, texto2, texto3, texto4, texto5, texto6;
  6. Serial serial;                
  7. void setup()
  8. {
  9. serial = new Serial(this, Serial.list()[0],9600);  
  10. String puerto = Serial.list()[0];                  
  11. size(620,400);                      
  12. cp5 = new ControlP5(this);        
  13. rojo = cp5.addKnob("R",0,255,0,70,120,100);
  14. rojo.setColor(newCColor(0xFFff0000,0xFF9f9f00,0xFF5f0000,0xFFFFFFFF,0xFFFFFFFF));
  15. verde = cp5.addKnob("G",0,255,0,260,120,100);
  16. verde.setColor(newCColor(0xFF00FF00,0xFF9f9f00,0xFF005F00,0xFFFFFFFF,0xFFFFFFFF));
  17. azul = cp5.addKnob("B",0,255,0,450,120,100);
  18. azul.setColor(newCColor(0xFF0000ff,0xFF9f9f00,0xFF00005f,0xFFFFFFFF,0xFFFFFFFF));
  19. texto1 = cp5.addTextlabel("label")
  20.                     .setText("CONTROL DE LED RGB")
  21.                     .setPosition(25,48)
  22.                     .setColorValue(0xffff0000)
  23.                     .setFont(createFont("Ravie",30))
  24.                     ;
  25.                    
  26. texto2 = cp5.addTextlabel("label1")
  27.                     .setText("AZUL")
  28.                     .setPosition(475,235)
  29.                     .setColorValue(0xffff0000)
  30.                     .setFont(createFont("Comic Sans MS",15))
  31.                     ;              
  32.    
  33. texto3 = cp5.addTextlabel("label2")
  34.                     .setText("VERDE")
  35.                     .setPosition(280,235)
  36.                     .setColorValue(0xffff0000)
  37.                     .setFont(createFont("Comic Sans MS",15))
  38.                     ;
  39.                    
  40. texto4 = cp5.addTextlabel("label3")
  41.                     .setText("ROJO")
  42.                     .setPosition(95,235)
  43.                     .setColorValue(0xffff0000)
  44.                     .setFont(createFont("Comic Sans MS",15))
  45.                     ;              
  46. texto4 = new Textlabel(cp5,"Estudiante: Juberth Andres Renteria",40,280,600,200);  
  47. texto4.setFont(createFont("MV Boli",15));
  48. texto5 = new Textlabel(cp5,"Ingenieria Electronica",40,295,600,200);  
  49. texto5.setFont(createFont("MV Boli",15));
  50. texto6 = new Textlabel(cp5,"Noveno semestre",40,310,600,200);  
  51. texto6.setFont(createFont("MV Boli",15));
  52. }
  53. void draw()
  54. {
  55. background(100,70,20);  
  56.  texto4.draw(this);  
  57.  texto5.draw(this);
  58.  texto6.draw(this);
  59. }
  60. void controlEvent (ControlEvent evento)
  61. {
  62. String nombre = evento.getController().getName();  
  63. int valor = int(evento.getController().getValue());  
  64. serial.write(nombre + ":" + valor);  
  65. println(nombre + ":" + valor);  
  66. }

LABORATORIO # 6

DESCRIPCIÓN DEL LABORATORIO:

En este laboratorio Controlaremos un LED RGB desde el Arduino, vía PWM con 3 potenciometros, uno para cada color. 


MATERIALES:

- Protoboard
- Arduino
- 3 Resistencias
- Cable UTP
- Led RGB
- 3 Potenciometros



DIAGRAMA:




ESQUEMA:






FOTOS MONTAJE:










VIDEO:






CODIGO:



Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #define PR A0 n puerto analogo (A0)
  2. #define PG A1
  3. #define PB A2
  4. int rojo = 11;
  5. int verde = 10;
  6. int azul = 9;
  7. void setup ()
  8. {
  9.   pinMode (rojo, OUTPUT);
  10.   pinMode (verde, OUTPUT);
  11.   pinMode (azul, OUTPUT);
  12.   pinMode (PR, INPUT);
  13.   pinMode (PG, INPUT);
  14.   pinMode (PB, INPUT);
  15.   Serial.begin (9600);
  16. }
  17. void loop ()
  18. {
  19.   int R = analogRead(PR);
  20.   int i = map(R,0,1023,0,255);
  21.   int G = analogRead(PG);
  22.   int i1 = map(G,0,1023,0,255);
  23.   int B = analogRead(PB);
  24.   int i2 = map(B,0,1023,0,255);
  25.   analogWrite (azul,i2);
  26.   analogWrite (rojo,i);
  27.   analogWrite (verde,i1);
  28.  }