0% found this document useful (0 votes)
14 views33 pages

#Include Avrinterrupt1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views33 pages

#Include Avrinterrupt1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

8x8x8 LED KÜP KODU

#include <avr/interrupt.h>

#include <string.h>

#define AXIS_X 1

#define AXIS_Y 2

#define AXIS_Z 3

volatile unsigned char cube[8][8];

volatile int current_layer = 0;

void setup()

int i;

for (i = 0; i < 14; i++)

pinMode(i, OUTPUT);

DDRC = 0xff;

PORTC = 0x00;

TCCR2A = 0x00;

TCCR2B = 0x00;

TCCR2A |= (0x01 << WGM21); // CTC mode. clear counter on TCNT2 == OCR2A

OCR2A = 10; // Interrupt every 25600th cpu cycle (256*100)

TCNT2 = 0x00; // start counting at 0

TCCR2B |= (0x01 << CS22) | (0x01 << CS21); // Start the clock with a 256
prescaler

TIMSK2 |= (0x01 << OCIE2A);

ISR (TIMER2_COMPA_vect)

int i;
// all layer selects off

PORTC = 0x00;

PORTB &= 0x0f;

PORTB |= 0x08; // output enable off.

for (i = 0; i < 8; i++)

PORTD = cube[current_layer][i];

PORTB = (PORTB & 0xF8) | (0x07 & (i + 1));

PORTB &= 0b00110111; // Output enable on.

if (current_layer < 6)

PORTC = (0x01 << current_layer);

} else if (current_layer == 6)

digitalWrite(12, HIGH);

} else

digitalWrite(13, HIGH);

current_layer++;

if (current_layer == 8)

current_layer = 0;

}
void loop()

int i, x, y, z;

while (true)

int i;

for (i = 0; i < 8; i++)

fill(0x00);

setplane(AXIS_Z, i);

delay_ms(10000);

effect_text(800);

effect_planboing(AXIS_Z, 400);

effect_planboing(AXIS_Y, 400);

effect_planboing(AXIS_X, 400);

effect_blinky2();

effect_random_filler(75, 1);

effect_random_filler(75, 0);
effect_rain(100);

effect_boxside_randsend_parallel (AXIS_X, 0, 150, 1);

effect_boxside_randsend_parallel (AXIS_X, 1, 150, 1);

effect_boxside_randsend_parallel (AXIS_Y, 0, 150, 1);

effect_boxside_randsend_parallel (AXIS_Y, 1, 150, 1);

effect_boxside_randsend_parallel (AXIS_Z, 0, 150, 1);

effect_boxside_randsend_parallel (AXIS_Z, 1, 150, 1);

effect_box_wamp(1000);

//box_filled(0, 0, 0, 7, 7, 7);

//
==============================================================================
============

// TEXT Functions

//
==============================================================================
============

