Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************************
- * Name : LED CUBE 8x8x8 74HC595
- * By : Liam Jackson
- Based on code by Joseph Francis (74hc595 SPI)
- and by chr at instructables
- http://www.instructables.com/id/Led-Cube-8x8x8/step70/Run-the-cube-on-an-Arduino/
- Font found somewhere
- ****************************************************************************************/
- #include <TimerOne.h>
- #include <string.h>
- #define AXIS_X 1
- #define AXIS_Y 2
- #define AXIS_Z 3
- //--- Pin connected to ST_CP of 74HC595
- int latchPin = 10;
- //--- Pin connected to SH_CP of 74HC595
- int clockPin = 13;
- //--- Pin connected to DS of 74HC595
- int dataPin = 11;
- //--- Used for faster latching
- int latchPinPORTB = latchPin - 8;
- //holds value for all the pins, [x][y][z]
- byte cube[8][8];
- //Counts through the layers
- int current_layer = 0;
- //--- This process is run by the timer and does the PWM control
- void iProcess(){
- //last layer store
- int oldLayerBit = current_layer + 2;
- //increment layer count
- current_layer++;
- if(current_layer >= 8){
- current_layer = 0;
- }
- //--- Run through all the shift register values and send them (last one first)
- // latching in the process
- latchOff();
- for (int i = 0 ; i < 8 ; i++){
- spi_transfer(cube[current_layer][i]);
- }
- //Hide the old layer
- digitalWrite(oldLayerBit, LOW);
- //New data on the pins
- latchOn();
- //new layer high
- digitalWrite(current_layer + 2, HIGH);
- }
- //--- Direct port access latching
- void latchOn(){
- bitSet(PORTB,latchPinPORTB);
- }
- void latchOff(){
- bitClear(PORTB,latchPinPORTB);
- }
- //--- Used to setup SPI based on current pin setup
- // this is called in the setup routine;
- void setupSPI(){
- byte clr;
- SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
- SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
- clr=SPSR; // clear SPI status reg
- clr=SPDR; // clear SPI data reg
- SPSR |= (1<<SPI2X); // set prescaler bits
- delay(10);
- }
- //--- The really fast SPI version of shiftOut
- byte spi_transfer(byte data)
- {
- SPDR = data; // Start the transmission
- loop_until_bit_is_set(SPSR, SPIF);
- return SPDR; // return the received byte, we don't need that
- }
- void setup() {
- Serial.begin(9600);
- //layer pins
- for(int i = 2; i < 10; i++)
- {
- pinMode(i, OUTPUT);
- }
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- digitalWrite(latchPin,LOW);
- digitalWrite(dataPin,LOW);
- digitalWrite(clockPin,LOW);
- //--- Setup to run SPI
- setupSPI();
- //--- Activate the PWM timer
- Timer1.initialize(100); // Timer for updating pwm pins
- Timer1.attachInterrupt(iProcess);
- }
- void loop(){
- int i,x,y,z;
- while (true)
- {
- effect_text(800);
- effect_box_wamp(1000);
- effect_rain(100);
- 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_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);
- }
- }
- // ==========================================================================================
- // 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','R','D','U','I','N','O',' ','R','U','L','E','S','!',' '};
- 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);
- }
- // ==========================================================================================
- // Effect functions
- // ==========================================================================================
- 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 delayt, 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(delayt);
- 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);
- }
- }
- // Set or clear exactly 512 voxels in a random order.
- void effect_random_filler (int delayt, 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(delayt);
- 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)));
- }
- }
- }
- // Draw a plane on one axis and send it back and forth once.
- void effect_planboing (int plane, int speedd)
- {
- int i;
- for (i=0;i<8;i++)
- {
- fill(0x00);
- setplane(plane, i);
- delay_ms(speedd);
- }
- for (i=7;i>=0;i--)
- {
- fill(0x00);
- setplane(plane,i);
- delay_ms(speedd);
- }
- }
- // ==========================================================================================
- // Draw functions
- // ==========================================================================================
- // Set a single voxel to ON
- void setvoxel(int x, int y, int z)
- {
- if (inrange(x,y,z))
- cube[z][y] |= (1 << x);
- }
- // Set a single voxel to ON
- void clrvoxel(int x, int y, int z)
- {
- if (inrange(x,y,z))
- cube[z][y] &= ~(1 << x);
- }
- // This function validates that we are drawing inside the cube.
- 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
- {
- // One of the coordinates was outside the cube.
- return 0x00;
- }
- }
- // Get the current status of a voxel
- 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;
- }
- }
- // In some effect we want to just take bool and write it to a voxel
- // this function calls the apropriate voxel manipulation function.
- void altervoxel(int x, int y, int z, int state)
- {
- if (state == 1)
- {
- setvoxel(x,y,z);
- } else
- {
- clrvoxel(x,y,z);
- }
- }
- // Flip the state of a voxel.
- // If the voxel is 1, its turned into a 0, and vice versa.
- void flpvoxel(int x, int y, int z)
- {
- if (inrange(x, y, z))
- cube[z][y] ^= (1 << x);
- }
- // Makes sure x1 is alwas smaller than x2
- // This is usefull for functions that uses for loops,
- // to avoid infinite loops
- 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;
- }
- // Sets all voxels along a X/Y plane at a given point
- // on axis Z
- void setplane_z (int z)
- {
- int i;
- if (z>=0 && z<8)
- {
- for (i=0;i<8;i++)
- cube[z][i] = 0xff;
- }
- }
- // Clears voxels in the same manner as above
- 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;
- }
- }
- // Fill a value into all 64 byts of the cube buffer
- // Mostly used for clearing. fill(0x00)
- // or setting all on. fill(0xff)
- 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;
- }
- }
- }
- // Draw a box with all walls drawn and all voxels inside set
- 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);
- }
- }
- }
- // Darw a hollow box with side walls.
- 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));
- }
- }
- }
- }
- // Draw a wireframe box. This only draws the corners and edges,
- // no walls.
- 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);
- // Lines along X axis
- cube[z1][y1] = byteline(x1,x2);
- cube[z1][y2] = byteline(x1,x2);
- cube[z2][y1] = byteline(x1,x2);
- cube[z2][y2] = byteline(x1,x2);
- // Lines along Y axis
- for (iy=y1;iy<=y2;iy++)
- {
- setvoxel(x1,iy,z1);
- setvoxel(x1,iy,z2);
- setvoxel(x2,iy,z1);
- setvoxel(x2,iy,z2);
- }
- // Lines along Z axis
- for (iz=z1;iz<=z2;iz++)
- {
- setvoxel(x1,y1,iz);
- setvoxel(x1,y2,iz);
- setvoxel(x2,y1,iz);
- setvoxel(x2,y2,iz);
- }
- }
- // Returns a byte with a row of 1's drawn in it.
- // byteline(2,5) gives 0b00111100
- char byteline (int start, int end)
- {
- return ((0xff<<start) & ~(0xff<<(end+1)));
- }
- // Flips a byte 180 degrees.
- // MSB becomes LSB, LSB becomes MSB.
- 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;
- }
- // Draw a line between any coordinates in 3d space.
- // Uses integer values for input, so dont expect smooth animations.
- void line(int x1, int y1, int z1, int x2, int y2, int z2)
- {
- float xy; // how many voxels do we move on the y axis for each step on the x axis
- float xz; // how many voxels do we move on the y axis for each step on the x axis
- unsigned char x,y,z;
- unsigned char lasty,lastz;
- // We always want to draw the line from x=0 to x=7.
- // If x1 is bigget than x2, we need to flip all the values.
- 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 each step of x, y increments by:
- for (x = x1; x<=x2;x++)
- {
- y = (xy*(x-x1))+y1;
- z = (xz*(x-x1))+z1;
- setvoxel(x,y,z);
- }
- }
- // Delay loop.
- // This is not calibrated to milliseconds,
- // but we had allready made to many effects using this
- // calibration when we figured it might be a good idea
- // to calibrate it.
- 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");
- }
- }
- }
- }
- // Shift the entire contents of the cube along an axis
- // This is great for effects where you want to draw something
- // on one side of the cube and have it flow towards the other
- // side. Like rain flowing down the Z axiz.
- void shift (char axis, int direction)
- {
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement