Thông báo

Collapse
No announcement yet.

Lập trình cho led Cube 8x8x8

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • #16
    mình cũng đã làm thử với 5x5x5 nhưng cũng bị hiện tượng đó. 2 lớp thì không có vấn đề nhừng lơn hơn là thì lại bị thế... mong các bác giúp đỡ

    Comment


    • #17
      Do led chất kém đó bạn , mình cũng gặp phải rồi thường thì thay tất cả cho nhanh . Trước khi mua lấy đồng hồ kim ra đo , led đểu đo 2 chiều lên kim hết

      Comment


      • #18
        mình cũng nghi là do led nhưng mình thử từng led 1 thì sáng ngon mà... hày là do trong lúc hàn nó nóng quá chiu không nổi?

        Comment


        • #19
          mình đothuwe rồi không sao chỉ khi hàn xong đo lại thì có bị thật

          Comment


          • #20
            Quên k nhắc ae trong quá trình hàn thì nên ngồi trên giường hay chỗ nào mà chân không chạm đất . Trước đây mình hàn bằng mỏ hàn nung rất nhiều led bị cháy mà k hiểu lý do mặc dù trước đó mình đã đo chọn led rồi . Rất có thể mỏ hàn dò điện theo chân người xuống đất tạo thành dòng làm cháy led đó.

            Comment


            • #21
              LED cùi vẫn chạy ngon nhé ! quan trọng là chất lượng LED phải đồng đều....

              Comment


              • #22
                bác oriondn chi rúp em cách làm thế nào mà led cùi vẫn chạy được cái. sau khi em hàn xong lấy đồng hồ đo thì thấy cả 2 chiều đều có điện trở. bác chỉ em cách khắc phục cái..

                Comment


                • #23
                  Mình đã làm thành công led cube 8x8x8 với nhiều hiệu ứng đẹp. Bây giờ minh đang làm lại led cube kích thước 10x10x10, đã mô phỏng xong.Thực ra làm led cube không khó, thậm chí là dễ.Khi làm led cỡ 8x8x8 mình có một vài vấn đề về vật liệu làm khung led cần mọi người giúp.Nếu ai giúp mình mình có thể cho sơ đồ Orcad cube 8x8x8.
                  Mọi người có thể cho mình hỏi có loại led nào 5mm, trong suốt mà sáng đều các mặt như led đục không ?.
                  Thứ 2 là mình cần vật liệu làm khung led cube.Khung led cube 8x8x8 mình làm bằng thép nhưng hàn không dính, sau đó mình làm bằng dây quấn máy biến áp sau khi đã cạo
                  lớp cách điện thì hàn dính nhưng nó có màu đỏ nên xấu. Mọi người cho mình hỏi có loại dây nào màu bạc như chân led mà hàn chì dính không

                  Comment


                  • #24
                    thấy họ làm bằng thanh thép mà.
                    https://sites.google.com/site/led3dc...am-khung-led3d

                    Comment


                    • #25
                      bác có axit chấm vào mối hàn là hàn được!

                      Comment


                      • #26
                        #include "effect.h"
                        #include "draw.h"
                        #include "font.h"
                        #include <string.h>
                        #include <math.h>
                        #include <avr/interrupt.h>
                        void sendvoxel_z (unsigned char x, unsigned char y, unsigned char z, int delay) {
                        int i, ii;
                        for (i = 0; i < 8; i++) {
                        if (z == 7) {
                        ii = 7-i;
                        clrvoxel(x,y,ii+1);
                        } else {
                        ii = i;
                        clrvoxel(x,y,ii-1);
                        }
                        setvoxel(x,y,ii);
                        delay_ms(delay);
                        }
                        }

                        // Send all the voxels from one side of the cube to the other
                        // Start at z and send to the opposite side.
                        // Sends in random order.
                        void sendplane_rand_z (unsigned char z, int delay, int wait) {
                        unsigned char loop = 16;
                        unsigned char x, y;

                        fill(0x00);

                        setplane_z(z);

                        // Send voxels at random untill all 16 have crossed the cube.
                        while(loop) {
                        x = rand()%4;
                        y = rand()%4;
                        if (getvoxel(x,y,z)) {
                        // Send the voxel flying
                        sendvoxel_z(x,y,z,delay);
                        delay_ms(wait);
                        loop--; // one down, loop-- to go. when this hits 0, the loop exits.
                        }
                        }
                        }

                        // For each coordinate along X and Y, a voxel is set either at level 0 or at level 7
                        // for n iterations, a random voxel is sent to the opposite side of where it was.
                        void effect_loop_sendvoxels_rand_z(int delay, int wait) {
                        unsigned char x, y, last_x = 0, last_y = 0;

                        fill(0x00);

                        // Loop through all the X and Y coordinates
                        for (x = 0; x < 8; x++) {
                        for (y = 0; y < 8; y++) {
                        // Then set a voxel either at the top or at the bottom
                        // rand()%2 returns either 0 or 1. multiplying by 7 gives either 0 or 7.
                        setvoxel(x,y,((rand()%2)*7));
                        }
                        }

                        while (1) {
                        // Pick a random x,y position
                        x = rand()%8;
                        y = rand()%8;
                        // but not the sameone twice in a row
                        if (y != last_y && x != last_x) {
                        if (getvoxel(x,y,0)) // If the voxel at this x,y is at the bottom
                        sendvoxel_z(x,y,0,delay); // send it to the top
                        else // else
                        sendvoxel_z(x,y,7,delay); // if its at the top, send it to the bottom

                        delay_ms(wait);
                        LED_PORT ^= LED_GREEN;

                        // Remember the last move
                        last_y = y;
                        last_x = x;
                        }

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }


                        // Big ugly function but it looks pretty
                        void effect_loop_boingboing(int delay, unsigned char mode, unsigned char drawmode) {
                        fill(0x00); // Blank the cube

                        int x = rand()%8, y = rand()%8, z = rand()%8; // Current coordinates for the point
                        int dx = 1, dy = 1, dz = 1; // Direction of movement
                        int axis_id, i;
                        unsigned char crash_x, crash_y, crash_z;

                        // Coordinate array for the snake.
                        int snake[8][3];
                        for (i = 0; i < 8; i++) {
                        snake[i][0] = x;
                        snake[i][1] = y;
                        snake[i][2] = z;
                        }

                        while (1) {
                        crash_x = 0;
                        crash_y = 0;
                        crash_z = 0;


                        // Let's mix things up a little:
                        if (rand()%3 == 0) {
                        // Pick a random axis, and set the speed to a random number.
                        axis_id = rand()%3;
                        if (axis_id == 0)
                        dx = rand()%3 - 1;

                        if (axis_id == 1)
                        dy = rand()%3 - 1;

                        if (axis_id == 2)
                        dz = rand()%3 - 1;
                        }

                        // x-axis crash
                        if ((dx == -1 && x == 0) || (dx == 1 && x == 7)) {
                        LED_PORT ^= LED_GREEN;
                        crash_x = 0x01;
                        if (rand()%3 == 1)
                        dx = (x == 7) ? -1 : 1;
                        else
                        dx = 0;
                        }

                        // y-axis crash
                        if ((dy == -1 && y == 0) || (dy == 1 && y == 7)) {
                        LED_PORT ^= LED_GREEN;
                        crash_y = 0x01;
                        if (rand()%3 == 1)
                        dy = (y == 7) ? -1 : 1;
                        else
                        dy = 0;
                        }

                        // z axis 0 crash
                        if ((dz == -1 && z == 0) || (z == 1 && z == 7)) {
                        LED_PORT ^= LED_GREEN;
                        crash_z = 0x01;
                        if (rand()%3 == 1)
                        dz = (z == 7) ? -1 : 1;
                        else
                        dz = 0;
                        }

                        // mode bit 0 sets crash action enable
                        if (mode | 0x01) {
                        if (crash_x) {
                        if (dy == 0) {
                        if (y == 7) {
                        dy = -1;
                        } else if (y == 0) {
                        dy = +1;
                        } else {
                        if (rand()%2 == 0)
                        dy = -1;
                        else
                        dy = 1;
                        }
                        }
                        if (dz == 0) {
                        if (z == 7) {
                        dz = -1;
                        } else if (z == 0) {
                        dz = 1;
                        } else {
                        if (rand()%2 == 0)
                        dz = -1;
                        else
                        dz = 1;
                        }
                        }
                        }

                        if (crash_y) {
                        if (dx == 0) {
                        if (x == 7) {
                        dx = -1;
                        } else if (x == 0) {
                        dx = 1;
                        } else {
                        if (rand()%2 == 0)
                        dx = -1;
                        else
                        dx = 1;
                        }
                        }
                        if (dz == 0) {
                        if (z == 3) {
                        dz = -1;
                        } else if (z == 0) {
                        dz = 1;
                        } else {
                        if (rand()%2 == 0)
                        dz = -1;
                        else
                        dz = 1;
                        }
                        }
                        }

                        if (crash_z) {
                        if (dy == 0) {
                        if (y == 7) {
                        dy = -1;
                        } else if (y == 0) {
                        dy = 1;
                        } else {
                        if (rand()%2 == 0)
                        dy = -1;
                        else
                        dy = 1;
                        }
                        }
                        if (dx == 0) {
                        if (x == 7) {
                        dx = -1;
                        } else if (x == 0) {
                        dx = 1;
                        } else {
                        if (rand()%2 == 0)
                        dx = -1;
                        else
                        dx = 1;
                        }
                        }
                        }
                        }

                        // mode bit 1 sets corner avoid enable
                        if (mode | 0x02) {
                        if ( // We are in one of 8 corner positions
                        (x == 0 && y == 0 && z == 0) ||
                        (x == 0 && y == 0 && z == 7) ||
                        (x == 0 && y == 7 && z == 0) ||
                        (x == 0 && y == 7 && z == 7) ||
                        (x == 7 && y == 0 && z == 0) ||
                        (x == 7 && y == 0 && z == 7) ||
                        (x == 7 && y == 7 && z == 0) ||
                        (x == 7 && y == 7 && z == 7)
                        ) {
                        // At this point, the voxel would bounce
                        // back and forth between this corner,
                        // and the exact opposite corner
                        // We don't want that!

                        // So we alter the trajectory a bit,
                        // to avoid corner stickyness
                        axis_id = rand()%3;
                        if (axis_id == 0)
                        dx = 0;

                        if (axis_id == 1)
                        dy = 0;

                        if (axis_id == 2)
                        dz = 0;
                        }
                        }
                        // one last sanity check
                        if (x == 0 && dx == -1)
                        dx = 1;

                        if (y == 0 && dy == -1)
                        dy = 1;

                        if (z == 0 && dz == -1)
                        dz = 1;

                        if (x == 7 && dx == 1)
                        dx = -1;

                        if (y == 7 && dy == 1)
                        dy = -1;

                        if (z == 7 && dz == 1)
                        dz = -1;


                        // Finally, move the voxel.
                        x = x + dx;
                        y = y + dy;
                        z = z + dz;

                        if (drawmode == 0x01) { // show one voxel at time
                        setvoxel(x,y,z);
                        delay_ms(delay);
                        clrvoxel(x,y,z);
                        } else if (drawmode == 0x02) { // flip the voxel in question
                        flpvoxel(x,y,z);
                        delay_ms(delay);
                        } if (drawmode == 0x03) { // draw a snake
                        for (i=7;i>=0;i--) {
                        snake[i][0] = snake[i-1][0];
                        snake[i][1] = snake[i-1][1];
                        snake[i][2] = snake[i-1][2];
                        }
                        snake[0][0] = x;
                        snake[0][1] = y;
                        snake[0][2] = z;

                        for (i = 0; i < 8; i++)
                        setvoxel(snake[i][0],snake[i][1],snake[i][2]);

                        delay_ms(delay);

                        for (i = 0; i < 8; i++)
                        clrvoxel(snake[i][0],snake[i][1],snake[i][2]);
                        }

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }

                        void effect_loop_rain(void) {
                        int i;
                        int rnd_x, rnd_y, rnd_num;

                        while (1) {
                        rnd_num = rand()%4;

                        for (i = 0; i < rnd_num; i++) {
                        rnd_x = rand()%8;
                        rnd_y = rand()%8;
                        setvoxel(rnd_x,rnd_y,7);
                        }

                        LED_PORT ^= LED_GREEN; // Green toggle

                        delay_ms(775);
                        shift(AXIS_Z,-1);

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }

                        void effect_loop_z_updown(int delay) {
                        unsigned char positions[64];
                        unsigned char destinations[64];

                        int i, y, move;

                        for (i = 0; i < 64; i++) {
                        positions[i] = 4;
                        destinations[i] = rand()%8;
                        }

                        for (i = 0; i < 8; i++) {
                        effect_z_updown_move(positions, destinations, AXIS_Z);
                        delay_ms(delay);
                        }

                        while (1) {
                        for (move = 0; move < 8; move++) {
                        effect_z_updown_move(positions, destinations, AXIS_Z);
                        delay_ms(delay);
                        }

                        delay_ms(delay*4);
                        LED_PORT ^= LED_GREEN;

                        for (y = 0; y < 32; y++)
                        destinations[rand()%64] = rand()%8;

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }

                        }

                        void effect_z_updown_move (unsigned char positions[64], unsigned char destinations[64], char axis)
                        {
                        int px;
                        for (px=0; px<64; px++)
                        {
                        if (positions[px]<destinations[px])
                        {
                        positions[px]++;
                        }
                        if (positions[px]>destinations[px])
                        {
                        positions[px]--;
                        }
                        }

                        draw_positions_axis (AXIS_Z, positions,0);
                        }

                        void effect_loop_wall_to_wall(int delay, int sleep) {

                        int i;
                        unsigned char positions[64];

                        // Set 64 random positions
                        for (i = 0; i < 64; i++)
                        positions[i] = rand()%8;

                        // Draw the positions from a random axis
                        switch (rand()%3) {
                        case 0:
                        draw_positions_axis(AXIS_X, positions, rand()%2);
                        break;
                        case 1:
                        draw_positions_axis(AXIS_Y, positions, rand()%2);
                        break;
                        case 2:
                        draw_positions_axis(AXIS_Z, positions, rand()%2);
                        break;
                        }



                        }

                        void effect_wall_to_wall(char axis_from, int invert_from,
                        char axis_to, int invert_to,
                        int delay, int sleep) {

                        int i, px;
                        int x, y;
                        int to, from;

                        int val_from[8];
                        int val_to[8];
                        unsigned char positions[64];
                        unsigned char transition_from[64];
                        unsigned char transition_to[64];

                        fill(0x00);
                        setplane(axis_from, invert_from ? 7 : 0);

                        // Generate transition maps
                        for (x = 0; x < 8; x++) {
                        for (i = 0; i < 8; i++) {
                        val_from[i] = 0;
                        val_to[i] = 0;
                        }

                        for (y = 0; y < 8; y++) {

                        to = rand()%8;//(y+3)%8;//rand()%8;//(y+x)%8;//
                        from = rand()%8;//(y+x)%8;//rand()%8;//(y+3)%8;//

                        if (val_from[from] || val_to[to])
                        y--;
                        else {
                        if (axis_from == AXIS_X && axis_to == AXIS_Y) {
                        transition_from[x * 8 + from] = to;
                        transition_to[((invert_from) ? 7 - to : to) * 8 + x] = (invert_to) ? 7 - from: from;
                        }

                        if (axis_from == AXIS_Y && axis_to == AXIS_X) {
                        transition_from[from * 8 + x] = to;
                        transition_to[x * 8 + ((invert_from) ? 7 - to : to)] = ((invert_to) ? 7 - from : from);
                        }

                        if (axis_from == AXIS_X && axis_to == AXIS_Z) {
                        transition_from[from * 8 + x] = to;
                        transition_to[((invert_from) ? 7 - to : to) * 8 + x] = (invert_to) ? 7 - from: from;
                        }

                        if (axis_from == AXIS_Z && axis_to == AXIS_X) {






                        transition_from[x * 8 + from] = to;
                        transition_to[x * 8 + ((invert_from) ? 7 - to : to)] = ((invert_to) ? 7 - from : from);
                        }






                        positions[x * 8 + y] = 0;
                        val_from[from] = 1;
                        val_to[to] = 1;
                        }
                        }
                        }

                        // asdf
                        for (i = 0; i < 8; i++) {
                        for (px = 0; px < 64; px++) {
                        if (positions[px] < transition_from[px])
                        positions[px]++;
                        if (positions[px] > transition_from[px])
                        positions[px]--;
                        }
                        draw_positions_axis(axis_from, positions, invert_from);
                        delay_ms(delay);
                        }


                        delay_ms(10000);
                        delay_ms(10000);
                        delay_ms(10000);
                        //fill(0x00);

                        for (i = 0; i < 64; i++)
                        positions[i] = transition_to[i];

                        draw_positions_axis(axis_to, positions, invert_to);

                        delay_ms(delay);


                        for (i = 0; i < 8; i++) {
                        for (px = 0; px < 64; px++) {
                        if (positions[px] < 7)
                        positions[px]++;
                        if (positions[px] > 7)
                        positions[px]--;
                        }
                        draw_positions_axis(axis_to, positions, invert_to);
                        delay_ms(delay);
                        }


                        delay_ms(10000);
                        fill(0x00);
                        }


                        void effect_axis_updown_randsuspend(char axis, int delay, int sleep, int invert) {
                        unsigned char positions[64];
                        unsigned char destinations[64];

                        int i,px;

                        // Set 64 random positions
                        for (i = 0; i < 64; i++) {
                        positions[i] = 0; // Set all starting positions to 0
                        destinations[i] = rand()%8;
                        }

                        // Loop 8 times to allow destination 7 to reach all the way
                        for (i = 0; i < 8; i++) {
                        // For every iteration, move all position one step closer to their destination
                        for (px = 0; px < 64; px++) {
                        if (positions[px] < destinations[px]) {
                        positions[px]++;
                        }
                        }

                        // Draw the positions and take a nap
                        draw_positions_axis (axis, positions, invert);
                        delay_ms(delay);
                        }

                        // Set all destinations to 7 (opposite from the side they started out)
                        for (i = 0; i < 64; i++)
                        destinations[i] = 7;

                        // Suspend the positions in mid-air for a while
                        delay_ms(sleep);

                        // Then do the same thing one more time
                        for (i=0; i<8; i++) {
                        for (px=0; px<64; px++) {
                        if (positions[px] < destinations[px])
                        positions[px]++;
                        if (positions[px] > destinations[px])
                        positions[px]--;
                        }
                        draw_positions_axis(axis, positions, invert);
                        delay_ms(delay);
                        }
                        }

                        // If fade is > 0, the side fades in, otherwise it fades out
                        void boxside_fade(char axis, int origin, int fade) {
                        int x, y, p, done = 0;

                        if (fade > 0) {
                        p = (origin) ? 7 : 0;
                        fill(0x00);
                        } else if (fade < 0) {
                        p = (origin) ? 0 : 7;
                        if (axis == AXIS_X)
                        setplane(AXIS_X, p);
                        else if (axis == AXIS_Y)
                        setplane(AXIS_Y, p);
                        else if (axis == AXIS_Z)
                        setplane(AXIS_Z, p);
                        } else
                        return;

                        while (done < 64) {
                        x = rand()%8;
                        y = rand()%8;

                        if (axis == AXIS_Z)
                        done += (fade > 0) ? confirmaltervoxel(x, y, p, 1): confirmaltervoxel(x, y, p, 0);
                        else if (axis == AXIS_Y)
                        done += (fade > 0) ? confirmaltervoxel(x, p, y, 1): confirmaltervoxel(x, p, y, 0);
                        else if (axis == AXIS_X)
                        done += (fade > 0) ? confirmaltervoxel(p, y, x, 1): confirmaltervoxel(p, y, x, 0);

                        delay_ms(75);

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }

                        void draw_positions_axis(char axis, unsigned char positions[64], int invert) {
                        int x, y, p;

                        fill(0x00);

                        for (x = 0; x < 8; x++) {
                        for (y = 0; y < 8; y++) {
                        if (invert)
                        p = (7-positions[(x*8)+y]);
                        else
                        p = positions[(x*8)+y];

                        if (axis == AXIS_Z)
                        setvoxel(x,y,p);

                        if (axis == AXIS_Y)
                        setvoxel(x,p,y);

                        if (axis == AXIS_X)
                        setvoxel(p,y,x);
                        }
                        }
                        }

                        void effect_boxside_randsend_parallel(char axis, int origin, int delay, int mode, int fade) {
                        int i;
                        int done;
                        unsigned char cubepos[64];
                        unsigned char pos[64];
                        int notdone = 1;
                        int notdone2 = 1;
                        int sent = 0;

                        for (i = 0; i < 64; i++)
                        pos[i] = 0;

                        if (fade == 1)
                        boxside_fade(axis, origin, fade);

                        while (notdone) {
                        if (mode == 1) {
                        notdone2 = 1;
                        while (notdone2 && sent < 64) {
                        i = rand()%64;
                        if (pos[i] == 0) {
                        sent++;
                        pos[i] += 1;
                        notdone2 = 0;
                        }
                        }
                        } else if (mode == 2) {
                        if (sent < 64) {
                        pos[sent] += 1;
                        sent++;
                        }
                        }

                        done = 0;
                        for (i = 0; i < 64; i++) {
                        if (pos[i] > 0 && pos[i] < 7)
                        pos[i] += 1;

                        if (pos[i] == 7)
                        done++;
                        }

                        if (done == 64)
                        notdone = 0;

                        for (i = 0; i < 64; i++) {
                        if (origin == 0)
                        cubepos[i] = pos[i];
                        else
                        cubepos[i] = (7-pos[i]);
                        }

                        delay_ms(delay);
                        draw_positions_axis(axis,cubepos,0);
                        LED_PORT ^= LED_GREEN;

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }

                        if (fade == -1)
                        boxside_fade(axis, origin, fade);
                        }

                        void effect_loop_boxside_randsend_parallel(void) {
                        int i;

                        while (1) {
                        i = rand()%12;

                        switch (i) {
                        case 0:
                        effect_boxside_randsend_parallel(AXIS_X, 0, 200, 1, 1);
                        delay_ms(1500);
                        effect_boxside_randsend_parallel(AXIS_X, 1, 200, 1, -1);
                        delay_ms(1500);
                        break;
                        case 1:
                        effect_boxside_randsend_parallel(AXIS_X, 1, 200, 1, 1);
                        delay_ms(1500);
                        effect_boxside_randsend_parallel(AXIS_X, 0, 200, 1, -1);
                        delay_ms(1500);
                        break;
                        case 2:
                        effect_boxside_randsend_parallel(AXIS_Y, 0, 200, 1, 1);
                        delay_ms(1500);
                        effect_boxside_randsend_parallel(AXIS_Y, 1, 200, 1, -1);
                        delay_ms(1500);
                        break;
                        case 3:
                        effect_boxside_randsend_parallel(AXIS_Y, 1, 200, 1, 1);
                        delay_ms(1500);
                        effect_boxside_randsend_parallel(AXIS_Y, 0, 200, 1, -1);
                        delay_ms(1500);
                        break;
                        case 4:
                        effect_boxside_randsend_parallel(AXIS_Z, 0, 200, 1, 1);
                        delay_ms(1500);
                        effect_boxside_randsend_parallel(AXIS_Z, 1, 200, 1, -1);
                        delay_ms(1500);
                        break;
                        case 5:
                        effect_boxside_randsend_parallel(AXIS_Z, 1, 200, 1, 1);
                        delay_ms(1500);
                        effect_boxside_randsend_parallel(AXIS_Z, 0, 200, 1, -1);
                        delay_ms(1500);
                        break;
                        case 6:
                        effect_boxside_randsend_parallel(AXIS_X, 0, 200, 1, 1);
                        boxside_fade(AXIS_X, 0, -1);
                        break;
                        case 7:
                        effect_boxside_randsend_parallel(AXIS_X, 1, 200, 1, 1);
                        boxside_fade(AXIS_X, 1, -1);
                        break;
                        case 8:
                        effect_boxside_randsend_parallel(AXIS_Y, 0, 200, 1, 1);
                        boxside_fade(AXIS_Y, 0, -1);
                        break;
                        case 9:
                        effect_boxside_randsend_parallel(AXIS_Y, 1, 200, 1, 1);
                        boxside_fade(AXIS_Y, 1, -1);
                        break;
                        case 10:
                        effect_boxside_randsend_parallel(AXIS_Z, 0, 200, 1, 1);
                        boxside_fade(AXIS_Z, 0, -1);
                        break;
                        case 11:
                        effect_boxside_randsend_parallel(AXIS_Z, 1, 200, 1, 1);
                        boxside_fade(AXIS_Z, 1, -1);
                        break;
                        }

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }


                        // Light all leds layer by layer,
                        // then unset layer by layer
                        void effect_loadbar(int delay)
                        {
                        fill(0x00);

                        int z,y;

                        for (z=0;z<8;z++)
                        {
                        for (y=0;y<8;y++)
                        cube[z][y] = 0xff;

                        delay_ms(delay);
                        }

                        delay_ms(delay*3);

                        for (z=0;z<8;z++)
                        {
                        for (y=0;y<8;y++)
                        cube[z][y] = 0x00;

                        delay_ms(delay);
                        }
                        }


                        // Set n number of voxels at random positions
                        void effect_random_sparkle_flash(int iterations, int voxels, int delay) {
                        int i;
                        int v;
                        for (i = 0; i < iterations; i++) {
                        for (v = 0; v <= voxels; v++)
                        setvoxel(rand()%8, rand()%8, rand()%8);

                        delay_ms(delay);
                        fill(0x00);

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }

                        /* Set a random target number of voxels to blink. Move the actual number of
                        * blinking voxels towards that number in single steps. Once reached, pick a
                        * new target randomly.
                        */
                        void effect_loop_random_sparkle(int max_led_count) {
                        int target = rand()%max_led_count, count = rand()%max_led_count;

                        while (1) {
                        if (count < target)
                        count++;
                        else
                        count--;

                        effect_random_sparkle_flash(5, count, 200);

                        if (count == target)
                        target = rand()%max_led_count;

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }

                        int effect_telcstairs_do(int x, int val, int delay)
                        {
                        int y,z;

                        for(y = 0, z = x; y <= z; y++, x--)
                        {
                        if(x < CUBE_SIZE && y < CUBE_SIZE)
                        {
                        cube[x][y] = val;
                        }
                        }
                        delay_ms(delay);
                        return z;
                        }

                        void effect_telcstairs (int invert, int delay, int val)
                        {
                        int x;

                        if(invert)
                        {
                        for(x = CUBE_SIZE*2; x >= 0; x--)
                        {
                        x = effect_telcstairs_do(x,val,delay);
                        }
                        }
                        else
                        {
                        for(x = 0; x < CUBE_SIZE*2; x++)
                        {
                        x = effect_telcstairs_do(x,val,delay);
                        }
                        }
                        }

                        void effect_wormsqueeze (int size, int axis, int direction, int iterations, int delay)
                        {
                        int x, y, i,j,k, dx, dy;
                        int cube_size;
                        int origin = 0;

                        if (direction == -1)
                        origin = 7;

                        cube_size = 8-(size-1);

                        x = rand()%cube_size;
                        y = rand()%cube_size;

                        for (i=0; i<iterations; i++)
                        {
                        dx = ((rand()%3)-1);
                        dy = ((rand()%3)-1);

                        if ((x+dx) > 0 && (x+dx) < cube_size)
                        x += dx;

                        if ((y+dy) > 0 && (y+dy) < cube_size)
                        y += dy;

                        shift(axis, direction);


                        for (j=0; j<size;j++)
                        {
                        for (k=0; k<size;k++)
                        {
                        if (axis == AXIS_Z)
                        setvoxel(x+j,y+k,origin);

                        if (axis == AXIS_Y)
                        setvoxel(x+j,origin,y+k);

                        if (axis == AXIS_X)
                        setvoxel(origin,y+j,x+k);
                        }
                        }

                        delay_ms(delay);
                        }
                        }

                        void effect_smileyspin (int count, int delay, char bitmap)
                        {
                        unsigned char dybde[] = {0,1,2,3,4,5,6,7,1,1,2,3,4,5,6,6,2,2,3,3,4,4,5,5,3 ,3,3,3,4,4,4,4};
                        int d = 0;
                        int flip = 0;
                        int x, y, off;
                        for(int i = 0; i<count; i++)
                        {
                        flip = 0;
                        d = 0;
                        off = 0;
                        // front:
                        for (int s=0;s<7;s++){
                        if(!flip){
                        off++;
                        if (off == 4){
                        flip = 1;
                        off = 0;
                        }
                        } else {
                        off++;
                        }
                        for (x=0; x<8; x++)
                        {
                        d = 0;
                        for (y=0; y<8; y++)
                        {
                        if (font_getbitmappixel ( bitmap, 7-x, y)){
                        if (!flip)
                        setvoxel(y,dybde[8 * off + d++],x);
                        else
                        setvoxel(y,dybde[31 - 8 * off - d++],x);
                        } else {
                        d++;
                        }
                        }
                        }
                        delay_ms(delay);
                        fill(0x00);
                        }

                        // side:
                        off = 0;
                        flip = 0;
                        d = 0;
                        for (int s=0;s<7;s++){
                        if(!flip){
                        off++;
                        if (off == 4){
                        flip = 1;
                        off = 0;
                        }
                        } else {
                        off++;
                        }
                        for (x=0; x<8; x++)
                        {
                        d = 0;
                        for (y=0; y<8; y++)
                        {
                        if (font_getbitmappixel ( bitmap, 7-x, y)){
                        if (!flip)
                        setvoxel(dybde[8 * off + d++], 7 - y,x);
                        else
                        setvoxel(dybde[31 - 8 * off - d++],7 - y,x);
                        } else {
                        d++;
                        }
                        }
                        }
                        delay_ms(delay);
                        fill(0x00);
                        }


                        flip = 0;
                        d = 0;
                        off = 0;
                        // back:
                        for (int s=0;s<7;s++){
                        if(!flip){
                        off++;
                        if (off == 4){
                        flip = 1;
                        off = 0;
                        }
                        } else {
                        off++;
                        }
                        for (x=0; x<8; x++)
                        {
                        d = 0;
                        for (y=0; y<8; y++)
                        {
                        if (font_getbitmappixel ( bitmap, 7-x, 7-y)){
                        if (!flip)
                        setvoxel(y,dybde[8 * off + d++],x);
                        else
                        setvoxel(y,dybde[31 - 8 * off - d++],x);
                        } else {
                        d++;
                        }
                        }
                        }
                        delay_ms(delay);
                        fill(0x00);
                        }

                        // other side:
                        off = 0;
                        flip = 0;
                        d = 0;
                        for (int s=0;s<7;s++){
                        if(!flip){
                        off++;
                        if (off == 4){
                        flip = 1;
                        off = 0;
                        }
                        } else {
                        off++;
                        }
                        for (x=0; x<8; x++)
                        {
                        d = 0;
                        for (y=0; y<8; y++)
                        {
                        if (font_getbitmappixel ( bitmap, 7-x, 7-y)){
                        if (!flip)
                        setvoxel(dybde[8 * off + d++], 7 - y,x);
                        else
                        setvoxel(dybde[31 - 8 * off - d++],7 - y,x);
                        } else {
                        d++;
                        }
                        }
                        }
                        delay_ms(delay);
                        fill(0x00);
                        }

                        }
                        }


                        void effect_pathmove (unsigned char *path, int length)
                        {
                        int i,z;
                        unsigned char state;

                        for (i=(length-1);i>=1;i--)
                        {
                        for (z=0;z<8;z++)
                        {

                        state = getvoxel(((path[(i-1)]>>4) & 0x0f), (path[(i-1)] & 0x0f), z);
                        altervoxel(((path[i]>>4) & 0x0f), (path[i] & 0x0f), z, state);
                        }
                        }
                        for (i=0;i<8;i++)
                        clrvoxel(((path[0]>>4) & 0x0f), (path[0] & 0x0f),i);
                        }

                        void effect_loop_rand_patharound(int delay) {
                        int z, dz;
                        z = 4;
                        unsigned char path[28];

                        font_getpath(0,path,28);

                        while (1) {
                        dz = ((rand()%3)-1);
                        z += dz;

                        if (z > 7)
                        z = 7;

                        if (z < 0)
                        z = 0;

                        effect_pathmove(path, 28);
                        setvoxel(0,7,z);
                        delay_ms(delay);

                        LED_PORT ^= LED_GREEN;

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }

                        void effect_loop_pathspiral(int delay) {
                        int z, i;
                        i = 0;
                        z = 4;
                        unsigned char path[16];

                        font_getpath(1, path, 16);

                        while (1) {
                        i++;

                        if (i >= 8)
                        i = 0;

                        setvoxel(4,0,i%8);
                        delay_ms(delay);
                        effect_pathmove(path, 28);

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN)) return;
                        }
                        }

                        void effect_path_text (int delay, char *str)
                        {
                        int z, i,ii;
                        z = 4;
                        unsigned char path[28];
                        font_getpath(0,path,28);

                        unsigned char chr[5];
                        unsigned char stripe;

                        while (*str)
                        {
                        //charfly(*str++, direction, axis, mode, delay);


                        font_getchar(*str++, chr);

                        for (ii=0;ii<5;ii++)
                        {
                        //stripe = pgm_read_byte(&font[(chr*5)+ii]);
                        stripe = chr[ii];

                        for (z=0;z<8;z++)
                        {
                        if ((stripe>>(7-z)) & 0x01)
                        {
                        setvoxel(0,7,z);
                        } else
                        {
                        clrvoxel(0,7,z);
                        }

                        }
                        effect_pathmove(path, 28);
                        delay_ms(delay);
                        }

                        effect_pathmove(path, 28);
                        delay_ms(delay);
                        }
                        for (i=0;i<28;i++)
                        {
                        effect_pathmove(path, 28);
                        delay_ms(delay);
                        }
                        }

                        void effect_loop_path_bitmap(int delay, char bitmap) {
                        int z, i;
                        z = 4;
                        unsigned char path[28];
                        font_getpath(0,path,28);

                        while (1) {
                        for (i = 0; i < 8; i++) {
                        for (z = 0; z < 8; z++) {
                        if (font_getbitmappixel(bitmap, (7-z), i))
                        setvoxel(0,7,z);
                        else
                        clrvoxel(0,7,z);
                        }
                        delay_ms(delay);
                        effect_pathmove(path, 28);

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN))
                        return;
                        }

                        for (i = 0; i < 20; i++) {
                        delay_ms(delay);
                        effect_pathmove(path, 28);

                        // Return if a button is pressed
                        if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN))
                        return;
                        }
                        }
                        }

                        Comment


                        • #27
                          1 #include "effect.h"
                          2 #include "draw.h"
                          3 #include "font.h"
                          4 #include <math.h>
                          5 #include <avr/interrupt.h>
                          6
                          7 // Send a voxel flying from one side of the cube to the other
                          8 // If its at the bottom, send it to the top..

                          9 void sendvoxel_z (unsigned char x, unsigned char y, unsigned char z, int delay)
                          10 {
                          11 int i, ii;

                          12 for (i=0; i<8; i++)
                          13 {
                          14 if (z == 7)
                          15 {
                          16 ii = 7-i;
                          17 clrvoxel(x,y,ii+1);

                          18 } else
                          19 {
                          20 ii = i;
                          21 clrvoxel(x,y,ii-1);
                          22 }
                          23 setvoxel(x,y,ii);
                          24 delay_ms(delay);
                          25 }
                          26 }
                          27
                          28 // Send all the voxels from one side of the cube to the other
                          29 // Start at z and send to the opposite side.
                          30 // Sends in random order.

                          31 void sendplane_rand_z (unsigned char z, int delay, int wait)
                          32 {
                          33 unsigned char loop = 16;
                          34 unsigned char x, y;
                          35
                          36 fill(0x00);
                          37
                          38 setplane_z(z);
                          39
                          40 // Send voxels at random untill all 16 have crossed the cube.

                          41 while(loop)
                          42 {
                          43 x = rand()%4;
                          44 y = rand()%4;

                          45 if (getvoxel(x,y,z))
                          46 {
                          47 // Send the voxel flying
                          48 sendvoxel_z(x,y,z,delay);
                          49 delay_ms(wait);
                          50 loop--; // one down, loop-- to go. when this hits 0, the loop exits.
                          51 }
                          52 }
                          53 }
                          54
                          55 // For each coordinate along X and Y, a voxel is set either at level 0 or at level 7
                          56 // for n iterations, a random voxel is sent to the opposite side of where it was.
                          57 void effect_loop_sendvoxels_rand_z(int delay, int wait) {
                          58 unsigned char x, y, last_x = 0, last_y = 0;
                          59
                          60 fill(0x00);
                          61
                          62 // Loop through all the X and Y coordinates
                          63 for (x = 0; x < 8; x++) {
                          64 for (y = 0; y < 8; y++) {
                          65 // Then set a voxel either at the top or at the bottom
                          66 // rand()%2 returns either 0 or 1. multiplying by 7 gives either 0 or 7.
                          67 setvoxel(x,y,((rand()%2)*7));
                          68 }
                          69 }
                          70
                          71 while (1) {
                          72 // Pick a random x,y position
                          73 x = rand()%8;
                          74 y = rand()%8;
                          75 // but not the sameone twice in a row
                          76 if (y != last_y && x != last_x) {
                          77 if (getvoxel(x,y,0)) // If the voxel at this x,y is at the bottom
                          78 sendvoxel_z(x,y,0,delay); // send it to the top
                          79 else // else
                          80 sendvoxel_z(x,y,7,delay); // if its at the top, send it to the bottom
                          81
                          82 delay_ms(wait);
                          83 LED_PORT ^= LED_GREEN;
                          84
                          85 // Remember the last move
                          86 last_y = y;
                          87 last_x = x;
                          88 }
                          89
                          90 // Return if a button is pressed
                          91 if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN))
                          92 return;
                          93 }
                          94 }
                          95
                          96
                          97 // Big ugly function but it looks pretty
                          98 void effect_loop_boingboing(int delay, unsigned char mode, unsigned char drawmode) {
                          99 fill(0x00); // Blank the cube
                          100
                          101 int x, y, z; // Current coordinates for the point
                          102 int dx, dy, dz; // Direction of movement
                          103 int lol, i; // lol?
                          104 unsigned char crash_x, crash_y, crash_z;
                          105
                          106 y = rand()%8;
                          107 x = rand()%8;
                          108 z = rand()%8;
                          109
                          110 // Coordinate array for the snake.
                          111 int snake[8][3];
                          112 for (i = 0; i < 8; i++) {
                          113 snake[i][0] = x;
                          114 snake[i][1] = y;
                          115 snake[i][2] = z;
                          116 }
                          117
                          118
                          119 dx = 1;
                          120 dy = 1;
                          121 dz = 1;
                          122
                          123 while (1) {
                          124 crash_x = 0;
                          125 crash_y = 0;
                          126 crash_z = 0;
                          127
                          128
                          129 // Let's mix things up a little:
                          130 if (rand()%3 == 0) {
                          131 // Pick a random axis, and set the speed to a random number.
                          132 lol = rand()%3;
                          133 if (lol == 0)
                          134 dx = rand()%3 - 1;
                          135
                          136 if (lol == 1)
                          137 dy = rand()%3 - 1;
                          138
                          139 if (lol == 2)
                          140 dz = rand()%3 - 1;
                          141 }
                          142
                          143 // x-axis crash
                          144 if ((dx == -1 && x == 0) || (dx == 1 && x == 7)) {
                          145 LED_PORT ^= LED_GREEN;
                          146 crash_x = 0x01;
                          147 if (rand()%3 == 1)
                          148 dx = (x == 7) ? -1 : 1;
                          149 else
                          150 dx = 0;
                          151 }
                          152
                          153 // y-axis crash
                          154 if ((dy == -1 && y == 0) || (dy == 1 && y == 7)) {
                          155 LED_PORT ^= LED_GREEN;
                          156 crash_y = 0x01;
                          157 if (rand()%3 == 1)
                          158 dy = (y == 7) ? -1 : 1;
                          159 else
                          160 dy = 0;
                          161 }
                          162
                          163 // z axis 0 crash
                          164 if ((dz == -1 && z == 0) || (z == 1 && z == 7)) {
                          165 LED_PORT ^= LED_GREEN;
                          166 crash_z = 0x01;
                          167 if (rand()%3 == 1)
                          168 dz = (z == 7) ? -1 : 1;
                          169 else
                          170 dz = 0;
                          171 }
                          172
                          173 // mode bit 0 sets crash action enable
                          174 if (mode | 0x01) {
                          175 if (crash_x) {
                          176 if (dy == 0) {
                          177 if (y == 7) {
                          178 dy = -1;
                          179 } else if (y == 0) {
                          180 dy = +1;
                          181 } else {
                          182 if (rand()%2 == 0)
                          183 dy = -1;
                          184 else
                          185 dy = 1;
                          186 }
                          187 }
                          188 if (dz == 0) {
                          189 if (z == 7) {
                          190 dz = -1;
                          191 } else if (z == 0) {
                          192 dz = 1;
                          193 } else {
                          194 if (rand()%2 == 0)
                          195 dz = -1;
                          196 else
                          197 dz = 1;
                          198 }
                          199 }
                          200 }
                          201
                          202 if (crash_y) {
                          203 if (dx == 0) {
                          204 if (x == 7) {
                          205 dx = -1;
                          206 } else if (x == 0) {
                          207 dx = 1;
                          208 } else {
                          209 if (rand()%2 == 0)
                          210 dx = -1;
                          211 else
                          212 dx = 1;
                          213 }
                          214 }
                          215 if (dz == 0) {
                          216 if (z == 3) {
                          217 dz = -1;
                          218 } else if (z == 0) {
                          219 dz = 1;
                          220 } else {
                          221 if (rand()%2 == 0)
                          222 dz = -1;
                          223 else
                          224 dz = 1;
                          225 }
                          226 }
                          227 }
                          228
                          229 if (crash_z) {
                          230 if (dy == 0) {
                          231 if (y == 7) {
                          232 dy = -1;
                          233 } else if (y == 0) {
                          234 dy = 1;
                          235 } else {
                          236 if (rand()%2 == 0)
                          237 dy = -1;
                          238 else
                          239 dy = 1;
                          240 }
                          241 }
                          242 if (dx == 0) {
                          243 if (x == 7) {
                          244 dx = -1;
                          245 } else if (x == 0) {
                          246 dx = 1;
                          247 } else {
                          248 if (rand()%2 == 0)
                          249 dx = -1;
                          250 else
                          251 dx = 1;
                          252 }
                          253 }
                          254 }
                          255 }
                          256
                          257 // mode bit 1 sets corner avoid enable
                          258 if (mode | 0x02) {
                          259 if ( // We are in one of 8 corner positions
                          260 (x == 0 && y == 0 && z == 0) ||
                          261 (x == 0 && y == 0 && z == 7) ||
                          262 (x == 0 && y == 7 && z == 0) ||
                          263 (x == 0 && y == 7 && z == 7) ||
                          264 (x == 7 && y == 0 && z == 0) ||
                          265 (x == 7 && y == 0 && z == 7) ||
                          266 (x == 7 && y == 7 && z == 0) ||
                          267 (x == 7 && y == 7 && z == 7)
                          268 ) {
                          269 // At this point, the voxel would bounce
                          270 // back and forth between this corner,
                          271 // and the exact opposite corner
                          272 // We don't want that!
                          273
                          274 // So we alter the trajectory a bit,
                          275 // to avoid corner stickyness
                          276 lol = rand()%3;
                          277 if (lol == 0)
                          278 dx = 0;
                          279
                          280 if (lol == 1)
                          281 dy = 0;
                          282
                          283 if (lol == 2)
                          284 dz = 0;
                          285 }
                          286 }
                          287 // one last sanity check
                          288 if (x == 0 && dx == -1)
                          289 dx = 1;
                          290
                          291 if (y == 0 && dy == -1)
                          292 dy = 1;
                          293
                          294 if (z == 0 && dz == -1)
                          295 dz = 1;
                          296
                          297 if (x == 7 && dx == 1)
                          298 dx = -1;
                          299
                          300 if (y == 7 && dy == 1)
                          301 dy = -1;
                          302
                          303 if (z == 7 && dz == 1)
                          304 dz = -1;
                          305
                          306
                          307 // Finally, move the voxel.
                          308 x = x + dx;
                          309 y = y + dy;
                          310 z = z + dz;
                          311
                          312 if (drawmode == 0x01) { // show one voxel at time
                          313 setvoxel(x,y,z);
                          314 delay_ms(delay);
                          315 clrvoxel(x,y,z);
                          316 } else if (drawmode == 0x02) { // flip the voxel in question
                          317 flpvoxel(x,y,z);
                          318 delay_ms(delay);
                          319 } if (drawmode == 0x03) { // draw a snake
                          320 for (i=7;i>=0;i--) {
                          321 snake[i][0] = snake[i-1][0];
                          322 snake[i][1] = snake[i-1][1];
                          323 snake[i][2] = snake[i-1][2];
                          324 }
                          325 snake[0][0] = x;
                          326 snake[0][1] = y;
                          327 snake[0][2] = z;
                          328
                          329 for (i = 0; i < 8; i++)
                          330 setvoxel(snake[i][0],snake[i][1],snake[i][2]);
                          331
                          332 delay_ms(delay);
                          333
                          334 for (i = 0; i < 8; i++)
                          335 clrvoxel(snake[i][0],snake[i][1],snake[i][2]);
                          336 }
                          337
                          338 // Return if a button is pressed
                          339 if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN))
                          340 return;
                          341 }
                          342 }
                          343
                          344 void effect_loop_rain(void) {
                          345 int i;
                          346 int rnd_x, rnd_y, rnd_num;
                          347
                          348 while (1) {
                          349 rnd_num = rand()%4;
                          350
                          351 for (i = 0; i < rnd_num; i++) {
                          352 rnd_x = rand()%8;
                          353 rnd_y = rand()%8;
                          354 setvoxel(rnd_x,rnd_y,7);
                          355 }
                          356
                          357 LED_PORT ^= LED_GREEN; // Green toggle
                          358
                          359 delay_ms(775);
                          360 shift(AXIS_Z,-1);
                          361
                          362 // Return if a button is pressed
                          363 if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN))
                          364 return;
                          365 }
                          366 }
                          367
                          368 void effect_loop_z_updown(int delay) {
                          369 unsigned char positions[64];
                          370 unsigned char destinations[64];
                          371
                          372 int i,y,move;
                          373
                          374 for (i = 0; i < 64; i++) {
                          375 positions[i] = 4;
                          376 destinations[i] = rand()%8;
                          377 }
                          378
                          379 for (i = 0; i < 8; i++) {
                          380 effect_z_updown_move(positions, destinations, AXIS_Z);
                          381 delay_ms(delay);
                          382 }
                          383
                          384 while (1) {
                          385 for (move = 0; move < 8; move++) {
                          386 effect_z_updown_move(positions, destinations, AXIS_Z);
                          387 delay_ms(delay);
                          388 }
                          389
                          390 delay_ms(delay*4);
                          391 LED_PORT ^= LED_GREEN;
                          392
                          393 for (y = 0; y < 32; y++)
                          394 destinations[rand()%64] = rand()%8;
                          395
                          396 // Return if a button is pressed
                          397 if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN))
                          398 return;
                          399 }
                          400
                          401 }
                          402
                          403 void effect_z_updown_move (unsigned char positions[64], unsigned char destinations[64], char axis)
                          404 {
                          405 int px;
                          406 for (px=0; px<64; px++)
                          407 {
                          408 if (positions[px]<destinations[px])
                          409 {
                          410 positions[px]++;
                          411 }
                          412 if (positions[px]>destinations[px])
                          413 {
                          414 positions[px]--;
                          415 }
                          416 }
                          417
                          418 draw_positions_axis (AXIS_Z, positions,0);
                          419 }
                          420
                          421 void effect_axis_updown_randsuspend (char axis, int delay, int sleep, int invert)
                          422 {
                          423 unsigned char positions[64];
                          424 unsigned char destinations[64];
                          425
                          426 int i,px;
                          427
                          428 // Set 64 random positions
                          429 for (i=0; i<64; i++)
                          430 {
                          431 positions[i] = 0; // Set all starting positions to 0
                          432 destinations[i] = rand()%8;
                          433 }
                          434
                          435 // Loop 8 times to allow destination 7 to reach all the way
                          436 for (i=0; i<8; i++)
                          437 {
                          438 // For every iteration, move all position one step closer to their destination
                          439 for (px=0; px<64; px++)
                          440 {
                          441 if (positions[px]<destinations[px])
                          442 {
                          443 positions[px]++;
                          444 }
                          445 }
                          446 // Draw the positions and take a nap
                          447 draw_positions_axis (axis, positions,invert);
                          448 delay_ms(delay);
                          449 }
                          450
                          451 // Set all destinations to 7 (opposite from the side they started out)
                          452 for (i=0; i<64; i++)
                          453 {
                          454 destinations[i] = 7;
                          455 }
                          456
                          457 // Suspend the positions in mid-air for a while
                          458 delay_ms(sleep);
                          459
                          460 // Then do the same thing one more time
                          461 for (i=0; i<8; i++)
                          462 {
                          463 for (px=0; px<64; px++)
                          464 {
                          465 if (positions[px]<destinations[px])
                          466 {
                          467 positions[px]++;
                          468 }
                          469 if (positions[px]>destinations[px])
                          470 {
                          471 positions[px]--;
                          472 }
                          473 }
                          474 draw_positions_axis (axis, positions,invert);
                          475 delay_ms(delay);
                          476 }
                          477 }
                          478
                          479 void draw_positions_axis (char axis, unsigned char positions[64], int invert)
                          480 {
                          481 int x, y, p;
                          482
                          483 fill(0x00);
                          484
                          485 for (x=0; x<8; x++)
                          486 {
                          487 for (y=0; y<8; y++)
                          488 {
                          489 if (invert)
                          490 {
                          491 p = (7-positions[(x*8)+y]);
                          492 } else
                          493 {
                          494 p = positions[(x*8)+y];
                          495 }
                          496
                          497 if (axis == AXIS_Z)
                          498 setvoxel(x,y,p);
                          499
                          500 if (axis == AXIS_Y)
                          501 setvoxel(x,p,y);
                          502
                          503 if (axis == AXIS_X)
                          504 setvoxel(p,y,x);
                          505 }
                          506 }
                          507
                          508 }
                          509
                          510
                          511 void effect_boxside_randsend_parallel (char axis, int origin, int delay, int mode)
                          512 {
                          513 int i;
                          514 int done;
                          515 unsigned char cubepos[64];
                          516 unsigned char pos[64];
                          517 int notdone = 1;
                          518 int notdone2 = 1;
                          519 int sent = 0;
                          520
                          521 for (i=0;i<64;i++)
                          522 {
                          523 pos[i] = 0;
                          524 }
                          525
                          526 while (notdone)
                          527 {
                          528 if (mode == 1)
                          529 {
                          530 notdone2 = 1;
                          531 while (notdone2 && sent<64)
                          532 {
                          533 i = rand()%64;
                          534 if (pos[i] == 0)
                          535 {
                          536 sent++;
                          537 pos[i] += 1;
                          538 notdone2 = 0;
                          539 }
                          540 }
                          541 } else if (mode == 2)
                          542 {
                          543 if (sent<64)
                          544 {
                          545 pos[sent] += 1;
                          546 sent++;
                          547 }
                          548 }
                          549
                          550 done = 0;
                          551 for (i=0;i<64;i++)
                          552 {
                          553 if (pos[i] > 0 && pos[i] <7)
                          554 {
                          555 pos[i] += 1;
                          556 }
                          557
                          558 if (pos[i] == 7)
                          559 done++;
                          560 }
                          561
                          562 if (done == 64)
                          563 notdone = 0;
                          564
                          565 for (i=0;i<64;i++)
                          566 {
                          567 if (origin == 0)
                          568 {
                          569 cubepos[i] = pos[i];
                          570 } else
                          571 {
                          572 cubepos[i] = (7-pos[i]);
                          573 }
                          574 }
                          575
                          576
                          577 delay_ms(delay);
                          578 draw_positions_axis(axis,cubepos,0);
                          579 LED_PORT ^= LED_RED;
                          580 }
                          581
                          582 }
                          583
                          584
                          585
                          586
                          587 // Light all leds layer by layer,
                          588 // then unset layer by layer
                          589 void effect_loadbar(int delay)
                          590 {
                          591 fill(0x00);
                          592
                          593 int z,y;
                          594
                          595 for (z=0;z<8;z++)
                          596 {
                          597 for (y=0;y<8;y++)
                          598 cube[z][y] = 0xff;
                          599
                          600 delay_ms(delay);
                          601 }
                          602
                          603 delay_ms(delay*3);
                          604
                          605 for (z=0;z<8;z++)
                          606 {
                          607 for (y=0;y<8;y++)
                          608 cube[z][y] = 0x00;
                          609
                          610 delay_ms(delay);
                          611 }
                          612 }
                          613
                          614
                          615 // Set n number of voxels at random positions
                          616 void effect_random_sparkle_flash (int iterations, int voxels, int delay)
                          617 {
                          618 int i;
                          619 int v;
                          620 for (i = 0; i < iterations; i++)
                          621 {
                          622 for (v=0;v<=voxels;v++)
                          623 setvoxel(rand()%8,rand()%8,rand()%8);
                          624
                          625 delay_ms(delay);
                          626 fill(0x00);
                          627 }
                          628 }
                          629
                          630 // blink 1 random voxel, blink 2 random voxels..... blink 20 random voxels
                          631 // and back to 1 again.
                          632 void effect_random_sparkle (void)
                          633 {
                          634 int i;
                          635
                          636 for (i=1;i<20;i++)
                          637 {
                          638 effect_random_sparkle_flash(5,i,200);
                          639 }
                          640
                          641 for (i=20;i>=1;i--)
                          642 {
                          643 effect_random_sparkle_flash(5,i,200);
                          644 }
                          645
                          646 }
                          647
                          648 int effect_telcstairs_do(int x, int val, int delay)
                          649 {
                          650 int y,z;
                          651
                          652 for(y = 0, z = x; y <= z; y++, x--)
                          653 {
                          654 if(x < CUBE_SIZE && y < CUBE_SIZE)
                          655 {
                          656 cube[x][y] = val;
                          657 }
                          658 }
                          659 delay_ms(delay);
                          660 return z;
                          661 }
                          662
                          663 void effect_telcstairs (int invert, int delay, int val)
                          664 {
                          665 int x;
                          666
                          667 if(invert)
                          668 {
                          669 for(x = CUBE_SIZE*2; x >= 0; x--)
                          670 {
                          671 x = effect_telcstairs_do(x,val,delay);
                          672 }
                          673 }
                          674 else
                          675 {
                          676 for(x = 0; x < CUBE_SIZE*2; x++)
                          677 {
                          678 x = effect_telcstairs_do(x,val,delay);
                          679 }
                          680 }
                          681 }
                          682
                          683 void effect_wormsqueeze (int size, int axis, int direction, int iterations, int delay)
                          684 {
                          685 int x, y, i,j,k, dx, dy;
                          686 int cube_size;
                          687 int origin = 0;
                          688
                          689 if (direction == -1)
                          690 origin = 7;
                          691
                          692 cube_size = 8-(size-1);
                          693
                          694 x = rand()%cube_size;
                          695 y = rand()%cube_size;
                          696
                          697 for (i=0; i<iterations; i++)
                          698 {
                          699 dx = ((rand()%3)-1);
                          700 dy = ((rand()%3)-1);
                          701
                          702 if ((x+dx) > 0 && (x+dx) < cube_size)
                          703 x += dx;
                          704
                          705 if ((y+dy) > 0 && (y+dy) < cube_size)
                          706 y += dy;
                          707
                          708 shift(axis, direction);
                          709
                          710
                          711 for (j=0; j<size;j++)
                          712 {
                          713 for (k=0; k<size;k++)
                          714 {
                          715 if (axis == AXIS_Z)
                          716 setvoxel(x+j,y+k,origin);
                          717
                          718 if (axis == AXIS_Y)
                          719 setvoxel(x+j,origin,y+k);
                          720
                          721 if (axis == AXIS_X)
                          722 setvoxel(origin,y+j,x+k);
                          723 }
                          724 }
                          725
                          726 delay_ms(delay);
                          727 }
                          728 }
                          729
                          730 void effect_smileyspin (int count, int delay, char bitmap)
                          731 {
                          732 unsigned char dybde[] = {0,1,2,3,4,5,6,7,1,1,2,3,4,5,6,6,2,2,3,3,4,4,5,5,3 ,3,3,3,4,4,4,4};
                          733 int d = 0;
                          734 int flip = 0;
                          735 int x, y, off;
                          736 for(int i = 0; i<count; i++)
                          737 {
                          738 flip = 0;
                          739 d = 0;
                          740 off = 0;
                          741 // front:
                          742 for (int s=0;s<7;s++){
                          743 if(!flip){
                          744 off++;
                          745 if (off == 4){
                          746 flip = 1;
                          747 off = 0;
                          748 }
                          749 } else {
                          750 off++;
                          751 }
                          752 for (x=0; x<8; x++)
                          753 {
                          754 d = 0;
                          755 for (y=0; y<8; y++)
                          756 {
                          757 if (font_getbitmappixel ( bitmap, 7-x, y)){
                          758 if (!flip)
                          759 setvoxel(y,dybde[8 * off + d++],x);
                          760 else
                          761 setvoxel(y,dybde[31 - 8 * off - d++],x);
                          762 } else {
                          763 d++;
                          764 }
                          765 }
                          766 }
                          767 delay_ms(delay);
                          768 fill(0x00);
                          769 }
                          770
                          771 // side:
                          772 off = 0;
                          773 flip = 0;
                          774 d = 0;
                          775 for (int s=0;s<7;s++){
                          776 if(!flip){
                          777 off++;
                          778 if (off == 4){
                          779 flip = 1;
                          780 off = 0;
                          781 }
                          782 } else {
                          783 off++;
                          784 }
                          785 for (x=0; x<8; x++)
                          786 {
                          787 d = 0;
                          788 for (y=0; y<8; y++)
                          789 {
                          790 if (font_getbitmappixel ( bitmap, 7-x, y)){
                          791 if (!flip)
                          792 setvoxel(dybde[8 * off + d++], 7 - y,x);
                          793 else
                          794 setvoxel(dybde[31 - 8 * off - d++],7 - y,x);
                          795 } else {
                          796 d++;
                          797 }
                          798 }
                          799 }
                          800 delay_ms(delay);
                          801 fill(0x00);
                          802 }
                          803
                          804
                          805 flip = 0;
                          806 d = 0;
                          807 off = 0;
                          808 // back:
                          809 for (int s=0;s<7;s++){
                          810 if(!flip){
                          811 off++;
                          812 if (off == 4){
                          813 flip = 1;
                          814 off = 0;
                          815 }
                          816 } else {
                          817 off++;
                          818 }
                          819 for (x=0; x<8; x++)
                          820 {
                          821 d = 0;
                          822 for (y=0; y<8; y++)
                          823 {
                          824 if (font_getbitmappixel ( bitmap, 7-x, 7-y)){
                          825 if (!flip)
                          826 setvoxel(y,dybde[8 * off + d++],x);
                          827 else
                          828 setvoxel(y,dybde[31 - 8 * off - d++],x);
                          829 } else {
                          830 d++;
                          831 }
                          832 }
                          833 }
                          834 delay_ms(delay);
                          835 fill(0x00);
                          836 }
                          837
                          838 // other side:
                          839 off = 0;
                          840 flip = 0;
                          841 d = 0;
                          842 for (int s=0;s<7;s++){
                          843 if(!flip){
                          844 off++;
                          845 if (off == 4){
                          846 flip = 1;
                          847 off = 0;
                          848 }
                          849 } else {
                          850 off++;
                          851 }
                          852 for (x=0; x<8; x++)
                          853 {
                          854 d = 0;
                          855 for (y=0; y<8; y++)
                          856 {
                          857 if (font_getbitmappixel ( bitmap, 7-x, 7-y)){
                          858 if (!flip)
                          859 setvoxel(dybde[8 * off + d++], 7 - y,x);
                          860 else
                          861 setvoxel(dybde[31 - 8 * off - d++],7 - y,x);
                          862 } else {
                          863 d++;
                          864 }
                          865 }
                          866 }
                          867 delay_ms(delay);
                          868 fill(0x00);
                          869 }
                          870
                          871 }
                          872 }
                          873
                          874
                          875 void effect_pathmove (unsigned char *path, int length)
                          876 {
                          877 int i,z;
                          878 unsigned char state;
                          879
                          880 for (i=(length-1);i>=1;i--)
                          881 {
                          882 for (z=0;z<8;z++)
                          883 {
                          884
                          885 state = getvoxel(((path[(i-1)]>>4) & 0x0f), (path[(i-1)] & 0x0f), z);
                          886 altervoxel(((path[i]>>4) & 0x0f), (path[i] & 0x0f), z, state);
                          887 }
                          888 }
                          889 for (i=0;i<8;i++)
                          890 clrvoxel(((path[0]>>4) & 0x0f), (path[0] & 0x0f),i);
                          891 }
                          892
                          893 void effect_loop_rand_patharound(int delay) {
                          894 int z, dz;
                          895 z = 4;
                          896 unsigned char path[28];
                          897
                          898 font_getpath(0,path,28);
                          899
                          900 while (1) {
                          901 dz = ((rand()%3)-1);
                          902 z += dz;
                          903
                          904 if (z > 7)
                          905 z = 7;
                          906
                          907 if (z < 0)
                          908 z = 0;
                          909
                          910 effect_pathmove(path, 28);
                          911 setvoxel(0,7,z);
                          912 delay_ms(delay);
                          913
                          914 LED_PORT ^= LED_GREEN;
                          915
                          916 // Return if a button is pressed
                          917 if (!(PIND & RS232_BTN) || !(PINB & MAIN_BTN))
                          918 return;
                          919 }
                          920 }
                          921
                          922 void effect_pathspiral (int iterations, int delay)
                          923 {
                          924 int z, i;
                          925 z = 4;
                          926 unsigned char path[16];
                          927
                          928 font_getpath(1,path,16);
                          929
                          930 for (i = 0; i < iterations; i++)
                          931 {
                          932 setvoxel(4,0,i%8);
                          933 delay_ms(delay);
                          934 effect_pathmove(path, 28);
                          935
                          936 }
                          937 }
                          938
                          939 void effect_path_text (int delay, char *str)
                          940 {
                          941 int z, i,ii;
                          942 z = 4;
                          943 unsigned char path[28];
                          944 font_getpath(0,path,28);
                          945
                          946 unsigned char chr[5];
                          947 unsigned char stripe;
                          948
                          949 while (*str)
                          950 {
                          951 //charfly(*str++, direction, axis, mode, delay);
                          952
                          953
                          954 font_getchar(*str++, chr);
                          955
                          956 for (ii=0;ii<5;ii++)
                          957 {
                          958 //stripe = pgm_read_byte(&font[(chr*5)+ii]);
                          959 stripe = chr[ii];
                          960
                          961 for (z=0;z<8;z++)
                          962 {
                          963 if ((stripe>>(7-z)) & 0x01)
                          964 {
                          965 setvoxel(0,7,z);
                          966 } else
                          967 {
                          968 clrvoxel(0,7,z);
                          969 }
                          970
                          971 }
                          972 effect_pathmove(path, 28);
                          973 delay_ms(delay);
                          974 }
                          975
                          976 effect_pathmove(path, 28);
                          977 delay_ms(delay);
                          978 }
                          979 for (i=0;i<28;i++)
                          980 {
                          981 effect_pathmove(path, 28);
                          982 delay_ms(delay);
                          983 }
                          984 }
                          985
                          986 void effect_path_bitmap (int delay, char bitmap, int iterations)
                          987 {
                          988 int z, i, ii;
                          989 z = 4;
                          990 unsigned char path[28];
                          991 font_getpath(0,path,28);
                          992
                          993 for (i=0; i < iterations; i++)
                          994 {
                          995 for (ii=0;ii<8;ii++)
                          996 {
                          997 for (z=0;z<8;z++)
                          998 {
                          999 if (font_getbitmappixel(bitmap,(7-z),ii))
                          1000 {
                          1001 setvoxel(0,7,z);
                          1002 } else
                          1003 {
                          1004 clrvoxel(0,7,z);
                          1005 }
                          1006
                          1007 }
                          1008 delay_ms(delay);
                          1009 effect_pathmove(path, 28);
                          1010 }
                          1011
                          1012 for (ii=0;ii<20;ii++)
                          1013 {
                          1014 delay_ms(delay);
                          1015 effect_pathmove(path, 28);
                          1016 }
                          1017 }
                          1018 for (ii=0;ii<10;ii++)
                          1019 {
                          1020 delay_ms(delay);
                          1021 effect_pathmove(path, 28);
                          1022 }
                          1023 }
                          1024
                          1025
                          1026

                          Comment


                          • #28
                            co the huong dan cu the ko ban do minh chua hoc qua con 595 ban co file nao hdan ko cho minh voi goi wa mail nguyendangminhky@mail.com thank nhieu

                            Comment


                            • #29
                              Trong code bạn đưa lên mình thấy có khai báo các thư viện #include "effect.h" #include "draw.h" #include "font.h" , sao mình ko thấy bạn gửi kèm theo các thư viện này thì mọi người biên dich và check code bạn ntn đc ? bạn có thể show cho a e chiêm ngưỡng sản phẩm của bạn cho mở mang tầm mắt ko nhỉ ?
                              ................. Pleiku .................... GIA LAI ...................

                              Comment


                              • #30
                                thấy cái này hay hay cũng muốn tìm hiểu mấy bác à, dùng 8 con 595 đưa dữ liệu ra cột và quét các tầng phải không ạ, nhưng e đang thắc mắc là dữ liệu ở các tầng thì làm sao đưa lên được, phải câu dây lên từng tầng hay làm thế nào cho đẹp, câu dây thì xấu quá. các hiệu ứng của nó phải đưa ra theo kiểu hoạt hình ạ hay có cách nào khác, nếu đưa ra theo kiểu hoạt hình thì sẽ rất tốn bộ nhớ, các bác ai giải quyết giúp e cái thắc mắc này với

                                Comment

                                Về tác giả

                                Collapse

                                ylotus Tìm hiểu thêm về ylotus

                                Bài viết mới nhất

                                Collapse

                                Đang tải...
                                X