Advertisement
Stybyk

RGB LEDS

Sep 17th, 2014
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.54 KB | None | 0 0
  1. // ***********************************************************************
  2. //
  3. // Demo program pro vyuku predmetu APPS (07/2014)
  4. // Petr Olivka, katedra informatiky, FEI, VSB-TU Ostrava
  5. //
  6. // Priklad pouzit vyvojoveho nastroje AVR-KIT:
  7. // ovladani LED a tlacitek.
  8. // Blikani LED PIND2 a PIND3 lze zastavit stiskem tlacitka PIND4-PIND7
  9. //
  10. // ***********************************************************************
  11.  
  12. // nejprve hlavickovy soubor AVR-KITu
  13. #include "../avrkit/avrkit.h"
  14.  
  15. #include <stdio.h>
  16. #include <avr/io.h>
  17.  
  18.  
  19. int T,T1R,T0R,T1L,T0L,procenta1,procenta2,tlacitko,blue,red;
  20.  
  21.  
  22. int main()
  23. {
  24.     // inicializace prostredi
  25.     avrkit_init();
  26.  
  27.     printf( "AVR-KIT ready...\n\n" );
  28.    
  29.  
  30.     // Cely port b jako vystup
  31.     DDRB |= 0xFF;
  32.     red = 0;
  33.     blue = 0;
  34.     int procenta1 = 10 ;
  35.     int procenta2 = 100;
  36.     int T = 10;
  37.     int T1L = procenta1 * T/100;
  38.     int T0L = T - T1L;
  39.     int T1R = procenta2 * T/100;
  40.     int T0R = T - T1R;
  41.     while ( 1 )
  42.     {
  43.         /*if ( read_butt() == 0b11100000 )
  44.         {
  45.              tlacitko = 1;
  46.            
  47.              
  48.         }
  49.        
  50.         if ( read_butt() == 0b11010000 )
  51.         {
  52.             tlacitko = 2;
  53.            
  54.         }
  55.        
  56.        
  57.         if (tlacitko == 1)
  58.         {
  59.             // rozsviceni LED PIND2
  60.             PORTB |= ( 1 << PINB1 );
  61.            
  62.             // zpozdeni
  63.             delay_ms(T1L);
  64.            
  65.            
  66.             PORTB &= ~( 1 << PINB1);
  67.             delay_ms(T0L);
  68.            
  69.        
  70.         // rozsviceni LED PIND2
  71.         PORTB |= ( 1 << PINB1 );
  72.        
  73.         // zpozdeni
  74.         delay_ms(T1L); 
  75.        
  76.        
  77.        PORTB &= ~( 1 << PINB1);
  78.        delay_ms(T0L);
  79.          
  80.         }
  81.        
  82.        
  83.         if (tlacitko == 2)
  84.         {
  85.             // rozsviceni LED PIND2
  86.             PORTB |= ( 1 << PINB5 );
  87.            
  88.             // zpozdeni
  89.             delay_ms(T1R);
  90.            
  91.            
  92.             PORTB &= ~( 1 << PINB5);
  93.             delay_ms(T0R);
  94.            
  95.            
  96.             // rozsviceni LED PIND2
  97.             PORTB |= ( 1 << PINB5 );
  98.            
  99.             // zpozdeni
  100.             delay_ms(T1R);
  101.            
  102.            
  103.             PORTB &= ~( 1 << PINB5);
  104.             delay_ms(T0R);
  105.            
  106.         }
  107.        
  108.          
  109.   }
  110.   */
  111.        
  112.        
  113.        
  114.        
  115.        
  116.             // rozsviceni LED PIND2
  117.             PORTB |= ( 1 << PINB1 );
  118.            
  119.             // zpozdeni
  120.             delay_ms(T1L);
  121.            
  122.            
  123.             PORTB &= ~( 1 << PINB1);
  124.             delay_ms(T0L);
  125.            
  126.                        
  127.        
  128.        
  129.             // rozsviceni LED PIND2
  130.             PORTB |= ( 1 << PINB5 );
  131.            
  132.             // zpozdeni
  133.             delay_ms(T1R);
  134.            
  135.            
  136.             PORTB &= ~( 1 << PINB5);
  137.             delay_ms(T0R);
  138.            
  139.        
  140.            
  141.            
  142.            
  143.     /*     
  144.        if ( read_butt() == 0b11100000 )
  145.         {
  146.              tlacitko = 1;
  147.            
  148.              
  149.         }
  150.        
  151.         if ( read_butt() == 0b11010000 )
  152.         {
  153.             tlacitko = 2;
  154.            
  155.         }
  156.        
  157.          
  158.         if ( read_butt() == 0b10110000 )
  159.         {
  160.             tlacitko = 3;
  161.            
  162.            
  163.         }
  164.        
  165.         if ( read_butt() == 0b01110000)
  166.         {
  167.             tlacitko = 4;
  168.            
  169.         }
  170.         */
  171.        
  172. }
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement