Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/delay.h>
  3.  
  4. int maxValue(int x) {
  5. if (x > 255) {
  6. return 255;
  7. }
  8.  
  9. return x;
  10. }
  11.  
  12. int minValue(int x) {
  13. if (x < 0) {
  14. return 0;
  15. }
  16.  
  17. return x;
  18. }
  19.  
  20. int main(void) {
  21. TCCR0|=(1<<WGM00)|(1<<WGM01)|(1<<COM01)|(0<<CS02)|(0<<CS01)|(1<<CS00);
  22. TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);
  23. TCCR1B|=(1<<WGM13)|(1<<WGM12)|(0<<CS12)|(0<<CS11)|(1<<CS10);
  24. ICR1=255;
  25.  
  26. DDRB |= (1 << PB3);
  27. DDRD |= (1 << PD5) | (1 << PD4);
  28. DDRA = 0x00; // in
  29.  
  30. PORTA = 0xFF;
  31.  
  32. int r = 255;
  33. int g = 255;
  34. int b = 255;
  35.  
  36. OCR0 = r; // PB3, R
  37. OCR1A = g; // PD5, G
  38. OCR1B = b; // PD4, B
  39.  
  40. int constN = 255 / 7;
  41. int lastButton = 0;
  42.  
  43. while (1) {
  44. if (PINA == lastButton) {
  45. continue;
  46. }
  47.  
  48. lastButton = PINA;
  49.  
  50. switch (PINA) {
  51. // R
  52. case 0b11111110:
  53. r += constN;
  54. r = maxValue(r);
  55. OCR0 = r;
  56. break;
  57. case 0b11111101:
  58. r -= constN;
  59. r = minValue(r);
  60. OCR0 = r;
  61. break;
  62.  
  63. // G
  64. case 0b11111011:
  65. g += constN;
  66. g = maxValue(g);
  67. OCR1A = g;
  68. break;
  69. case 0b11110111:
  70. g -= constN;
  71. g = minValue(g);
  72. OCR1A = g;
  73. break;
  74.  
  75. // B
  76. case 0b11101111:
  77. b += constN;
  78. b = maxValue(b);
  79. OCR1B = b;
  80. break;
  81. case 0b11011111:
  82. b -= constN;
  83. b = minValue(b);
  84. OCR1B = b;
  85. break;
  86. }
  87. }
  88.  
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement