Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <avr/pgmspace.h>
- #include <avr/signal.h>
- // #define F_CPU 7372800UL
- // #include <util/delay.h>
- #define LAYER1 0x80
- #define LAYER2 0x40
- #define LAYER3 0x20
- #define LAYER4 0x10
- #define LAYERS 0xf0
- #define LAYERS_R 0x0f
- #define LAYER_PORT PORTB
- unsigned short int i=0;
- #define GRID1 PORTD
- #define GRID2 PORTA
- void delay_ms (uint16_t x);
- void launch_effect (int effect);
- volatile unsigned char cube[4][4];
- volatile unsigned char tmpcube[4][4];
- volatile unsigned char current_layer;
- #include "draw.c" // this is for effect on LEDs
- #include "frames.c"
- #include "effect.c"
- int main (void)
- {
- DDRA = 0xff;
- DDRD = 0xff;
- PORTA = 0x00;
- PORTD = 0x00;
- /////////////////////////////////// ?
- DDRB= 0xfe; // PORTB.0 as INPUT
- PORTB = 0X01;
- //////////////////////////////////
- TCNT2 = 0x00;
- TIMSK |= (1 << OCIE2);
- OCR2 = 30;
- TCCR2 = 0x06; // prescaler /256
- TCCR2 |= (1 << WGM01);
- sei(); // Enable Interrupts
- int x;
- int z;
- current_layer = 0x00;
- ////////////////////// for effect start
- for(;;)
- {
- delay_ms(1000);
- launch_effect(i);
- }
- ////////////////////////////////////////
- }
- 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++){
- ////////////////////////////////// ? this don't work
- if(PINB & (1<<0) ){ // it should change effect when pushButton on PB0 is pressed
- i = (i+1) % 4;
- return;
- }
- ////////////////////////////////
- asm volatile ("nop");
- }
- }
- }
- }
- ISR(TIMER2_COMP_vect) // for writing to buffer
- {
- LAYER_PORT &= LAYERS_R;
- GRID1 = (0x0f & cube[current_layer][0]) | (0xf0 & (cube[current_layer][1] << 4));
- GRID2 = (0x0f & cube[current_layer][2]) | (0xf0 & (cube[current_layer][3] << 4));
- LAYER_PORT |= (0x01 << (7 - current_layer));
- if (current_layer++ == 3)
- current_layer = 0;
- }
- void launch_effect (int effect)
- {
- switch (effect)
- {
- case 0:
- loadbar(250);
- break;
- case 1:
- boingboing(150,100,0x03,0x01);
- break;
- case 2:
- fill(0x00);
- random_filler(100,1,150,1);
- random_filler(100,1,150,0);
- break;
- case 3:
- sendvoxels_rand_z(150,100,100);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement