Advertisement
RuiViana

Fade_Code

Jul 22nd, 2016
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. /* +-----+
  2. +----[PWR]-------------------| USB |--+
  3. | +-----+ |
  4. | GND/RST2 [ ][ ] |
  5. | MOSI2/SCK2 [ ][ ] A5/SCL[ ] |
  6. | 5V/MISO2 [ ][ ] A4/SDA[ ] |
  7. | AREF[ ] |
  8. | GND[ ] |
  9. | [ ]N/C SCK/13[ ] |
  10. | [ ]IOREF MISO/12[ ] |
  11. | [ ]RST MOSI/11[ ]~|
  12. | [ ]3V3 +---+ 10[ ]~|
  13. | [ ]5v -| A |- 9[ ]~|
  14. | [ ]GND -| R |- 8[ ] | LED
  15. | [ ]GND -| D |- | +--------|>|----RRRRR---GND
  16. | [ ]Vin -| U |- 7[ ] | |
  17. | -| I |- 6[ ]~| |
  18. | [ ]A0 -| N |- 5[ ]~|------+ +----+
  19. | [ ]A1 -| O |- 4[ ] |------------| IR |
  20. | [ ]A2 +---+ INT1/3[ ]~| +----+
  21. | [ ]A3 INT0/2[ ] |
  22. | [ ]A4/SDA RST SCK MISO TX>1[ ] |
  23. | [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] |
  24. | [ ] [ ] [ ] |
  25. | UNO_R3 GND MOSI 5V ____________/
  26. \_______________________/
  27. */
  28.  
  29.  
  30. #include <IRremote.h>
  31. int RECV_PIN = 4;
  32. IRrecv irrecv(RECV_PIN);
  33. decode_results results;
  34.  
  35. int redPin = 12; //rgb led
  36. int greenPin = 8;
  37. int bluePin = 7;
  38. int const potenciometro = 0; //motor pot
  39. int const transTIP120 = 10;
  40. int valPotenciometro = 0;
  41. int i1 = 0;
  42. int i2 = 0;
  43. int i3 = 0;
  44. int i4 = 0;
  45. int i5 = 0;
  46. int i6 = 0;
  47. int i7 = 0;
  48. int i8 = 0;
  49. int i9 = 0;
  50. int led = 5; //leds
  51. int brightness = 0;
  52. int fadeAmount = 5;
  53. //------------------------------
  54. void setup()
  55. {
  56. Serial.begin(9600);
  57. pinMode(transTIP120, OUTPUT); //pot motor
  58. irrecv.enableIRIn();
  59. pinMode(led, OUTPUT); //leds
  60. pinMode(redPin, OUTPUT); //rgb
  61. pinMode(greenPin, OUTPUT);
  62. pinMode(bluePin, OUTPUT);
  63. pinMode(2, OUTPUT); //RELAY
  64. pinMode(3, OUTPUT);
  65. pinMode(5, OUTPUT);
  66. pinMode(6, OUTPUT);
  67. }
  68. //-------------------------
  69. void loop()
  70. {
  71. if (irrecv.decode(&results))
  72. {
  73. Serial.println(brightness);
  74. if (results.value == 0xFF6897) //button 1 // Red Button
  75. {
  76. setColor(255, 0, 0); // Sets Red Color to the RGB LED
  77. delay(100);
  78. }
  79. if (results.value == 0xFF9867) // Yellow Button //button 2
  80. {
  81. setColor(255, 255, 0); // Yellow Color
  82. delay(100);
  83. }
  84. if (results.value == 0xFF02FD) // Stop Button //button OK
  85. {
  86. setColor(0, 0, 0); // OFF
  87. delay(100);
  88. }
  89. if (i1 == 0 && results.value == 0xFFB04F) //button 3
  90. {
  91. digitalWrite(6, HIGH);
  92. i1 = 1;
  93. }
  94. else if (i1 == 1 && results.value == 0xFFB04F) //button 3
  95. {
  96. digitalWrite(6, LOW);
  97. i1 = 0;
  98. }
  99. else if (i2 == 0 && results.value == 0xFF30CF) //button 4
  100. {
  101. digitalWrite(5, HIGH);
  102. i2 = 1;
  103. }
  104. else if (i2 == 1 && results.value == 0xFF30CF) //button 4
  105. {
  106. digitalWrite(5, LOW);
  107. i2 = 0;
  108. }
  109. else if (i3 == 0 && results.value == 0xFF18E7) //button 5
  110. {
  111. digitalWrite(3, HIGH);
  112. i3 = 1;
  113. }
  114. else if (i3 == 1 && results.value == 0xFF18E7) //button 5
  115. {
  116. digitalWrite(3, LOW);
  117. i3 = 0;
  118. }
  119. else if (i4 == 0 && results.value == 0xFF7A85) //button 6
  120. {
  121. digitalWrite(2, HIGH);
  122. i4 = 1;
  123. }
  124. else if (i4 == 1 && results.value == 0xFF7A85) //button 6
  125. {
  126. digitalWrite(2, LOW);
  127. i4 = 0;
  128. }
  129. else if (i5 == 0 && results.value == 0xFF10EF) //button 7
  130. {
  131. digitalWrite(10, HIGH);
  132. i5 = 1;
  133. pot();
  134. }
  135. else if (i5 == 1 && results.value == 0xFF10EF) //button 7
  136. {
  137. digitalWrite(10, LOW);
  138. i5 = 0;
  139. }
  140. else if (i6 == 0 && results.value == 0xFD32CD) //button 8
  141. {
  142. digitalWrite(11, HIGH);
  143. i6 = 1;
  144. fade();
  145. }
  146. else if (i6 == 1 && results.value == 0xFF38C7) //button 8
  147. {
  148. digitalWrite(11, LOW);
  149. i6 = 0;
  150. }
  151. irrecv.resume();
  152. }
  153. delay(100);
  154. }
  155. //-------------------------------------//rgb led
  156. void setColor(int red, int green, int blue)
  157. {
  158. analogWrite(redPin, red);
  159. analogWrite(greenPin, green);
  160. analogWrite(bluePin, blue);
  161. }
  162. //-------------------------
  163. void pot() {
  164. valPotenciometro = analogRead(potenciometro) / 4; //potmotor
  165. analogWrite(transTIP120, valPotenciometro);
  166. }
  167. //-------------------------
  168. void fade()
  169. {
  170. Serial.println(brightness);
  171. analogWrite(led, brightness); //fade led
  172. brightness = brightness + fadeAmount;
  173. if (brightness == 0 || brightness == 255)
  174. {
  175. fadeAmount = -fadeAmount ;
  176. }
  177. delay(30);
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement