sábado, 30 de mayo de 2015

laboratorio #11

enviar desde una pagina web un mensaje a una matriz LED 8x8 que se desplaza de izquierda a derecha atraves de un IC MAX7219

materiales a utilizar

placa Arduino uno o Arduino mega
matriz LED 8X8
cables varios

montaje























codigo arduino

#include "LedControl.h"
 pin 12 = DataIn:din
 pin 11 = CLK
 pin 10 = : cs

//laboratorio #11 : Enviar desde una página web un mensaje a una matriz LED 8x8 (desplazándose de izquierda a derecha) a través de IC MAX7219.
     
 */
LedControl lc = LedControl(12,11,10);

//ASCII TABLE

 byte chars[129][8] = {
    {0,0,0,0,0,0,0,0}, // 0
  {0,0,0,0,0,0,0,0}, // 1
  {0,0,0,0,0,0,0,0}, // 2
  {0,0,0,0,0,0,0,0}, // 3
  {0,0,0,0,0,0,0,0}, // 4
  {0,0,0,0,0,0,0,0}, // 5
  {0,0,0,0,0,0,0,0}, // 6
  {0,0,0,0,0,0,0,0}, // 7
  {0,0,0,0,0,0,0,0}, // 8
  {0,0,0,0,0,0,0,0}, // 9
  {0,0,0,0,0,0,0,0}, // 10
  {0,0,0,0,0,0,0,0}, // 11
  {0,0,0,0,0,0,0,0}, // 12
  {0,0,0,0,0,0,0,0}, // 13
  {0,0,0,0,0,0,0,0}, // 14
  {0,0,0,0,0,0,0,0}, // 15
  {0,0,0,0,0,0,0,0}, // 16
  {0,0,0,0,0,0,0,0}, // 17
  {0,0,0,0,0,0,0,0}, // 18
  {0,0,0,0,0,0,0,0}, // 19
  {0,0,0,0,0,0,0,0}, // 20
  {0,0,0,0,0,0,0,0}, // 21
  {0,0,0,0,0,0,0,0}, // 22
  {0,0,0,0,0,0,0,0}, // 23
  {0,0,0,0,0,0,0,0}, // 24
  {0,0,0,0,0,0,0,0}, // 25
  {0,0,0,0,0,0,0,0}, // 26
  {0,0,0,0,0,0,0,0}, // 27
  {0,0,0,0,0,0,0,0}, // 28
  {0,0,0,0,0,0,0,0}, // 29
  {0,0,0,0,0,0,0,0}, // 30
  {0,0,0,0,0,0,0,0}, // 31
  {0,0,0,0,0,0,0,0}, // 32
  {0,0,0,0,0,0,0,0}, // 33
  {0,0,0,0,0,0,0,0}, // 34
  {0,0,0,0,0,0,0,0}, // 35
  {0,0,0,0,0,0,0,0}, // 36
  {0,0,0,0,0,0,0,0}, // 37
  {0,0,0,0,0,0,0,0}, // 38
  {0,0,0,0,0,0,0,0}, // 39
  {0,0,0,0,0,0,0,0}, // 40
  {0,0,0,0,0,0,0,0}, // 41
  {0,0,0,0,0,0,0,0}, // 42
  {0,0,0,0,0,0,0,0}, // 43
  {0,0,0,0,0,0,0,0}, // 44
  {0,0,0,0,0,0,0,0}, // 45
  {0,0,0,0,0,0,0,0}, // 46
  {0,0,0,0,0,0,0,0}, // 47
  {0,0,0,0,0,0,0,0}, // 48
  {0,0,0,0,0,0,0,0}, // 49
  {0,0,0,0,0,0,0,0}, // 50
  {0,0,0,0,0,0,0,0}, // 51
  {0,0,0,0,0,0,0,0}, // 52
  {0,0,0,0,0,0,0,0}, // 53
  {0,0,0,0,0,0,0,0}, // 54
  {0,0,0,0,0,0,0,0}, // 55
  {0,0,0,0,0,0,0,0}, // 56
  {0,0,0,0,0,0,0,0}, // 57
  {0,0,0,0,0,0,0,0}, // 58
  {0,0,0,0,0,0,0,0}, // 59
  {0,0,0,0,0,0,0,0}, // 60
  {0,0,0,0,0,0,0,0}, // 61
  {0,0,0,0,0,0,0,0}, // 62
  {0,0,0,0,0,0,0,0}, // 63
  {0,0,0,0,0,0,0,0}, // 64
  {B11110110,B11111111,B00001001,B00001001,B00001001,B00001001,B11111111,B11110110}, // 65A
  {B11111111,B11111111,B10001001,B10001001,B10001001,B10001001,B11111111,B01110110}, // 66B
  {B11111111,B11111111,B11100111,B11000011,B11000011,B11000011,B11000011,B11000011}, // 67C
  {B11111111,B11111111,B11000011,B11000011,B11000011,B11000011,B11111111,B01111110}, // 68D
  {B01111110,B11111111,B11011011,B11011011,B11011011,B11000011,B11000011,B00000000},//E
  {B11111110,B11111111,B00110011,B00110011,B00110011,B00110011,B00110011,B00000000},//F
  {B11111110,B11111111,B10000011,B10011011,B10011011,B10011011,B10011011,B11110011},//G
  {B11111111,B11111111,B00011000,B00011000,B00011000,B00011000,B11111111,B11111111},//H
  {B11000011,B11000011,B11000011,B11111111,B11111111,B11000011,B11000011,B11000011},//I
  {B11000011,B11000011,B11000011,B11111111,B11111111,B00000011,B00000011,B00000011},//J
  {B11111111,B11111111,B00011000,B00011000,B00111100,B01100110,B11000011,B10000001},//K
  {B11111111,B11111111,B11100000,B11000000,B11000000,B11000000,B11000000,B00000000},//L
  {B11111111,B11111111,B00000110,B00011100,B00011100,B00000110,B11111111,B11111111},//M
  {B11111111,B11111111,B00000110,B00001100,B00011000,B00110000,B11111111,B11111111},//N
  {B01111110,B11111111,B11000011,B10000001,B10000001,B11000011,B11111111,B01111110},//O
  {B11111110,B11111111,B00011111,B00010001,B00010001,B00011111,B00011111,B00000000},//P
  {B00111110,B01111111,B01000001,B01000001,B01010001,B01100001,B01111111,B10111110},//Q
  {B11111110,B11111111,B00011001,B00011001,B00011001,B00111001,B11011111,B10001110},//R
  {B11001110,B11011111,B11011011,B11011011,B11011011,B11011011,B11111011,B01110011}, // 83S
  {B00000011,B00000011,B00000011,B11111111,B11111111,B00000011,B00000011,B00000011}, // 84T
  {B11111111,B11111111,B11000000,B11000000,B11000000,B11000000,B11111111,B11111111}, // 85U
  {B00011111,B00111100,B01110000,B11100000,B11100000,B01110000,B00111100,B00011111},//V
  {B00111110,B01111000,B11110000,B00111000,B00111000,B11110000,B01111000,B00111110},//W
  {B10000001,B11000011,B01100110,B00011000,B00011000,B01100110,B11000011,B10000001},//X
  {B00000001,B00000111,B00001100,B11111000,B11111000,B00001100,B00000111,B00000001},//Y
  {B11000001,B11100001,B11110001,B10111001,B10011101,B10001111,B10000111,B10000011},//Z
  {0,0,0,0,0,0,0,0}, // 91
  {0,0,0,0,0,0,0,0}, // 92
  {0,0,0,0,0,0,0,0}, // 93
  {0,0,0,0,0,0,0,0}, // 94
  {0,0,0,0,0,0,0,0}, // 95
  {0,0,0,0,0,0,0,0}, // 96
  {B11110110,B11111111,B00001001,B00001001,B00001001,B00001001,B11111111,B11110110}, // 65A
  {B11111111,B11111111,B10001001,B10001001,B10001001,B10001001,B11111111,B01110110}, // 66B
  {B11111111,B11111111,B11100111,B11000011,B11000011,B11000011,B11000011,B11000011}, // 67C
  {B11111111,B11111111,B11000011,B11000011,B11000011,B11000011,B11111111,B01111110}, // 68D
  {B01111110,B11111111,B11011011,B11011011,B11011011,B11000011,B11000011,B00000000},//E
  {B11111110,B11111111,B00110011,B00110011,B00110011,B00110011,B00110011,B00000000},//F
  {B11111110,B11111111,B10000011,B10011011,B10011011,B10011011,B10011011,B11110011},//G
  {B11111111,B11111111,B00011000,B00011000,B00011000,B00011000,B11111111,B11111111},//H
  {B11000011,B11000011,B11000011,B11111111,B11111111,B11000011,B11000011,B11000011},//I
  {B11000011,B11000011,B11000011,B11111111,B11111111,B00000011,B00000011,B00000011},//J
  {B11111111,B11111111,B00011000,B00011000,B00111100,B01100110,B11000011,B10000001},//K
  {B11111111,B11111111,B11100000,B11000000,B11000000,B11000000,B11000000,B00000000},//L
  {B11111111,B11111111,B00000110,B00011100,B00011100,B00000110,B11111111,B11111111},//M
  {B11111111,B11111111,B00000110,B00001100,B00011000,B00110000,B11111111,B11111111},//N
  {B01111110,B11111111,B11000011,B10000001,B10000001,B11000011,B11111111,B01111110},//O
  {B11111110,B11111111,B00011111,B00010001,B00010001,B00011111,B00011111,B00000000},//P
  {B00111110,B01111111,B01000001,B01000001,B01010001,B01100001,B01111111,B10111110},//Q
  {B11111110,B11111111,B00011001,B00011001,B00011001,B00111001,B11011111,B10001110},//R
  {B11001110,B11011111,B11011011,B11011011,B11011011,B11011011,B11111011,B01110011}, // 83S
  {B00000011,B00000011,B00000011,B11111111,B11111111,B00000011,B00000011,B00000011}, // 84T
  {B11111111,B11111111,B11000000,B11000000,B11000000,B11000000,B11111111,B11111111}, // 85U
  {B00011111,B00111100,B01110000,B11100000,B11100000,B01110000,B00111100,B00011111},//V
  {B00111110,B01111000,B11110000,B00111000,B00111000,B11110000,B01111000,B00111110},//W
  {B10000001,B11000011,B01100110,B00011000,B00011000,B01100110,B11000011,B10000001},//X
  {B00000001,B00000111,B00001100,B11111000,B11111000,B00001100,B00000111,B00000001},//Y
  {B11000001,B11100001,B11110001,B10111001,B10011101,B10001111,B10000111,B10000011},//Z
  {0,0,0,0,0,0,0,0}, // 123
  {0,0,0,0,0,0,0,0}, // 124
  {0,0,0,0,0,0,0,0}, // 125
  {0,0,0,0,0,0,0,0}, // 126
  {0,0,0,0,0,0,0,0}, // 127
  {0,0,0,0,0,0,0,0} // 128
};

/* siempre esperamos un poco entre las actualizaciones de la pantalla */

void setup() {
  /*
     El MAX72XX está en modo de ahorro de energía en el arranque,
      tenemos que hacer una llamada de atención
  */
 
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);

  Serial.begin(9600);

}

/*
 Este método mostrará los caracteres para la
 palabra "Arduino" uno tras otro en la matriz.
(se necesitan al menos leds 5x7 para ver todo el caracteres)
 */
void writeChar(char chLetter, int nuDelayTime) {
 
      for (int i=0; i<8; i++){
          lc.setRow(0,i,chars[chLetter][i]);
      }
     
    delay(nuDelayTime);

}

void loop() {

  Serial.flush();

  if (Serial.available() > 0) {

    char chLetter = Serial.read();
 
    writeChar(chLetter,700);
 
  }

}

video del laboratorio





laboratorio #10

En este laboratorio se muestra un mensaje de izquierda a derecha en una matriz de LEDs de 8x8 atraves de un ICMAX7219 enviado desde un Arduino.

Elementos utilizados

placa Arduino uno o mega
matriz de leds de 8x8
cables varios


diagrama en fritzing


















codigo Arduino


#include "LedControl.h"
String texto="universidad santiago de cali:";

LedControl lc=LedControl(12,11,10,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;

void setup() {
  Serial.begin(9600);
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
}
char abcMAY[36]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','1','2', '3', '4', '5', '6', '7', '8', '9', '0'};
char abcMIN[36]={'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','1','2', '3', '4', '5', '6', '7', '8', '9', '0'};
byte letras[36][5]= { {B11111110,B00010001,B00010001,B00010001,B11111110},//A
  {0xFF, 0x89, 0x89, 0x89, 0x76},//B
  {B01111110,B10000001,B10000001,B10000001,B01000110},//C
  {0xff, 0x81, 0x81, 0x81, 0x7e},//D
  {0x7e, 0x89, 0x89, 0x89, 0x89},//E
  {0xff, 0x09, 0x09, 0x09, 0x01},//F
  {0x7e, 0x89, 0x89, 0x89, 0xf2},//G
  {0xFF, 0x18, 0x18, 0x18,0xff},//H
  {B00000000,B10000100,B11111101,B10000000,B00000000},//I
  {0x71, 0x81, 0x7f, 0x01, 0x01},//J
  {0xff, 0x10, 0x2c, 0x42, 0x81},//K
  {0x7f, 0xc0, 0x80,0x80, 0x80},//L
  {0xff, 0x06, 0x0c, 0x06, 0xff},//M
  {B11111111,B00000100,B00001000,B00010000,B11111111}, //N
  {B01111110,B10000001,B10000001,B10000001,B01111110},//O
  {0xff, 0x09, 0x09, 0x09, 0x06},//P
  {0xbe, 0x41,0xA1, 0x81, 0x7e},//Q
  {B11111111,B00010001,B00110001,B01010001,B10001110},//R
  {0x86, 0x89, 0x89, 0x89, 0x71},//S
  {0x01, 0x01, 0xff, 0x01, 0x01},//T
  {B01111111,B11000000,B11000000,B11000000,B01111111},//U
  {0x3f, 0x40, 0x80, 0x40, 0x3f},//V
  {0x7f, 0x80, 0x70, 0x80, 0x7f},//W
  {0xe3, 0x14, 0x08, 0x14, 0xe3},//X
  {0x03, 0x04, 0xf8, 0x04, 0x03},//Y
  {0xe1, 0x91, 0x89, 0x85, 0x83 }//Z

  ,{0x00, 0x82, 0xff, 0x80,0x00},//1
  {0xc2, 0xa1, 0x91, 0x89, 0x86},//2
  {0x81,0x81,0x85,0x8b,0x71},//3
  {0x18,0x14, 0x12, 0xff, 0x00},//4
  {0x8f, 0x89, 0x89, 0x89, 0x71},//5
  {0x7c, 0x8a, 0x89, 0x89, 0x70},//6
  {0x01, 0xf1, 0x09,0x05, 0x03},//7
  {0x76, 0x89, 0x89, 0x89, 0x76},//8
  {0x06, 0x89, 0x89, 0x89, 0x7e },//9
  {B01111110,B11100001,B10011001,B10000111,B01111110},//O
};
/*
 This method will display the characters for the
 word "Arduino" one after the other on the matrix.
 (you need at least 5x7 leds to see the whole chars)
 */
void writeArduinoOnMatrix(String mensajea) {
  /* here is the data for the characters */


 for(int j=0;j<mensajea.length();j++){
   for(int k=0;k<36;k++){
 if(mensajea.charAt(j)==abcMAY[k] || mensajea.charAt(j)==abcMIN[k]){
 palabras(letras[k]);
 }
 }
 }

}
void palabras(byte listd[]){
  for(int j=7;j>-4;j--){
 
  for(int i=4; i> -1; i--){
  lc.setRow(0,j+i,listd[i]);
  }
  delay(delaytime);
  for(int o=0; o<8 ; o++){
  lc.setRow(0,o,0);
  }
  }
}

void loop() {
  writeArduinoOnMatrix(texto);

}

void serialEvent(){
while(Serial.available()){
texto= Serial.readString();
}
}

video del laboratorio



jueves, 28 de mayo de 2015

laboratorio #8

En este laboratorio se manipulara en la pantalla de un computador un objeto gráfico usando processing leyendo los datos en Arduino mega desde un joystick shield

Lista de componentes

placa arduino uno o mega
cables varios
joystick

Montaje














montaje en protoboard

diagrama en fritzing


codigo arduino

 //laboratorio 8
int pinarr=4; //pines a utilizar
int pinaba=5;
int pinizq=6;
int pinder=3;
int po=A0;
int pa=A1;

void setup()
{
//se inicia la comunicacion serial
//y se asignan el modo de los pines
Serial.begin(9600);
pinMode(pinarr, INPUT);
pinMode(pinaba, INPUT);
pinMode(pinizq, INPUT);
pinMode(pinder, INPUT);
pinMode(po, INPUT);
pinMode(pa, INPUT);

}
int x;
int y;
void loop()
{
 x=analogRead(po);
y=analogRead(pa);


if (y>1022){
Serial.println("arriba");

}
if (y<1){
Serial.println("abajo");

}
if (x>1022){
Serial.println("der");

}
if (x<1){
Serial.println("izq");

}
delay(200);


}

codigo processing

import controlP5.*;
import processing.serial.*;

PImage img;
int iW2, iH2;
int posX, posY;
int velocity, angle;
 Serial serial;
 String val;
void setup() {
   serial = new Serial(this, Serial.list()[0], 9600);
  // tamaño de la ventana
  size(800, 600);
  // carga la imagen en la variable
  img = loadImage("spaceship.gif");
  iW2 = img.width/2;
  iH2 = img.height/2;
  posX = (width/2)-iW2;
  posY = (height/2)-iH2;
  velocity = -5;
  angle = 0;
}

void draw() {
  // limpia la ventana
  background(0);
  posX += velocity * sin(radians(angle));
  if (posX-iW2 < 0) posX = width;
  if (posX-iW2 > width) posX = iW2;
  posY += velocity * cos(radians(angle));
  if (posY-iH2 < 0) posY = height;
  if (posY-iH2 > height) posY = iH2;
  // dibuja la imagen
  pushMatrix();
  translate(posX-iW2, posY-iH2);
  rotate(radians(-angle));
  image(img, -iW2, -iH2);
  popMatrix();
  Cambio();
}
/*
void keyPressed() {
  if (key == CODED) {
    if (keyCode == UP)
      velocity -= 5;  
    if (keyCode == DOWN)
      velocity += 5;
    if (keyCode == LEFT)
      angle += 5;  
    if (keyCode == RIGHT)
      angle -= 5;
  }  
}*/

void Cambio(){
 if ( serial.available() > 0)
  {  // If data is available,
  val = serial.readString()+"";         // read it and store it in val

  }

println(val); //print it out in the console
if(val==null){val="0";}
if(val.indexOf("arriba")>=0){
        velocity -= 5;  
val="";
}
if(val.indexOf("abajo")>=0){
      velocity += 5;
val="";
}
if(val.indexOf("izq")>=0){
      angle += 5;  
val="";
}
if(val.indexOf("der")>=0){
      angle -= 5;
val="";
}


}

vídeo del laboratorio