lunes, 1 de abril de 2013

Cube Leds 3x3x3 ARDUINO


 Este es mi trabajo realizado en una Protoboard;
la imagen que se aprecia aquí, la saque de internet, les enseña como deben de hacer el cubo(las patitas negativas del led son los horizontales y las patitas positivas del led son los verticales) pero ha diferencia de la mía  es que en mi trabajo yo empece con el PIN 0, es igual a la imagen con la condición que deben de mover un PIN a la derecha(o sea, en vez de comenzar desde el PIN 1, yo empece con el PIN 0 y termine en el PIN 11, solo deben de correr un PIN).

MATERIALES:
-27 leds
-9 resistencias de 100 ohmios
-3 resistencias de 1000 ohmios (1K ohmio)
-Cable multipar o de red
-3 transistores NPN 2N 3904

AQUÍ UN VIDEO DE MI CUBO DE LEDs(mas abajo el código)


CÓDIGO:

void setup() {
// initialize the digital pin as an output.
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT); // LEDs verdes
pinMode(10, OUTPUT); // LEDs amarillos
pinMode(11, OUTPUT); // LEDs rojos

}

void loop() {
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);

for (int i=0; i <= 3; i++) // run loop 6 times
{
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(2, HIGH);
digitalWrite(6, HIGH);
delay(300);
digitalWrite(2, LOW);
digitalWrite(6, LOW);
digitalWrite(1, HIGH);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(1, LOW);
digitalWrite(7, LOW);
digitalWrite(0, HIGH);
digitalWrite(8, HIGH);
delay(300);
digitalWrite(0, LOW);
digitalWrite(8, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(2, HIGH);
digitalWrite(6, HIGH);
delay(300);
digitalWrite(2, LOW);
digitalWrite(6, LOW);
digitalWrite(1, HIGH);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(1, LOW);
digitalWrite(7, LOW);
digitalWrite(0, HIGH);
digitalWrite(8, HIGH);
delay(300);
digitalWrite(0, LOW);
digitalWrite(8, LOW);

}

for (int i=0; i <= 3; i++) // run loop 4 times
{
byte pins[] = {0, 1, 2, 5, 8, 7, 6, 3};
// above array of 8
{
for (int i=0; i <= 3; i++) // run loop 3 times
{
byte level[] = {11, 10, 9};
for(int i=0; i<=2; i++) // loop equals number
{ // of values in array
digitalWrite(level[i], HIGH); // write index value

for(int i=0; i<=7; i++) // loop equals number
{ // of values in array
digitalWrite(pins[i], HIGH); // write index value
delay(200); // pause 200ms
digitalWrite(pins[i], LOW); // write index value
}
digitalWrite(level[i], LOW); // write index value

}
}
}

digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);

for (int i=0; i <= 4; i++) // run loop 4 times
{

digitalWrite(0, HIGH);
delay(300);

digitalWrite(4, HIGH);
delay(300);

digitalWrite(8, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(400);

digitalWrite(6, HIGH);
delay(300);

digitalWrite(4, HIGH);
delay(300);
digitalWrite(2, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(400);


digitalWrite(3, HIGH);
delay(300);

digitalWrite(4, HIGH);
delay(300);

digitalWrite(5, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(400);


digitalWrite(7, HIGH);
delay(300);

digitalWrite(4, HIGH);
delay(300);

digitalWrite(1, HIGH);
delay(300);


digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(200);
}

digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);

for (int i=0; i <= 3; i++) // run loop 5 times
{
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);

digitalWrite(4, HIGH);
delay(500);
digitalWrite(1, HIGH);
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(9, HIGH);
digitalWrite(11, HIGH);
delay(200);
digitalWrite(0, HIGH);
digitalWrite(2, HIGH);
digitalWrite(6, HIGH);
digitalWrite(8, HIGH);
delay(500);
// all off
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);

}
for (int i=0; i <= 4; i++) // run loop 4 times
{
digitalWrite(5, LOW);
digitalWrite(8, LOW);

digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(6, HIGH);
delay(300);
digitalWrite(3, LOW);
digitalWrite(0, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
delay(300);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
delay(300);
}
}
}



17 comentarios:

  1. y cuales son als librerias help me!! es q lo estoy usando como proyecto final

    ResponderEliminar
    Respuestas
    1. Hola amigo este código según veo es 100% libre de librerías es código originario del Arduino que puedes modificar a tu gusto

      Eliminar
    2. Este comentario ha sido eliminado por el autor.

      Eliminar
  2. Genial, ya lo hice funcionar, gracias!!!

    ResponderEliminar
  3. excelente aporte funcionando en 2016

    ResponderEliminar
  4. solo me enciende el nivel uno, ¿a que se debe?, porfa gracias

    ResponderEliminar
    Respuestas
    1. Fijate si estás haciendo bien las conexiones a las salidas declaradas para cada nivel, si miras las salidas son 9/10/11 trata de que coincida para que haga bien el efecto de luces saludos

      Eliminar
  5. Trato de cargarlo a mi arduino Mega pero me marca un montón de errores en el código, que puedo hacer?

    ResponderEliminar
  6. al gun codigo para que paresca que esta llovindo

    ResponderEliminar
  7. excelente pero solo me prende en nivel uno
    creo que algo hice mal :v

    ResponderEliminar
  8. Algun codigo que tengas que me puedas proporcionar pero para que me de letras?

    ResponderEliminar
  9. Les dejo el código adaptado al diagrama que muestra.

    void setup() {
    // initialize the digital pin as an output.
    pinMode(1, OUTPUT);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT); // LEDs verdes
    pinMode(11, OUTPUT); // LEDs amarillos
    pinMode(12, OUTPUT); // LEDs rojos

    }

    void loop() {
    digitalWrite(10, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(12, HIGH);

    for (int i=0; i <= 3; i++) // run loop 6 times
    {
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    delay(300);
    digitalWrite(4, LOW);
    digitalWrite(6, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(7, HIGH);
    delay(300);
    digitalWrite(3, LOW);
    digitalWrite(7, LOW);
    digitalWrite(2, HIGH);
    digitalWrite(8, HIGH);
    delay(300);
    digitalWrite(2, LOW);
    digitalWrite(8, LOW);
    digitalWrite(1, HIGH);
    digitalWrite(9, HIGH);
    delay(300);
    digitalWrite(1, LOW);
    digitalWrite(9, LOW);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    delay(300);
    digitalWrite(4, LOW);
    digitalWrite(6, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(7, HIGH);
    delay(300);
    digitalWrite(3, LOW);
    digitalWrite(7, LOW);
    digitalWrite(2, HIGH);
    digitalWrite(8, HIGH);
    delay(300);
    digitalWrite(2, LOW);
    digitalWrite(8, LOW);
    digitalWrite(1, HIGH);
    digitalWrite(9, HIGH);
    delay(300);
    digitalWrite(1, LOW);
    digitalWrite(9, LOW); //cambiados//

    }

    for (int i=0; i <= 3; i++) // run loop 4 times
    {
    byte pins[] = {1, 2, 3, 6, 9, 8, 7, 4};
    // above array of 8
    {
    for (int i=0; i <= 3; i++) // run loop 3 times
    {
    byte level[] = {12, 11, 10};
    for(int i=0; i<=2; i++) // loop equals number
    { // of values in array
    digitalWrite(level[i], HIGH); // write index value

    for(int i=0; i<=7; i++) // loop equals number
    { // of values in array
    digitalWrite(pins[i], HIGH); // write index value
    delay(200); // pause 200ms
    digitalWrite(pins[i], LOW); // write index value
    }
    digitalWrite(level[i], LOW); // write index value

    }
    }
    }

    digitalWrite(10, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(12, HIGH);

    for (int i=0; i <= 4; i++) // run loop 4 times
    {

    digitalWrite(1, HIGH);
    delay(300);

    digitalWrite(5, HIGH);
    delay(300);

    digitalWrite(9, HIGH);
    delay(300);
    digitalWrite(5, LOW);
    delay(400);

    digitalWrite(7, HIGH);
    delay(300);

    digitalWrite(5, HIGH);
    delay(300);
    digitalWrite(3, HIGH);
    delay(300);
    digitalWrite(5, LOW);
    delay(400);


    digitalWrite(4, HIGH);
    delay(300);

    digitalWrite(5, HIGH);
    delay(300);

    digitalWrite(6, HIGH);
    delay(300);
    digitalWrite(5, LOW);
    delay(400);


    digitalWrite(8, HIGH);
    delay(300);

    digitalWrite(5, HIGH);
    delay(300);

    digitalWrite(2, HIGH);
    delay(300);


    digitalWrite(1, LOW);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    delay(200);
    }

    digitalWrite(10, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(12, HIGH);

    for (int i=0; i <= 3; i++) // run loop 5 times
    {
    digitalWrite(10, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(12, LOW);

    digitalWrite(5, HIGH);
    delay(500);
    digitalWrite(2, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(8, HIGH);
    delay(200);
    digitalWrite(10, HIGH);
    digitalWrite(12, HIGH);
    delay(200);
    digitalWrite(1, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(9, HIGH);
    delay(500);
    // all off
    digitalWrite(1, LOW);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);

    }
    for (int i=0; i <= 4; i++) // run loop 4 times
    {
    digitalWrite(6, LOW);
    digitalWrite(9, LOW);

    digitalWrite(1, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    delay(300);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    digitalWrite(7, HIGH);
    delay(300);
    digitalWrite(4, LOW);
    digitalWrite(1, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    delay(300);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(6, HIGH);
    delay(300);
    }
    }
    }

    ResponderEliminar
  10. Gracias por compartir iniciandome en arduino veremos que tal. 🤟😎

    ResponderEliminar
  11. The Casinos Near Harrah's Cherokee Casino Resort
    Closest casinos to Harrah's Cherokee Casino Resort in Cherokee. 의정부 출장안마 MapYOGA.com 경산 출장마사지 only has a 안산 출장안마 short drive 화성 출장안마 from 춘천 출장마사지 Harrah's Cherokee Casino Resort.

    ResponderEliminar