char font_data[128][8] = {

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 0 :

{ 0x00, 0x3E, 0x41, 0x55, 0x41, 0x55, 0x49, 0x3E }, // 1 :

{ 0x00, 0x3E, 0x7F, 0x6B, 0x7F, 0x6B, 0x77, 0x3E }, // 2 :

{ 0x00, 0x22, 0x77, 0x7F, 0x7F, 0x3E, 0x1C, 0x08 }, // 3 :


{ 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x1C, 0x08 }, // 4 :

{ 0x00, 0x08, 0x1C, 0x2A, 0x7F, 0x2A, 0x08, 0x1C }, // 5 :

{ 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x08, 0x1C }, // 6 :

{ 0x00, 0x00, 0x1C, 0x3E, 0x3E, 0x3E, 0x1C, 0x00 }, // 7 :

{ 0xFF, 0xFF, 0xE3, 0xC1, 0xC1, 0xC1, 0xE3, 0xFF }, // 8 :

{ 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00 }, // 9 :

{ 0xFF, 0xFF, 0xE3, 0xDD, 0xDD, 0xDD, 0xE3, 0xFF }, // 10 :

{ 0x00, 0x0F, 0x03, 0x05, 0x39, 0x48, 0x48, 0x30 }, // 11 :

{ 0x00, 0x08, 0x3E, 0x08, 0x1C, 0x22, 0x22, 0x1C }, // 12 :

{ 0x00, 0x18, 0x14, 0x10, 0x10, 0x30, 0x70, 0x60 }, // 13 :

{ 0x00, 0x0F, 0x19, 0x11, 0x13, 0x37, 0x76, 0x60 }, // 14 :

{ 0x00, 0x08, 0x2A, 0x1C, 0x77, 0x1C, 0x2A, 0x08 }, // 15 :

{ 0x00, 0x60, 0x78, 0x7E, 0x7F, 0x7E, 0x78, 0x60 }, // 16 :

{ 0x00, 0x03, 0x0F, 0x3F, 0x7F, 0x3F, 0x0F, 0x03 }, // 17 :

{ 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x08 }, // 18 :

{ 0x00, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66 }, // 19 :


{ 0x00, 0x3F, 0x65, 0x65, 0x3D, 0x05, 0x05, 0x05 }, // 20 :

{ 0x00, 0x0C, 0x32, 0x48, 0x24, 0x12, 0x4C, 0x30 }, // 21 :

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F }, // 22 :

{ 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x3E }, // 23 :

{ 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x1C, 0x1C, 0x1C }, // 24 :

{ 0x00, 0x1C, 0x1C, 0x1C, 0x7F, 0x3E, 0x1C, 0x08 }, // 25 :

{ 0x00, 0x08, 0x0C, 0x7E, 0x7F, 0x7E, 0x0C, 0x08 }, // 26 :

{ 0x00, 0x08, 0x18, 0x3F, 0x7F, 0x3F, 0x18, 0x08 }, // 27 :

{ 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x7F, 0x7F }, // 28 :

{ 0x00, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00 }, // 29 :

{ 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x3E, 0x7F, 0x7F }, // 30 :

{ 0x00, 0x7F, 0x7F, 0x3E, 0x3E, 0x1C, 0x1C, 0x08 }, // 31 :

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 32 :

{ 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18 }, // 33 : !

{ 0x00, 0x36, 0x36, 0x14, 0x00, 0x00, 0x00, 0x00 }, // 34 : "


{ 0x00, 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36 }, // 35 : #

{ 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08 }, // 36 : $

{ 0x00, 0x60, 0x66, 0x0C, 0x18, 0x30, 0x66, 0x06 }, // 37 : %

{ 0x00, 0x3C, 0x66, 0x3C, 0x28, 0x65, 0x66, 0x3F }, // 38 : &

{ 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00 }, // 39 : '

{ 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60 }, // 40 : (

{ 0x00, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06 }, // 41 : )

{ 0x00, 0x00, 0x36, 0x1C, 0x7F, 0x1C, 0x36, 0x00 }, // 42 : *

{ 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00 }, // 43 : +

{ 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60 }, // 44 : ,

{ 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00 }, // 45 : -

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60 }, // 46 : .

{ 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00 }, // 47 : /

{ 0x00, 0x3C, 0x66, 0x6E, 0x76, 0x66, 0x66, 0x3C }, // 48 : 0

{ 0x00, 0x18, 0x18, 0x38, 0x18, 0x18, 0x18, 0x7E }, // 49 : 1

{ 0x00, 0x3C, 0x66, 0x06, 0x0C, 0x30, 0x60, 0x7E }, // 50 : 2


{ 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C }, // 51 : 3

{ 0x00, 0x0C, 0x1C, 0x2C, 0x4C, 0x7E, 0x0C, 0x0C }, // 52 : 4

{ 0x00, 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C }, // 53 : 5

{ 0x00, 0x3C, 0x66, 0x60, 0x7C, 0x66, 0x66, 0x3C }, // 54 : 6

{ 0x00, 0x7E, 0x66, 0x0C, 0x0C, 0x18, 0x18, 0x18 }, // 55 : 7

