Advertisement
Guest User

Untitled

a guest
Aug 16th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <avr/pgmspace.h>
  4.  
  5. #include <avr/signal.h>
  6.  
  7. // #define F_CPU 7372800UL
  8. // #include <util/delay.h>
  9.  
  10. #define LAYER1 0x80
  11. #define LAYER2 0x40
  12. #define LAYER3 0x20
  13. #define LAYER4 0x10
  14. #define LAYERS 0xf0
  15. #define LAYERS_R 0x0f
  16. #define LAYER_PORT PORTB
  17.  
  18. unsigned short int i=0;
  19.  
  20. #define GRID1 PORTD
  21. #define GRID2 PORTA
  22.  
  23. void delay_ms (uint16_t x);
  24. void launch_effect (int effect);
  25.  
  26. volatile unsigned char cube[4][4];
  27. volatile unsigned char tmpcube[4][4];
  28. volatile unsigned char current_layer;
  29.  
  30.  
  31. #include "draw.c" // this is for effect on LEDs
  32. #include "frames.c"
  33. #include "effect.c"
  34.  
  35. int main (void)
  36. {    
  37.     DDRA = 0xff;   
  38.     DDRD = 0xff;   
  39.  
  40.     PORTA = 0x00;
  41.     PORTD = 0x00;
  42.  
  43.         /////////////////////////////////// ?
  44.     DDRB= 0xfe; // PORTB.0 as INPUT
  45.     PORTB = 0X01;
  46.         //////////////////////////////////
  47.  
  48.     TCNT2 = 0x00;  
  49.     TIMSK |= (1 << OCIE2);
  50.    
  51.     OCR2 = 30;         
  52.     TCCR2 = 0x06;   // prescaler /256  
  53.     TCCR2 |= (1 << WGM01);   
  54.     sei(); // Enable Interrupts
  55.    
  56.     int x;
  57.     int z;
  58.  
  59.     current_layer = 0x00;
  60.    
  61.   ////////////////////// for effect start              
  62.             for(;;)
  63.             {          
  64.                 delay_ms(1000);
  65.                 launch_effect(i);
  66.             }
  67.        
  68.   ////////////////////////////////////////     
  69.  
  70. }
  71.  
  72. void delay_ms(uint16_t x)
  73. {
  74.   uint8_t y, z;
  75.   for ( ; x > 0 ; x--){
  76.     for ( y = 0 ; y < 90 ; y++){
  77.     ;  for ( z = 0 ; z < 6 ; z++){
  78.      ////////////////////////////////// ?  this don't work
  79.       if(PINB & (1<<0) ){   // it should change effect when pushButton on PB0 is pressed
  80.           i = (i+1) % 4;
  81.           return;
  82.       }
  83.      ////////////////////////////////
  84.        asm volatile ("nop");
  85.         }          
  86.     }
  87.   }
  88. }
  89.  
  90. ISR(TIMER2_COMP_vect) // for writing to buffer
  91. {
  92.     LAYER_PORT &= LAYERS_R;
  93.  
  94.     GRID1 = (0x0f & cube[current_layer][0]) | (0xf0 & (cube[current_layer][1] << 4));
  95.     GRID2 = (0x0f & cube[current_layer][2]) | (0xf0 & (cube[current_layer][3] << 4));
  96.  
  97.     LAYER_PORT |= (0x01 << (7 - current_layer));
  98.  
  99.     if (current_layer++ == 3)
  100.         current_layer = 0;
  101. }
  102.  
  103. void launch_effect (int effect)
  104. {  
  105.     switch (effect)
  106.     {
  107.         case 0:
  108.             loadbar(250);
  109.             break;
  110.         case 1:
  111.             boingboing(150,100,0x03,0x01);
  112.             break;
  113.         case 2:
  114.             fill(0x00);
  115.             random_filler(100,1,150,1);
  116.             random_filler(100,1,150,0);
  117.             break;
  118.         case 3:
  119.             sendvoxels_rand_z(150,100,100);
  120.             break;
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement