DESCRIPCIÓN DEL LABORATORIO: Controlar 8 LEDs desde el Arduino, a través de un IC 74HC595, definiendo mínimo 8 patrones de movimiento que son controlados desde una interfaz gráfica en Processing/ControlP5
MATERIALES:
- Protoboard
- Arduino Uno
- 8 Resistencias
- 8 Leds
- Cable UTP
- IC 74HC595
- Cables
DIAGRAMAS:
MONTAJE PROTOBOARD:
ESQUEMATICO:
FOTOS DEL MONTAJE:
VIDEO:
CODIGO ARDUINO:
- // Pin conectado a ST_CP del 74HC595
- //Pin connected to ST_CP of 74HC595
- int latchPin = 8;
- // Pin conectado a SH_CP del 74HC595
- //Pin connected to SH_CP of 74HC595
- int clockPin = 12;
- // Pin conectado a DS de 74HC595
- //Pin connected to DS of 74HC595
- int dataPin = 11;
- void setup() {
- /*Se inicializa el puerto serial a 9600 baudio*/
- /* The serial port is initialized at 9600 baud */
- Serial.begin(9600);
- /* Define the pins latchPin, clockPin and dataPin as OUTPUT pins */
- /*Defino los pines latchPin, clockPin and dataPin como pines de SALIDA */
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- }
- void loop() {
- /*Evaluo si el puerto Serial tiene datos*/
- /* Evaluated whether Serial port has data */
- if (Serial.available()>0){
- /*el dato obtenido del puerto Serial es obtenido como un entero y almacenado en la variable valor*/
- /* Data from the Serial port obtained is obtained as an integer and stored in the variable value */
- int valor = Serial.parseInt();
- /*Se imprime al monitor Serial el valor*/
- /* The Serial monitor prints the value */
- Serial.println(valor);
- /* tomar el Pin Pestillo para que los led's no cambein mientras se manda el valor */
- /*take the latchPin low so
- the LEDs don't change while you're sending in bits:*/
- digitalWrite(latchPin, LOW);
- // shift out the bits:
- // Cambiar los bits:
- shiftOut(dataPin, clockPin, MSBFIRST, valor);
- //take the latch pin high so the LEDs will light up:
- // Cambia a la alta el pasador por lo que los LEDs se iluminarán:
- digitalWrite(latchPin, HIGH);
- // pause before next value:
- delay(500);
- }
- }
CODIGO PROCESSING:
- import controlP5.*;
- import processing.serial.*;
- ControlP5 cp5;
- CheckBox checkbox;
- int []colores={0,0,0};
- int [] binar={128, 64, 32, 16, 8, 4, 2, 1};
- Serial serial;
- void setup() {
- size(700, 400);
- smooth();
- cp5 = new ControlP5(this);
- checkbox = cp5.addCheckBox("checkBox")
- .setPosition(100, 200)
- .setColorForeground(color(120))
- .setColorActive(color(255))
- .setColorLabel(color(255))
- .setSize(40, 40)
- .setItemsPerRow(4)
- .setSpacingColumn(30)
- .setSpacingRow(20)
- .addItem("LED 1",1)
- .addItem("LED 2",2)
- .addItem("LED 3",3)
- .addItem("LED 4",4)
- .addItem("LED 5",5)
- .addItem("LED 6",6)
- .addItem("LED 7",7)
- .addItem("LED 8",8)
- ;
- cp5.addButton("Encender")
- .setPosition(100, 320)
- .setSize(80,40)
- ;
- serial = new Serial(this, Serial.list()[0], 9600);
- }
- void draw() {
- background(0);
- pushMatrix();
- translate(width/2 + 200, height/2);
- stroke(255);
- strokeWeight(2);
- fill(colores[0],colores[1],colores[2]);
- ellipse(0,0,200,200);
- popMatrix();
- }
- void controlEvent(ControlEvent theEvent) {
- if (theEvent.isFrom(checkbox)) {
- }else if(theEvent.getController().getName().equals("Encender")){
- colores[0]=0;
- colores[1]=0;
- colores[2]=0;
- int total=0;
- for (int i=0;i<checkbox.getArrayValue().length;i++) {
- int n = (int)checkbox.getArrayValue()[i];
- if (n>0){
- total+=binar[i];
- }
- }
- serial.write(""+total);
- if (total==224){
- colores[0]=255;
- colores[1]=255;
- colores[2]=0;
- }
- if (total==28){
- colores[0]=0;
- colores[1]=255;
- colores[2]=0;
- }
- if (total==3){
- colores[0]=255;
- colores[1]=0;
- colores[2]=0;
- }
- println(total);
- }
- }


No hay comentarios:
Publicar un comentario