Advertisement
Stybyk

RGB LEDS

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