{ 0x00, 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C }, // 56 : 8

{ 0x00, 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C }, // 57 : 9

{ 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00 }, // 58 : :

{ 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30 }, // 59 : ;

{ 0x00, 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06 }, // 60 : <

{ 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00 }, // 61 : =

//

{ 0x00, 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60 }, // 62 : >

{ 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x18, 0x00, 0x18 }, // 63 : ?

{ 0x00, 0x38, 0x44, 0x5C, 0x58, 0x42, 0x3C, 0x00 }, // 64 : @

{ 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 }, // 65 : A


{ 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C }, // 66 : B

{ 0x00, 0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C }, // 67 : C

{ 0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C }, // 68 : D

{ 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E }, // 69 : E

{ 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60 }, // 70 : F

{ 0x00, 0x3C, 0x66, 0x60, 0x60, 0x6E, 0x66, 0x3C }, // 71 : G

{ 0x00, 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 }, // 72 : H

{ 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C }, // 73 : I

{ 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 }, // 74 : J

{ 0x00, 0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66 }, // 75 : K

{ 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E }, // 76 : L

{ 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63 }, // 77 : M

{ 0x00, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63, 0x63 }, // 78 : N

{ 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C }, // 79 : O

{ 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60 }, // 80 : P

{ 0x00, 0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x06 }, // 81 : Q


{ 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66 }, // 82 : R

{ 0x00, 0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C }, // 83 : S

{ 0x00, 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x18 }, // 84 : T

{ 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E }, // 85 : U

{ 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18 }, // 86 : V

{ 0x00, 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63 }, // 87 : W

{ 0x00, 0x63, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x63 }, // 88 : X

{ 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18 }, // 89 : Y

{ 0x00, 0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E }, // 90 : Z

{ 0x00, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E }, // 91 : [

{ 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00 }, // 92 : \

{ 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78 }, // 93 : ]

{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00 }, // 94 : ^

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F }, // 95 : _

{ 0x00, 0x0C, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00 }, // 96 : `


{ 0x00, 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E }, // 97 : a

{ 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C }, // 98 : b

{ 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C }, // 99 : c

{ 0x00, 0x06, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E }, // 100 : d

{ 0x00, 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C }, // 101 : e

{ 0x00, 0x1C, 0x36, 0x30, 0x30, 0x7C, 0x30, 0x30 }, // 102 : f

{ 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x3C }, // 103 : g

{ 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66 }, // 104 : h

{ 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3C }, // 105 : i

{ 0x00, 0x0C, 0x00, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 }, // 106 : j

{ 0x00, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0x66 }, // 107 : k

{ 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 }, // 108 : l

{ 0x00, 0x00, 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x6B }, // 109 : m

{ 0x00, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66 }, // 110 : n

{ 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C }, // 111 : o

{ 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60 }, // 112 : p


{ 0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x3C, 0x0D, 0x0F }, // 113 : q

{ 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x60, 0x60 }, // 114 : r

{ 0x00, 0x00, 0x00, 0x3E, 0x40, 0x3C, 0x02, 0x7C }, // 115 : s

{ 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18 }, // 116 : t

{ 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3E }, // 117 : u

{ 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x18 }, // 118 : v

{ 0x00, 0x00, 0x00, 0x63, 0x6B, 0x6B, 0x6B, 0x3E }, // 119 : w

{ 0x00, 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66 }, // 120 : x

{ 0x00, 0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x3C }, // 121 : y

{ 0x00, 0x00, 0x00, 0x3C, 0x0C, 0x18, 0x30, 0x3C }, // 122 : z

{ 0x00, 0x0E, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0E }, // 123 : {

{ 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18 }, // 124 : |

{ 0x00, 0x70, 0x18, 0x18, 0x0C, 0x18, 0x18, 0x70 }, // 125 : }

{ 0x00, 0x00, 0x00, 0x3A, 0x6C, 0x00, 0x00, 0x00 }, // 126 : ~

{ 0x00, 0x08, 0x1C, 0x36, 0x63, 0x41, 0x41, 0x7F } // 127 :


};

// Define display string here

const int charNum = 15;

char string[charNum] = {'A', 'L', 'I', ' ', 'A', 'K', 'S', 'O', 'Y', ' '};

void effect_text(int delayt) {

fill(0x00);

for (int ltr = 0; ltr < charNum; ltr++) { // For each letter in string array

for (int dist = 0; dist < 8; dist++) { //bring letter forward

fill(0x00);//blank last row

int rev = 0;

for (int rw = 7; rw >= 0; rw--) {//copy rows

cube[rev][dist] = bitswap(font_data[string[ltr]][rw]);

rev++;

delay_ms(delayt);

unsigned char bitswap (unsigned char x)//Reverses a byte (so letters aren't
backwards);

{ byte result;

asm("mov __tmp_reg__, %[in] \n\t"

"lsl __tmp_reg__ \n\t" /* shift out high bit to carry */

"ror %[out] \n\t" /* rotate carry __tmp_reg__to low bit (eventually) */

"lsl __tmp_reg__ \n\t" /* 2 */

"ror %[out] \n\t"

"lsl __tmp_reg__ \n\t" /* 3 */

"ror %[out] \n\t"


"lsl __tmp_reg__ \n\t" /* 4 */

"ror %[out] \n\t"

"lsl __tmp_reg__ \n\t" /* 5 */

"ror %[out] \n\t"

"lsl __tmp_reg__ \n\t" /* 6 */

"ror %[out] \n\t"

"lsl __tmp_reg__ \n\t" /* 7 */

"ror %[out] \n\t"

"lsl __tmp_reg__ \n\t" /* 8 */

"ror %[out] \n\t"

: [out] "=r" (result) : [in] "r" (x));

return (result);

/*EKFUNKZ*//*EKFUNKZ*/

void effect_box_wamp(int delayt)

for (int k = 0; k < 3; k++) {

for (int i = 0; i < 4; i++) {

fill(0x00);

box_filled(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);

delay_ms(delayt);

for (int i = 3; i >= 0; i--) {

fill(0x00);

box_filled(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);

delay_ms(delayt);

}
for (int k = 0; k < 3; k++) {

for (int i = 0; i < 4; i++) {

fill(0x00);

box_walls(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);

delay_ms(delayt);

for (int i = 3; i >= 0; i--) {

fill(0x00);

box_walls(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);

delay_ms(delayt);

for (int k = 0; k < 3; k++) {

for (int i = 0; i < 4; i++) {

fill(0x00);

box_wireframe(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);

delay_ms(delayt);

for (int i = 3; i >= 0; i--) {

fill(0x00);

box_wireframe(3 - i, 3 - i, 3 - i, 4 + i, 4 + i, 4 + i);

delay_ms(delayt);

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 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;

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);

void effect_rain (int iterations)

int i, ii;

int rnd_x;

int rnd_y;

int rnd_num;
for (ii = 0; ii < iterations; ii++)

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);

delay_ms(1000);

shift(AXIS_Z, -1);

void effect_random_filler (int delay, int state)

int x, y, z;

int loop = 0;

if (state == 1)

fill(0x00);

} else

fill(0xff);

while (loop < 511)

x = rand() % 8;

y = rand() % 8;

z = rand() % 8;

if ((state == 0 && getvoxel(x, y, z) == 0x01) || (state == 1 &&


getvoxel(x, y, z) == 0x00))

{
altervoxel(x, y, z, state);

delay_ms(delay);

loop++;

void effect_blinky2()

int i, r;

fill(0x00);

for (r = 0; r < 2; r++)

i = 750;

while (i > 0)

{ fill(0x00);

delay_ms(i);

fill(0xff);

delay_ms(100);

i = i - (15 + (1000 / (i / 10)));

delay_ms(1000);

i = 750;

while (i > 0)

fill(0x00);

delay_ms(751 - i);

fill(0xff);

delay_ms(100);

i = i - (15 + (1000 / (i / 10)));


}

void effect_planboing (int plane, int speed)

int i;

for (i = 0; i < 8; i++)

fill(0x00);

setplane(plane, i);

delay_ms(speed);

for (i = 7; i >= 0; i--)

fill(0x00);

setplane(plane, i);

delay_ms(speed);

void setvoxel(int x, int y, int z)

if (inrange(x, y, z))

cube[z][y] |= (1 << x);

}void clrvoxel(int x, int y, int z)

if (inrange(x, y, z))

cube[z][y] &= ~(1 << x);

unsigned char inrange(int x, int y, int z)

if (x >= 0 && x < 8 && y >= 0 && y < 8 && z >= 0 && z < 8)
{

return 0x01;

} else

return 0x00;

unsigned char getvoxel(int x, int y, int z)

if (inrange(x, y, z))

if (cube[z][y] & (1 << x))

return 0x01;

} else

return 0x00;

} else

return 0x00;

void altervoxel(int x, int y, int z, int state)

if (state == 1)

setvoxel(x, y, z);

} else

clrvoxel(x, y, z);
}

void flpvoxel(int x, int y, int z)

if (inrange(x, y, z))

cube[z][y] ^= (1 << x);

void argorder(int ix1, int ix2, int *ox1, int *ox2)

if (ix1 > ix2)

int tmp;

tmp = ix1;

ix1 = ix2;

ix2 = tmp;

*ox1 = ix1;

*ox2 = ix2;

void setplane_z (int z)

int i;

if (z >= 0 && z < 8)

for (i = 0; i < 8; i++)

cube[z][i] = 0xff;

void clrplane_z (int z)

int i;
if (z >= 0 && z < 8)

for (i = 0; i < 8; i++)

cube[z][i] = 0x00;

void setplane_x (int x)

int z;

int y;

if (x >= 0 && x < 8)

for (z = 0; z < 8; z++)

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

cube[z][y] |= (1 << x);

void clrplane_x (int x)

int z;

int y;

if (x >= 0 && x < 8)

for (z = 0; z < 8; z++)

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

{
cube[z][y] &= ~(1 << x);

void setplane_y (int y)

int z;

if (y >= 0 && y < 8)

for (z = 0; z < 8; z++)

cube[z][y] = 0xff;

void clrplane_y (int y)

int z;

if (y >= 0 && y < 8)

for (z = 0; z < 8; z++)

cube[z][y] = 0x00;

void setplane (char axis, unsigned char i)

switch (axis)

case AXIS_X:

setplane_x(i);

break;

case AXIS_Y:
setplane_y(i);

break;

case AXIS_Z:

setplane_z(i);

break;

void clrplane (char axis, unsigned char i)

switch (axis)

case AXIS_X:

clrplane_x(i);

break;

case AXIS_Y:

clrplane_y(i);

break;

case AXIS_Z:

clrplane_z(i);

break;

void fill (unsigned char pattern)

int z;

int y;

for (z = 0; z < 8; z++)

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

cube[z][y] = pattern;
}

void box_filled(int x1, int y1, int z1, int x2, int y2, int z2)

int iy;

int iz;

argorder(x1, x2, &x1, &x2);

argorder(y1, y2, &y1, &y2);

argorder(z1, z2, &z1, &z2);

for (iz = z1; iz <= z2; iz++)

for (iy = y1; iy <= y2; iy++)

cube[iz][iy] |= byteline(x1, x2);

void box_walls(int x1, int y1, int z1, int x2, int y2, int z2)

int iy;

int iz;

argorder(x1, x2, &x1, &x2);

argorder(y1, y2, &y1, &y2);

argorder(z1, z2, &z1, &z2);

for (iz = z1; iz <= z2; iz++)

for (iy = y1; iy <= y2; iy++)

if (iy == y1 || iy == y2 || iz == z1 || iz == z2)

{
cube[iz][iy] = byteline(x1, x2);

} else

cube[iz][iy] |= ((0x01 << x1) | (0x01 << x2));

void box_wireframe(int x1, int y1, int z1, int x2, int y2, int z2)

int iy;

int iz;

argorder(x1, x2, &x1, &x2);

argorder(y1, y2, &y1, &y2);

argorder(z1, z2, &z1, &z2);

cube[z1][y1] = byteline(x1, x2);

cube[z1][y2] = byteline(x1, x2);

cube[z2][y1] = byteline(x1, x2);

cube[z2][y2] = byteline(x1, x2);

for (iy = y1; iy <= y2; iy++)

setvoxel(x1, iy, z1);

setvoxel(x1, iy, z2);

setvoxel(x2, iy, z1);

setvoxel(x2, iy, z2);

for (iz = z1; iz <= z2; iz++)

setvoxel(x1, y1, iz);

setvoxel(x1, y2, iz);


setvoxel(x2, y1, iz);

setvoxel(x2, y2, iz);

char byteline (int start, int end)

return ((0xff << start) & ~(0xff << (end + 1)));

char flipbyte (char byte)

char flop = 0x00;

flop = (flop & 0b11111110) | (0b00000001 & (byte >> 7));

flop = (flop & 0b11111101) | (0b00000010 & (byte >> 5));

flop = (flop & 0b11111011) | (0b00000100 & (byte >> 3));

flop = (flop & 0b11110111) | (0b00001000 & (byte >> 1));

flop = (flop & 0b11101111) | (0b00010000 & (byte << 1));

flop = (flop & 0b11011111) | (0b00100000 & (byte << 3));

flop = (flop & 0b10111111) | (0b01000000 & (byte << 5));

flop = (flop & 0b01111111) | (0b10000000 & (byte << 7));

return flop;

void line(int x1, int y1, int z1, int x2, int y2, int z2)

float xy;

float xz;

unsigned char x, y, z;

unsigned char lasty, lastz;

if (x1 > x2)

int tmp;
tmp = x2; x2 = x1; x1 = tmp;

tmp = y2; y2 = y1; y1 = tmp;

tmp = z2; z2 = z1; z1 = tmp;

if (y1 > y2)

xy = (float)(y1 - y2) / (float)(x2 - x1);

lasty = y2;

} else

xy = (float)(y2 - y1) / (float)(x2 - x1);

lasty = y1;

if (z1 > z2)

xz = (float)(z1 - z2) / (float)(x2 - x1);

lastz = z2;

} else

xz = (float)(z2 - z1) / (float)(x2 - x1);

lastz = z1;

for (x = x1; x <= x2; x++)

y = (xy * (x - x1)) + y1;

z = (xz * (x - x1)) + z1;

setvoxel(x, y, z);

void delay_ms(uint16_t x)

{
uint8_t y, z;

for ( ; x > 0 ; x--) {

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

for ( z = 0 ; z < 6 ; z++) {

asm volatile ("nop");

int i, x , y;

int ii, iii;

int state;

for (i = 0; i < 8; i++)

if (direction == -1)

ii = i;

} else

ii = (7 - i);

for (x = 0; x < 8; x++)

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

if (direction == -1)

iii = ii + 1;

} else
{

iii = ii - 1;

if (axis == AXIS_Z)

state = getvoxel(x, y, iii);

altervoxel(x, y, ii, state);

if (axis == AXIS_Y)

state = getvoxel(x, iii, y);

altervoxel(x, ii, y, state);

if (axis == AXIS_X)

state = getvoxel(iii, y, x);

altervoxel(ii, y, x, state);

if (direction == -1)

i = 7;

} else

i = 0;
}

for (x = 0; x < 8; x++)

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

if (axis == AXIS_Z)

clrvoxel(x, y, i);

if (axis == AXIS_Y)

clrvoxel(x, i, y);

if (axis == AXIS_X)

clrvoxel(i, y, x);

You might also like